Repository navigation
304 lines (283 loc) · 12.3 KB
/
Copy pathpypi.yml
File metadata and controls
304 lines (283 loc) · 12.3 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
name: PyPI packages
# The packages a release puts on PyPI: testing-files-generator, as one wheel
# for each system with that system's tfg binary of the release inside and one
# wheel with none, and pytest-testing-files-generator, which installs it. They
# are made of the PUBLISHED release, as npm.yml makes the npm packages, and
# reach PyPI only after every system has installed and used them and the owner
# has approved the run in the pypi environment. docs/PYTEST-2026-11-09.md.
#
# PyPI takes them through trusted publishing, so no token is kept anywhere,
# and the publishing action puts an attestation of each file beside it. A run
# by hand can send them to TestPyPI instead, to see that PyPI takes them
# before a release depends on it. A pull request that touches the packages
# makes and tries them from the latest release and publishes nothing, and so
# does a release candidate: PyPI only gets stable releases.
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: "Published tag to publish the PyPI packages of, for example v0.6.0"
required: true
index:
description: "testpypi to try PyPI's test index, pypi to publish"
required: true
default: testpypi
type: choice
options: [testpypi, pypi]
pull_request:
paths:
- "python/**"
- "testdata/wrappers/**"
- ".github/requirements-pypi.txt"
- ".github/workflows/pypi.yml"
- ".github/actions/release-archives/**"
permissions:
contents: read
concurrency:
group: pypi-${{ github.event.release.tag_name || inputs.tag || github.ref }}
cancel-in-progress: false
jobs:
which:
name: which release, and where it goes
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
tag: ${{ steps.which.outputs.tag }}
version: ${{ steps.which.outputs.version }}
index: ${{ steps.which.outputs.index }}
steps:
- name: which release
id: which
env:
GH_TOKEN: ${{ github.token }}
EVENT: ${{ github.event_name }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
INPUT_TAG: ${{ inputs.tag }}
INPUT_INDEX: ${{ inputs.index }}
# Asked of the API rather than taken from the event, because a run by
# hand has no event payload and a draft must never reach PyPI. An older
# release may go to PyPI after a newer one: pip installs the highest
# version, whatever order they were published in.
run: |
set -euo pipefail
case "$EVENT" in
release) tag="$RELEASE_TAG"; index=pypi ;;
workflow_dispatch) tag="$INPUT_TAG"; index="$INPUT_INDEX" ;;
*) tag="$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq .tag_name)"; index=none ;;
esac
if ! [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "::error::\"$tag\" is not a release tag. Run this workflow with the tag of a published release, such as v0.6.0."
exit 1
fi
draft="$(gh release view "$tag" --repo "$GITHUB_REPOSITORY" --json isDraft --jq .isDraft)"
if [ "$draft" != "false" ]; then
echo "::error::$tag is not published yet, and PyPI only ever gets what people can download. Publish the release, and this workflow starts by itself."
exit 1
fi
# PyPI only ever gets stable releases. A release candidate stays a
# prerelease on GitHub, and its wheels are made and tried here the
# way a pull request's are. TestPyPI, by hand, may still take one.
if [[ "$tag" == *-* ]] && [ "$index" = pypi ]; then
if [ "$EVENT" = workflow_dispatch ]; then
echo "::error::$tag is a release candidate, and PyPI only gets stable releases. Run this workflow with the tag of a stable release, such as v0.6.0, or choose testpypi."
exit 1
fi
index=none
echo "::notice::$tag is a release candidate, so its wheels are made and tried and nothing goes to PyPI. PyPI only gets stable releases."
fi
{
echo "tag=$tag"
echo "version=${tag#v}"
echo "index=$index"
} >> "$GITHUB_OUTPUT"
echo "$tag, index: $index"
assemble:
name: the wheels, made of the release's own archives
needs: which
runs-on: ubuntu-latest
timeout-minutes: 15
env:
TAG: ${{ needs.which.outputs.tag }}
VERSION: ${{ needs.which.outputs.version }}
steps:
# The code of the package from the tagged commit, the one its binaries
# were built from. A pull request tries its own code against the latest
# release, and so does a run to TestPyPI: that is a rehearsal of the
# code the next release will carry, with binaries that are already out.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
ref: ${{ needs.which.outputs.index == 'pypi' && needs.which.outputs.tag || '' }}
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.13"
- name: which archives the wheels are made of
run: |
set -euo pipefail
assemble=python/testing-files-generator/release/assemble.py
if [ ! -f "$assemble" ]; then
echo "::error::the tree of $TAG has no $assemble, so it has no PyPI packages to make. PyPI gets the releases tagged after the packages came into the repository, so run this workflow for one of those."
exit 1
fi
python "$assemble" archives "$VERSION" > archives.txt
- name: the published archives, each checked before it is opened
uses: ./.github/actions/release-archives
with:
tag: ${{ needs.which.outputs.tag }}
archives: archives.txt
token: ${{ github.token }}
- name: lay out the wheels and check them
# Laid out here, on Linux, where the archives keep the execute bit of
# the binaries for Linux and macOS.
run: |
set -euo pipefail
python -m pip install --disable-pip-version-check -r .github/requirements-pypi.txt
python python/testing-files-generator/release/assemble.py build "$VERSION" binaries dist
python python/testing-files-generator/release/try_wheels.py --without-binary dist "$VERSION"
mv binaries.txt dist/binaries.txt
ls -l dist/main dist/plugin
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: pypi-wheels
path: dist/
retention-days: 7
try:
name: installed and run on ${{ matrix.name }}
needs: [which, assemble]
strategy:
fail-fast: false
# One runner per system, each the system its wheel is for, and Alpine
# in a container for the wheels for musl. Each installs with pip and
# with uv. internal/guard/pypipackage_test.go holds this list to
# src/testing_files_generator/_binary.py.
matrix:
include:
- name: win32-x64
system: win32-x64
runner: windows-latest
python: "3.13"
- name: win32-arm64
system: win32-arm64
runner: windows-11-arm
python: "3.13"
- name: linux-x64
system: linux-x64
runner: ubuntu-latest
python: "3.10"
- name: linux-arm64
system: linux-arm64
runner: ubuntu-24.04-arm
python: "3.13"
- name: darwin-arm64
system: darwin-arm64
runner: macos-latest
python: "3.13"
- name: linux-x64 on Alpine
system: linux-x64
runner: ubuntu-latest
alpine: python:3.13-alpine
- name: linux-arm64 on Alpine
system: linux-arm64
runner: ubuntu-24.04-arm
alpine: python:3.13-alpine
runs-on: ${{ matrix.runner }}
timeout-minutes: 20
env:
VERSION: ${{ needs.which.outputs.version }}
SYSTEM: ${{ matrix.system }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
ref: ${{ needs.which.outputs.index == 'pypi' && needs.which.outputs.tag || '' }}
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
if: matrix.alpine == ''
with:
python-version: ${{ matrix.python }}
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: pypi-wheels
path: dist
- name: installed with pip and with uv, and used
if: matrix.alpine == ''
shell: bash
run: |
set -euo pipefail
python -m pip install --disable-pip-version-check -r .github/requirements-pypi.txt
for installer in pip uv; do
python python/testing-files-generator/release/try_wheels.py dist "$VERSION" dist/binaries.txt "$SYSTEM" "$installer"
done
- name: installed with pip and with uv on Alpine, and used
if: matrix.alpine != ''
env:
IMAGE: ${{ matrix.alpine }}
run: |
set -euo pipefail
docker run --rm -v "$PWD:/w" -w /w -e VERSION -e SYSTEM "$IMAGE" sh -c '
set -eu
python -m pip install --root-user-action=ignore --disable-pip-version-check -r .github/requirements-pypi.txt
for installer in pip uv; do
python python/testing-files-generator/release/try_wheels.py dist "$VERSION" dist/binaries.txt "$SYSTEM" "$installer"
done'
publish:
name: published on ${{ needs.which.outputs.index }}
needs: [which, try]
if: needs.which.outputs.index != 'none'
runs-on: ubuntu-latest
timeout-minutes: 15
# The run waits here until the owner approves it in the environment, and
# PyPI takes the files only from this workflow in this environment - the
# trusted publisher of each project names both.
environment:
name: ${{ needs.which.outputs.index }}
url: ${{ needs.which.outputs.index == 'testpypi' && 'https://test.pypi.org/project/testing-files-generator/' || 'https://pypi.org/project/testing-files-generator/' }}
permissions:
contents: read
# The OIDC token PyPI trusts, and the attestations published beside each file.
id-token: write
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: pypi-wheels
path: dist
# testing-files-generator first, so pytest-testing-files-generator never
# names a version PyPI does not have. A run that stopped half way skips
# what is there already. verify-metadata runs twine check on the files
# before anything is sent, and it is written out because nothing else in
# this workflow checks the metadata the way PyPI reads it.
- name: testing-files-generator on TestPyPI
if: needs.which.outputs.index == 'testpypi'
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
packages-dir: dist/main/
repository-url: https://test.pypi.org/legacy/
verify-metadata: true
skip-existing: true
print-hash: true
- name: pytest-testing-files-generator on TestPyPI
if: needs.which.outputs.index == 'testpypi'
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
packages-dir: dist/plugin/
repository-url: https://test.pypi.org/legacy/
verify-metadata: true
skip-existing: true
print-hash: true
- name: testing-files-generator on PyPI
if: needs.which.outputs.index == 'pypi'
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
packages-dir: dist/main/
verify-metadata: true
skip-existing: true
print-hash: true
- name: pytest-testing-files-generator on PyPI
if: needs.which.outputs.index == 'pypi'
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
packages-dir: dist/plugin/
verify-metadata: true
skip-existing: true
print-hash: true