-
Notifications
You must be signed in to change notification settings - Fork 0
319 lines (312 loc) · 12.4 KB
/
Copy pathrelease-python.yml
File metadata and controls
319 lines (312 loc) · 12.4 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
name: release-python
on:
push:
tags:
- "v[0-9]*"
workflow_dispatch:
inputs:
release_tag:
description: "Existing immutable release tag, for example v0.2.0"
required: true
type: string
publish:
description: "Publish the verified wheel and sdist to PyPI"
required: true
default: false
type: boolean
permissions:
contents: read
concurrency:
group: release-python-${{ github.event_name == 'workflow_dispatch' && inputs.release_tag || github.ref_name }}
cancel-in-progress: false
jobs:
build:
name: test + build + verify
runs-on: ubuntu-latest
outputs:
artifact_name: ${{ steps.release.outputs.artifact_name }}
source_commit: ${{ steps.release.outputs.source_commit }}
tag: ${{ steps.release.outputs.tag }}
version: ${{ steps.release.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.release_tag || github.ref }}
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip
- name: Resolve and validate immutable release tag
id: release
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_RELEASE_TAG: ${{ inputs.release_tag }}
REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
tag="$INPUT_RELEASE_TAG"
else
tag="$REF_NAME"
fi
if [[ ! "$tag" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([-+][0-9A-Za-z.-]+)?$ ]]; then
echo "Release tag must be an exact v-prefixed semantic version: $tag" >&2
exit 1
fi
GNUPGHOME="$(mktemp -d)"
export GNUPGHOME
trap 'rm -rf "$GNUPGHOME"' EXIT
curl -fsS https://updates.auraone.ai/keys/auraone-open.gpg |
gpg --batch --import
fingerprints="$(
gpg --batch --with-colons --fingerprint |
awk -F: '/^fpr:/ { print $10 }'
)"
test "$fingerprints" = "F909806D13D9CD4CF403FA3C8C61E177EB6329E7"
git fetch --force origin "refs/tags/$tag:refs/tags/$tag"
test "$(git cat-file -t "refs/tags/$tag")" = "tag"
verify_output="$(git verify-tag --raw "$tag" 2>&1)"
printf '%s\n' "$verify_output"
tag_signer="$(
printf '%s\n' "$verify_output" |
awk '/\[GNUPG:\] VALIDSIG / { print $3; exit }'
)"
test "$tag_signer" = "F909806D13D9CD4CF403FA3C8C61E177EB6329E7"
tag_commit="$(git rev-parse "$tag^{}")"
test "$(git rev-parse HEAD)" = "$tag_commit"
version="${tag#v}"
{
echo "artifact_name=auraone-sdk-python-$version"
echo "source_commit=$tag_commit"
echo "tag=$tag"
echo "version=$version"
} >> "$GITHUB_OUTPUT"
- name: Install build tooling and test dependencies
run: |
python -m pip install --upgrade pip build twine
python -m pip install -e ".[dev]"
- name: Validate source metadata
run: python scripts/release_preflight.py --expected-version "${{ steps.release.outputs.version }}"
- name: Test
env:
PYTHONDONTWRITEBYTECODE: "1"
PYTEST_DISABLE_PLUGIN_AUTOLOAD: "1"
run: python -m pytest -p no:cacheprovider -q tests
- name: Build and validate wheel and sdist
run: |
python -m build
python -m twine check --strict dist/*
python scripts/release_preflight.py \
--expected-version "${{ steps.release.outputs.version }}" \
--dist dist
- name: Test installed wheel
shell: bash
run: |
set -euo pipefail
python -m venv /tmp/auraone-sdk-wheel
/tmp/auraone-sdk-wheel/bin/python -m pip install --upgrade pip
/tmp/auraone-sdk-wheel/bin/python -m pip install dist/*.whl
test "$(/tmp/auraone-sdk-wheel/bin/aura --version)" = "aura ${{ steps.release.outputs.version }}"
/tmp/auraone-sdk-wheel/bin/python -c \
"import aura, aura_one; assert aura_one.__version__ == '${{ steps.release.outputs.version }}'"
- name: Generate release checksums
shell: bash
run: |
set -euo pipefail
mkdir -p release-evidence
(
cd dist
sha256sum -- ./* > ../release-evidence/SHA256SUMS
)
- name: Upload immutable release artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ steps.release.outputs.artifact_name }}
path: |
dist/
release-evidence/SHA256SUMS
if-no-files-found: error
retention-days: 30
publish:
name: publish with PyPI trusted publishing
if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish }}
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/auraone-sdk/${{ needs.build.outputs.version }}/
permissions:
attestations: write
contents: read
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.artifact_name }}
path: release-artifacts
- name: Check out coordinated publication authorization
uses: actions/checkout@v4
with:
repository: auraoneai/open
ref: ${{ vars.OSS_PUBLICATION_AUTHORIZATION_TAG }}
path: .publication-authorization
persist-credentials: false
fetch-depth: 0
- name: Verify signed coordinated publication authorization
shell: bash
env:
AUTHORIZATION_TAG: ${{ vars.OSS_PUBLICATION_AUTHORIZATION_TAG }}
EXPECTED_REPOSITORY: auraoneai-sdk-python
EXPECTED_PACKAGE: auraone-sdk
EXPECTED_VERSION: ${{ needs.build.outputs.version }}
EXPECTED_SOURCE_COMMIT: ${{ needs.build.outputs.source_commit }}
EXPECTED_CHANNEL: pypi
run: |
set -euo pipefail
if [[ -z "$AUTHORIZATION_TAG" ]]; then
echo "OSS_PUBLICATION_AUTHORIZATION_TAG must name a signed coordinated publication authorization tag" >&2
exit 1
fi
git check-ref-format "refs/tags/$AUTHORIZATION_TAG"
GNUPGHOME="$(mktemp -d)"
export GNUPGHOME
trap 'rm -rf "$GNUPGHOME"' EXIT
curl -fsS https://updates.auraone.ai/keys/auraone-open.gpg |
gpg --batch --import
fingerprints="$(
gpg --batch --with-colons --fingerprint |
awk -F: '/^fpr:/ { print $10 }'
)"
test "$fingerprints" = "F909806D13D9CD4CF403FA3C8C61E177EB6329E7"
git -C .publication-authorization fetch --force origin \
"refs/tags/$AUTHORIZATION_TAG:refs/tags/$AUTHORIZATION_TAG"
test "$(
git -C .publication-authorization cat-file -t "refs/tags/$AUTHORIZATION_TAG"
)" = "tag"
verify_output="$(
cd .publication-authorization
git verify-tag --raw "$AUTHORIZATION_TAG" 2>&1
)"
printf '%s\n' "$verify_output"
tag_signer="$(
printf '%s\n' "$verify_output" |
awk '/\[GNUPG:\] VALIDSIG / { print $3; exit }'
)"
test "$tag_signer" = "F909806D13D9CD4CF403FA3C8C61E177EB6329E7"
authorization_commit="$(
git -C .publication-authorization rev-parse "$AUTHORIZATION_TAG^{commit}"
)"
test "$(
git -C .publication-authorization rev-parse HEAD
)" = "$authorization_commit"
node .publication-authorization/scripts/verify-publication-authorization.mjs \
--authorization .publication-authorization/release/publication-authorization.json \
--repository "$EXPECTED_REPOSITORY" \
--package "$EXPECTED_PACKAGE" \
--version "$EXPECTED_VERSION" \
--source-commit "$EXPECTED_SOURCE_COMMIT" \
--channel "$EXPECTED_CHANNEL"
- name: Attest the exact downloaded Python distributions
uses: actions/attest-build-provenance@v3
with:
subject-path: release-artifacts/dist/*
- name: Check for an exact prior publication
id: registry
env:
DIST_DIR: release-artifacts/dist
PACKAGE_NAME: auraone-sdk
PACKAGE_VERSION: ${{ needs.build.outputs.version }}
run: |
python - <<'PY'
import hashlib, json, os, pathlib, urllib.error, urllib.request
name, version = os.environ["PACKAGE_NAME"], os.environ["PACKAGE_VERSION"]
try:
with urllib.request.urlopen(f"https://pypi.org/pypi/{name}/{version}/json", timeout=20) as response:
payload = json.load(response)
except urllib.error.HTTPError as error:
if error.code != 404:
raise
open(os.environ["GITHUB_OUTPUT"], "a").write("exists=false\n")
raise SystemExit(0)
remote = {item["filename"]: item["digests"]["sha256"] for item in payload["urls"]}
local = {
path.name: hashlib.sha256(path.read_bytes()).hexdigest()
for path in pathlib.Path(os.environ["DIST_DIR"]).iterdir() if path.is_file()
}
if remote != local:
raise SystemExit(f"{name}=={version} exists with different distribution bytes")
open(os.environ["GITHUB_OUTPUT"], "a").write("exists=true\n")
PY
- name: Publish the exact verified distributions
if: steps.registry.outputs.exists != 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: release-artifacts/dist/
verbose: true
verify:
name: verify PyPI metadata and clean installation
if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish }}
needs: [build, publish]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.build.outputs.tag }}
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Verify PyPI metadata and files
run: python scripts/verify_pypi_release.py "${{ needs.build.outputs.version }}"
- name: Verify a clean PyPI installation
shell: bash
run: |
set -euo pipefail
python -m venv /tmp/auraone-sdk-pypi
/tmp/auraone-sdk-pypi/bin/python -m pip install --upgrade pip
/tmp/auraone-sdk-pypi/bin/python -m pip install \
--no-cache-dir "auraone-sdk==${{ needs.build.outputs.version }}"
test "$(/tmp/auraone-sdk-pypi/bin/aura --version)" = "aura ${{ needs.build.outputs.version }}"
/tmp/auraone-sdk-pypi/bin/python -c \
"import aura, aura_one; assert aura_one.__version__ == '${{ needs.build.outputs.version }}'"
github-release:
name: attest and attach matching GitHub Release assets
if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish }}
needs: [build, verify]
runs-on: ubuntu-latest
permissions:
attestations: write
contents: write
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.artifact_name }}
path: release-artifacts
- name: Attest Python distributions
uses: actions/attest-build-provenance@v3
with:
subject-path: release-artifacts/dist/*
- name: Create or update the matching GitHub Release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ needs.build.outputs.tag }}
shell: bash
run: |
set -euo pipefail
if ! gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
gh release create "$RELEASE_TAG" \
--repo "$GITHUB_REPOSITORY" \
--verify-tag \
--generate-notes \
--title "AuraOne Python SDK ${{ needs.build.outputs.version }}"
fi
gh release upload "$RELEASE_TAG" \
release-artifacts/dist/* \
release-artifacts/release-evidence/SHA256SUMS \
--repo "$GITHUB_REPOSITORY" \
--clobber