Repository navigation
231 lines (192 loc) · 7.13 KB
/
Copy pathpythonpackage.yml
File metadata and controls
231 lines (192 loc) · 7.13 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: CI
on:
push:
pull_request:
# Monthly run: detects breakage caused by new Python releases.
schedule:
- cron: "0 6 1 * *"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
versions:
name: Compute Python versions
runs-on: ubuntu-latest
outputs:
supported: ${{ steps.compute.outputs.supported }}
oldest: ${{ steps.compute.outputs.oldest }}
latest: ${{ steps.compute.outputs.latest }}
next: ${{ steps.compute.outputs.next }}
steps:
- uses: actions/checkout@v7
- name: Fetch supported CPython versions from endoflife.date
id: compute
run: |
if ! curl --fail --silent --show-error --location --retry 3 \
--output eol.json https://endoflife.date/api/python.json; then
echo "::error::Could not fetch https://endoflife.date/api/python.json; refusing to fall back to a pinned version list."
exit 1
fi
python3 - <<'PY'
import json
import os
import tomllib
from datetime import date
today = date.today().isoformat()
with open("eol.json") as fp:
cycles = json.load(fp)
def key(cycle):
return tuple(int(p) for p in cycle.split("."))
# Released (release date in the past) and not yet end-of-life.
supported = sorted(
(
c["cycle"]
for c in cycles
if str(c["releaseDate"]) <= today
and c["eol"] is not True
and (c["eol"] is False or str(c["eol"]) > today)
),
key=key,
)
if not supported:
raise SystemExit("::error::endoflife.date returned no supported CPython version")
major, minor = key(supported[-1])
next_version = f"{major}.{minor + 1}"
with open("pyproject.toml", "rb") as fp:
requires = tomllib.load(fp)["project"]["requires-python"]
floor = requires.removeprefix(">=").strip()
if key(floor) < key(supported[0]):
print(
f"::warning::requires-python ({requires}) is below the oldest "
f"supported CPython ({supported[0]}). The next release should "
"raise requires-python and the version classifiers."
)
with open(os.environ["GITHUB_OUTPUT"], "a") as out:
out.write(f"supported={json.dumps(supported)}\n")
out.write(f"oldest={supported[0]}\n")
out.write(f"latest={supported[-1]}\n")
out.write(f"next={next_version}\n")
print("supported:", supported, "next:", next_version)
PY
test:
name: Test (Python ${{ matrix.python-version }})
needs: versions
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJSON(needs.versions.outputs.supported) }}
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@v10.3.2
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: uv sync --python '${{ steps.python.outputs.python-path }}'
- name: Run unit tests
run: uv run pytest --tb=short
prerelease:
name: Test (upcoming Python ${{ needs.versions.outputs.next }}, may fail)
needs: versions
runs-on: ubuntu-latest
# Informational only: never fails the workflow or blocks publishing.
continue-on-error: true
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@v10.3.2
- name: Set up Python ${{ needs.versions.outputs.next }} (pre-release)
id: python
# Fails when no pre-release of the next version exists yet.
continue-on-error: true
uses: actions/setup-python@v7
with:
python-version: ${{ needs.versions.outputs.next }}
allow-prereleases: true
- name: Note missing pre-release
if: steps.python.outcome != 'success'
run: echo "::notice::No Python ${{ needs.versions.outputs.next }} (pre-)release is available yet; skipping."
- name: Install dependencies
if: steps.python.outcome == 'success'
run: uv sync --python '${{ steps.python.outputs.python-path }}'
- name: Run unit tests
if: steps.python.outcome == 'success'
run: uv run pytest --tb=short
lint:
runs-on: ubuntu-latest
needs: versions
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@v10.3.2
- name: Set up Python
id: python
uses: actions/setup-python@v7
with:
python-version: ${{ needs.versions.outputs.latest }}
- name: Install dependencies
run: uv sync --python '${{ steps.python.outputs.python-path }}'
# Runs ruff, ruff-format and (via "uv run mypy") the strict type check.
- name: Run pre-commit
run: uv run pre-commit run --all-files
docs:
runs-on: ubuntu-latest
needs: versions
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@v10.3.2
- name: Set up Python
id: python
uses: actions/setup-python@v7
with:
python-version: ${{ needs.versions.outputs.latest }}
- name: Install dependencies
run: uv sync --python '${{ steps.python.outputs.python-path }}'
- name: Build documentation
run: uv run sphinx-build -n -W --keep-going -b html docs docs/_build/html
build:
name: Build and inspect package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
# Builds the sdist and wheel, runs check-wheel-contents and twine check,
# prints the contents and uploads them as the "Packages" artifact. Runs
# on every event so packaging problems show up in PRs.
- uses: hynek/build-and-inspect-python-package@v3.0.2
publish:
runs-on: ubuntu-latest
needs: [versions, test, lint, docs, build]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
environment: pypi
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@v10.3.2
- name: Check that the tag matches the package version
env:
TAG: ${{ github.ref_name }}
run: |
version="$(uv version --short)"
if [ "${TAG#v}" != "$version" ]; then
echo "::error::Tag $TAG does not match the pyproject.toml version $version"
exit 1
fi
- name: Download the built packages
uses: actions/download-artifact@v8
with:
name: Packages
path: dist
# Trusted Publishing (OIDC); also uploads PEP 740 attestations.
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1