Repository navigation
288 lines (266 loc) · 11.2 KB
/
Copy pathrelease.yml
File metadata and controls
288 lines (266 loc) · 11.2 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# Publish when a merge to main carries a version that has no `v<version>` tag yet (the
# workflow creates the tag with the GitHub release), or when such a tag is pushed by hand.
# `.dev` versions and already-tagged versions only build.
#
# One-time setup (a publisher registered on PyPI and TestPyPI, and two GitHub
# environments; `pypi` must allow the `main` branch and `v*` tags) is described in
# RELEASING.md. A version number on PyPI can never be reused.
#
# Every released version goes to TestPyPI and is installed back from that index first.
# Final versions then go to PyPI; pre-releases remain on TestPyPI only.
#
# No API token is involved anywhere in this file, and none should be added. Trusted
# Publishing mints a short-lived credential scoped to this workflow and environment.
name: Release
on:
push:
branches: [main]
tags:
- "v*"
# Lets the build-and-verify half be exercised without releasing.
workflow_dispatch:
permissions:
contents: read
# One release at a time: a second merge waits, then finds the tag and only builds.
concurrency:
group: release-publish
cancel-in-progress: false
jobs:
build:
name: Build and verify the distributions
runs-on: ubuntu-latest
outputs:
version: ${{ steps.meta.outputs.version }}
prerelease: ${{ steps.meta.outputs.prerelease }}
release: ${{ steps.meta.outputs.release }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
# No cache in the release build: a poisoned cache must never reach a
# published artifact.
enable-cache: false
python-version: "3.13"
# Read the version from the file rather than importing the package: the build
# backend reads it from the same place, so this is what would actually be
# published. A tag that disagrees with it is how a release goes out under the
# wrong number, and that is unfixable afterwards.
- name: The tag must match the packaged version
id: meta
env:
GH_TOKEN: ${{ github.token }}
run: |
packaged=$(sed -nE 's/^__version__ *= *"([^"]+)".*/\1/p' src/python_wrap/__init__.py | head -n1)
if [ -z "$packaged" ]; then
echo "::error::could not read __version__ from src/python_wrap/__init__.py"
exit 1
fi
echo "version=$packaged" >> "$GITHUB_OUTPUT"
if printf '%s' "$packaged" | grep -Eq '^[0-9]+(\.[0-9]+)*(\.post[0-9]+)?$'; then
echo "prerelease=false" >> "$GITHUB_OUTPUT"
else
echo "prerelease=true" >> "$GITHUB_OUTPUT"
fi
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
tag="${GITHUB_REF_NAME#v}"
echo "tag=$tag packaged=$packaged"
if [ "$tag" != "$packaged" ]; then
echo "::error::tag $GITHUB_REF_NAME does not match python_wrap.__version__ ($packaged)"
exit 1
fi
fi
release=false
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
release=true
elif [ "${GITHUB_EVENT_NAME}" = "push" ] && [ "${GITHUB_REF}" = "refs/heads/main" ] \
&& ! printf '%s' "$packaged" | grep -q 'dev'; then
# matching-refs matches prefixes, so compare the whole ref.
tagged=$(gh api "repos/$GITHUB_REPOSITORY/git/matching-refs/tags/v$packaged" \
--jq "[.[] | select(.ref == \"refs/tags/v$packaged\")] | length")
if [ "$tagged" = "0" ]; then release=true; fi
fi
echo "release=$release" | tee -a "$GITHUB_OUTPUT"
- name: Check changelog and stability metadata
if: steps.meta.outputs.release == 'true'
run: uv run --frozen --no-sync python scripts/check_release.py --tag
- name: Install Redis for the release integration gate
run: sudo apt-get update && sudo apt-get install -y redis-server
- name: Verify distributed coordination before publishing
env:
PW_REQUIRE_REDIS: "1"
run: |
uv sync --frozen --group dev
uv run --no-sync pytest tests/test_redis_backends.py tests/test_distributed_contracts.py tests/test_fork_safety.py
- name: Build
run: uv build
- name: twine check
run: uvx twine check --strict dist/*
- name: Smoke-test the wheel in a clean environment
env:
PACKAGE_VERSION: ${{ steps.meta.outputs.version }}
run: |
python3 -m zipfile -l dist/*.whl | grep -q 'python_wrap/py.typed'
uv venv "$RUNNER_TEMP/smoke" --python 3.13
uv pip install --python "$RUNNER_TEMP/smoke" dist/*.whl
"$RUNNER_TEMP/smoke/bin/python" -I scripts/check_installed.py "$PACKAGE_VERSION"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: release-dist
path: dist/
if-no-files-found: error
# The full CI suite must pass on the released commit before anything is uploaded.
ci:
needs: build
if: needs.build.outputs.release == 'true'
uses: ./.github/workflows/ci.yml
publish-testpypi:
name: Publish to TestPyPI
needs: [build, ci]
if: needs.build.outputs.release == 'true'
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/python-wrap
permissions:
# The OIDC token Trusted Publishing exchanges for a short-lived upload token.
id-token: write
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: release-dist
path: dist/
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
repository-url: https://test.pypi.org/legacy/
# Re-running after a failed attempt should not be blocked by files that
# already landed.
skip-existing: true
verify-testpypi:
name: Install and verify from TestPyPI
needs: [build, publish-testpypi]
if: needs.build.outputs.release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
python-version: "3.13"
- name: Install the exact published version without fallback indexes
env:
VERSION: ${{ needs.build.outputs.version }}
run: |
uv venv "$RUNNER_TEMP/testpypi-smoke" --python 3.13
for attempt in 1 2 3 4 5 6; do
if uv pip install --python "$RUNNER_TEMP/testpypi-smoke" --no-deps --no-cache \
--index-url https://test.pypi.org/simple/ "python-wrap==$VERSION"; then
break
fi
if [ "$attempt" = 6 ]; then exit 1; fi
sleep 10
done
"$RUNNER_TEMP/testpypi-smoke/bin/python" -I scripts/check_installed.py "$VERSION"
publish-pypi:
name: Publish to PyPI
needs: [build, verify-testpypi]
if: needs.build.outputs.release == 'true' && needs.build.outputs.prerelease == 'false'
runs-on: ubuntu-latest
environment:
# Add a required reviewer to this environment to make every real upload wait for
# one click.
name: pypi
url: https://pypi.org/p/python-wrap
permissions:
id-token: write
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: release-dist
path: dist/
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
# PEP 740 attestations, signed by the same OIDC identity.
attestations: true
verify-pypi:
name: Install and verify from PyPI
needs: [build, publish-pypi]
if: needs.build.outputs.release == 'true' && needs.build.outputs.prerelease == 'false'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
python-version: "3.13"
- name: Install the exact published version
env:
VERSION: ${{ needs.build.outputs.version }}
run: |
uv venv "$RUNNER_TEMP/pypi-smoke" --python 3.13
for attempt in 1 2 3 4 5 6; do
if uv pip install --python "$RUNNER_TEMP/pypi-smoke" --no-deps --no-cache \
--index-url https://pypi.org/simple/ "python-wrap==$VERSION"; then
break
fi
if [ "$attempt" = 6 ]; then exit 1; fi
sleep 10
done
"$RUNNER_TEMP/pypi-smoke/bin/python" -I scripts/check_installed.py "$VERSION"
github-release:
name: Create the GitHub release
needs: [build, verify-testpypi, publish-pypi, verify-pypi]
# Whichever publish job applied must have succeeded; the other is skipped.
if: >-
!cancelled() && needs.build.outputs.release == 'true' && needs.build.result == 'success'
&& needs.verify-testpypi.result == 'success'
&& ((needs.build.outputs.prerelease == 'true' && needs.publish-pypi.result == 'skipped')
|| (needs.publish-pypi.result == 'success' && needs.verify-pypi.result == 'success'))
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: release-dist
path: dist/
# The release notes are the CHANGELOG section for this version: from its `## `
# heading up to the next one. Matches `## [0.2.0] - date` and `## 0.2.0`.
- name: Extract the changelog section
env:
VERSION: ${{ needs.build.outputs.version }}
run: |
awk -v v="$VERSION" '
/^## / {
if (found) exit
if (index($0, "[" v "]") || index($0, "## " v) == 1) { found = 1; next }
}
found { print }
' CHANGELOG.md > release-notes.md
if [ ! -s release-notes.md ]; then
echo "::warning::no CHANGELOG.md section found for $VERSION"
echo "See CHANGELOG.md for what changed in this release." > release-notes.md
fi
cat release-notes.md
- name: Create the release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.build.outputs.version }}
PRERELEASE: ${{ needs.build.outputs.prerelease }}
run: |
flags=()
if [ "$PRERELEASE" = "true" ]; then flags+=(--prerelease); fi
# --target creates the tag on the released commit when none was pushed.
gh release create "v$VERSION" dist/* \
--repo "$GITHUB_REPOSITORY" \
--target "$GITHUB_SHA" \
--title "v$VERSION" \
--notes-file release-notes.md \
"${flags[@]}"