-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (92 loc) · 3.11 KB
/
release.yml
File metadata and controls
109 lines (92 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Release
# Fires when a version tag is pushed (manually, after the Prepare Release PR
# is merged and reviewed).
#
# Jobs:
# build - build wheel + sdist with uv
# publish - upload to PyPI via OIDC trusted publishing (no API token needed)
# release - create a GitHub Release with the dist files and changelog notes
on:
push:
tags: ["v*.*.*"]
permissions:
contents: write # create GitHub Releases and upload assets
id-token: write # OIDC token for PyPI trusted publishing
jobs:
# --------------------------------------------------------------------------
build:
name: Build distribution
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
python-version: "3.13"
enable-cache: true
- name: Build wheel and sdist
run: uv build
- name: Upload dist artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
if-no-files-found: error
retention-days: 7
# --------------------------------------------------------------------------
publish:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/anyplotlib
steps:
- name: Download dist artifact
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
# Trusted publishing - no API token required.
# One-time setup on pypi.org: add a pending publisher for
# Owner: CSSFrancis Repo: anyplotlib Workflow: release.yml
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# --------------------------------------------------------------------------
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download dist artifact
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Extract release notes from CHANGELOG.rst
env:
TAG: ${{ github.ref_name }}
shell: python
run: |
import re, pathlib, os
tag = os.environ["TAG"]
text = pathlib.Path("CHANGELOG.rst").read_text()
parts = re.split(r"(?m)(?=^\S[^\n]*\n=+\n)", text)
notes = next((p.strip() for p in parts if p.strip().startswith(tag)), None)
fallback = "Release " + tag + "\n" + "=" * (len(tag) + 8) + "\n\nSee CHANGELOG.rst."
pathlib.Path("release_notes.rst").write_text(notes if notes else fallback)
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ github.ref_name }}
run: |
PRERELEASE_FLAG=""
if [[ "$TAG" == *b* ]]; then PRERELEASE_FLAG="--prerelease"; fi
gh release create "$TAG" \
--title "$TAG" \
--notes-file release_notes.rst \
$PRERELEASE_FLAG \
dist/*