Repository navigation
479 lines (459 loc) · 20.4 KB
/
Copy pathrelease.yml
File metadata and controls
479 lines (459 loc) · 20.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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# Originally generated by `cargo-dist`. This workflow is now maintained manually.
# https://axodotdev.github.io/cargo-dist
#
# Copyright 2022-2024, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
# CI that:
#
# * checks for a Git Tag that looks like a release
# * builds artifacts with dist (archives, installers, hashes)
# * uploads those artifacts to temporary workflow zip
# * on success, uploads the artifacts to a GitHub Release
#
# Note that the GitHub Release will be created with a generated
# title/body based on your changelogs.
name: Release
permissions: {}
# This task will run whenever you workflow_dispatch with a tag that looks like a version
# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
#
# If PACKAGE_NAME is specified, then the announcement will be for that
# package (erroring out if it doesn't have the given version or isn't dist-able).
#
# If PACKAGE_NAME isn't specified, then the announcement will be for all
# (dist-able) packages in the workspace with that version (this mode is
# intended for workspaces with only one dist-able package, or with all dist-able
# packages versioned/released in lockstep).
#
# If you push multiple tags at once, separate instances of this workflow will
# spin up, creating an independent announcement for each one. However, GitHub
# will hard limit this to 3 tags per commit, as it will assume more tags is a
# mistake.
#
# If there's a prerelease-style suffix to the version, then the release(s)
# will be marked as a prerelease.
on:
workflow_dispatch:
inputs:
tag:
description: Release Tag
required: true
default: dry-run
type: string
env:
# Release actions must not consume shared GitHub Actions caches.
ACTIONS_CACHE_MODE: none
UV_LOCKED: 1
jobs:
release-gate:
# N.B. This name should not change, it is used for downstream checks.
name: release-gate
runs-on: ${{ github.repository_owner == 'astral-sh' && 'github-ubuntu-24.04-x86_64-4' || 'ubuntu-latest' }}
# This environment requires a 2-factor approval, i.e., the workflow must be approved by another
# team member. GitHub fires approval events on every job that deploys to an environment, so we
# have a dedicated environment for this purpose instead of using the `release` environment.
# We use a GitHub App with a deployment protection rule webhook to ensure that the `release`
# environment is only approved when the `release-gate` job succeeds. Dry-runs also require
# approval because they use the real signing keys.
environment:
name: release-gate
deployment: true
steps:
- run: echo "Release approved"
# Run 'dist plan' (or host) to determine what tasks we need to do
plan:
runs-on: "depot-ubuntu-latest-4"
outputs:
val: ${{ steps.plan.outputs.manifest }}
artifact: ${{ steps.upload.outputs.artifact-id }}
tag: ${{ (inputs.tag != 'dry-run' && inputs.tag) || '' }}
tag-flag: ${{ inputs.tag && inputs.tag != 'dry-run' && format('--tag={0}', inputs.tag) || '' }}
publishing: ${{ inputs.tag && inputs.tag != 'dry-run' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
submodules: recursive
- name: "Install uv"
uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
with:
# renovate: datasource=github-release-attachments depName=astral-sh/uv
version: "0.12.14"
checksum: "18ef5c3888ae59828cb13f38d57e9389b8173ecc719eff163bfafc74b38f5936"
# sure would be cool if github gave us proper conditionals...
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
# functionality based on whether this is a pull_request, and whether it's from a fork.
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
# but also really annoying to build CI around when it needs secrets to work right.)
- id: plan
run: |
uv run --only-dev dist ${DIST_CMD} --output-format=json > plan-dist-manifest.json
echo "dist ran successfully"
cat plan-dist-manifest.json
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
env:
DIST_CMD: ${{ (inputs.tag && inputs.tag != 'dry-run' && format('host --steps=create --tag={0}', inputs.tag)) || 'plan' }}
- name: "Upload dist-manifest.json"
id: upload
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist-manifest-plan-${{ github.run_id }}-${{ github.run_attempt }}
path: plan-dist-manifest.json
build-release-artifacts:
needs:
- plan
if: ${{ needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload' || inputs.tag == 'dry-run' }}
uses: $/.github/workflows/build-release-binaries.yml
with:
plan: ${{ needs.plan.outputs.val }}
secrets: inherit
permissions:
"contents": "read"
build-docker:
needs:
- plan
if: ${{ needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload' || inputs.tag == 'dry-run' }}
uses: $/.github/workflows/build-docker.yml
with:
plan: ${{ needs.plan.outputs.val }}
secrets: inherit
permissions:
"contents": "read"
"id-token": "write"
assemble-release-artifacts:
needs:
- plan
- build-release-artifacts
- release-gate
if: ${{ github.repository == 'astral-sh/uv' && github.ref == 'refs/heads/main' }}
uses: $/.github/workflows/sign-release-binaries.yml
with:
plan: ${{ needs.plan.outputs.val }}
secrets: inherit
permissions:
contents: read
id-token: write
generate-local-dist-manifest:
needs:
- plan
- build-release-artifacts
- assemble-release-artifacts
if: ${{ needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload' || inputs.tag == 'dry-run' }}
runs-on: "depot-ubuntu-latest-4"
outputs:
artifact: ${{ steps.upload.outputs.artifact-id }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
submodules: recursive
- name: "Install uv"
uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
with:
# renovate: datasource=github-release-attachments depName=astral-sh/uv
version: "0.12.14"
checksum: "18ef5c3888ae59828cb13f38d57e9389b8173ecc719eff163bfafc74b38f5936"
- name: Fetch release archives and plan
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
artifact-ids: ${{ needs.plan.outputs.artifact }},${{ needs.assemble-release-artifacts.outputs.github-archives }}
path: target/distrib/
merge-multiple: true
- name: Generate local dist manifest
shell: bash
env:
TAG: ${{ needs.plan.outputs.tag-flag }}
run: |
temp_manifest=target/local-dist-manifest.json.tmp
tag_args=()
if [[ -n "$TAG" ]]; then
tag_args=("$TAG")
fi
uv run --only-dev dist manifest "${tag_args[@]}" --output-format=json --no-local-paths --artifacts=local > "$temp_manifest"
python3 scripts/patch-dist-manifest-checksums.py --manifest "$temp_manifest" --artifacts-dir target/distrib
mv "$temp_manifest" target/distrib/local-dist-manifest.json
- name: Upload synthesized local dist manifest
id: upload
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist-manifest-local-${{ github.run_id }}-${{ github.run_attempt }}
path: target/distrib/local-dist-manifest.json
# Build and package all the platform-agnostic(ish) things
build-global-dist-artifacts:
needs:
- plan
- build-release-artifacts
- generate-local-dist-manifest
- assemble-release-artifacts
runs-on: "depot-ubuntu-latest-4"
outputs:
artifacts: ${{ steps.artifacts.outputs.artifact-id }}
manifest: ${{ steps.manifest.outputs.artifact-id }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
submodules: recursive
- name: "Install uv"
uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
with:
# renovate: datasource=github-release-attachments depName=astral-sh/uv
version: "0.12.14"
checksum: "18ef5c3888ae59828cb13f38d57e9389b8173ecc719eff163bfafc74b38f5936"
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
- name: Fetch release archives and manifests
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
artifact-ids: ${{ needs.plan.outputs.artifact }},${{ needs.generate-local-dist-manifest.outputs.artifact }},${{ needs.assemble-release-artifacts.outputs.github-archives }}
path: target/distrib/
merge-multiple: true
- id: cargo-dist
shell: bash
run: |
uv run --only-dev dist build ${DIST_TAG_FLAG} --output-format=json "--artifacts=global" > dist-manifest.json
echo "dist ran successfully"
# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
env:
DIST_TAG_FLAG: ${{ needs.plan.outputs.tag-flag }}
- name: "Check planned GitHub release files"
shell: bash
run: |
jq -r '.releases[].artifacts[]' dist-manifest.json |
while IFS= read -r asset; do
if [[ ! -f "target/distrib/$asset" ]]; then
echo "Missing GitHub release asset: $asset" >&2
exit 1
fi
done
- name: "Upload artifacts"
id: artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: release-github-global-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ steps.cargo-dist.outputs.paths }}
- name: "Upload global dist manifest"
id: manifest
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist-manifest-global-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ env.BUILD_MANIFEST_NAME }}
# Finalize the cargo-dist manifest before publication
finalize-dist-manifest:
needs:
- plan
- build-release-artifacts
- build-docker
- build-global-dist-artifacts
- generate-local-dist-manifest
- assemble-release-artifacts
# Only run if we're publishing and the required builds and signing succeeded (skipped builds are fine).
if: ${{ always() && needs.plan.result == 'success' && needs.plan.outputs.publishing == 'true' && needs.assemble-release-artifacts.result == 'success' && (needs.build-global-dist-artifacts.result == 'skipped' || needs.build-global-dist-artifacts.result == 'success') && (needs.build-release-artifacts.result == 'skipped' || needs.build-release-artifacts.result == 'success') && (needs.build-docker.result == 'skipped' || needs.build-docker.result == 'success') }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
runs-on: "depot-ubuntu-latest-4"
outputs:
val: ${{ steps.host.outputs.manifest }}
github-artifacts: ${{ needs.assemble-release-artifacts.outputs.github-archives }},${{ needs.build-global-dist-artifacts.outputs.artifacts }},${{ steps.manifest.outputs.artifact-id }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
submodules: recursive
- name: "Install uv"
uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
with:
# renovate: datasource=github-release-attachments depName=astral-sh/uv
version: "0.12.14"
checksum: "18ef5c3888ae59828cb13f38d57e9389b8173ecc719eff163bfafc74b38f5936"
# Fetch artifacts from scratch-storage
- name: Fetch release artifacts and manifests
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
artifact-ids: ${{ needs.plan.outputs.artifact }},${{ needs.generate-local-dist-manifest.outputs.artifact }},${{ needs.build-global-dist-artifacts.outputs.manifest }},${{ needs.assemble-release-artifacts.outputs.github-archives }},${{ needs.build-global-dist-artifacts.outputs.artifacts }}
path: target/distrib/
merge-multiple: true
# This is a harmless no-op for GitHub Releases, hosting for that happens in "publish-github"
- id: host
shell: bash
run: |
uv run --only-dev dist host ${DIST_TAG_FLAG} --steps=upload --steps=release --output-format=json > dist-manifest.json
echo "artifacts uploaded and released successfully"
cat dist-manifest.json
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
env:
DIST_TAG_FLAG: ${{ needs.plan.outputs.tag-flag }}
- name: "Upload dist-manifest.json"
id: manifest
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: release-github-manifest-${{ github.run_id }}-${{ github.run_attempt }}
path: dist-manifest.json
publish-docker:
needs:
- plan
- finalize-dist-manifest
- release-gate
- build-docker
uses: $/.github/workflows/publish-docker.yml
with:
manifest: ${{ needs.build-docker.outputs.manifest }}
secrets: inherit
permissions:
"attestations": "write"
"contents": "read"
"id-token": "write"
"packages": "write"
publish-pypi:
needs:
- plan
- finalize-dist-manifest
- release-gate
- assemble-release-artifacts
if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }}
uses: $/.github/workflows/publish-pypi.yml
with:
plan: ${{ needs.plan.outputs.val }}
uv-wheels: ${{ needs.assemble-release-artifacts.outputs.uv-wheels }}
uv-build-wheels: ${{ needs.assemble-release-artifacts.outputs.uv-build-wheels }}
uv-sdist: ${{ needs.assemble-release-artifacts.outputs.uv-sdist }}
uv-build-sdist: ${{ needs.assemble-release-artifacts.outputs.uv-build-sdist }}
secrets: inherit
# publish jobs get escalated permissions
permissions:
"id-token": "write"
"packages": "write"
publish-crates:
needs:
- plan
- finalize-dist-manifest
- release-gate
- publish-pypi # DIRTY: see #16989
if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }}
uses: $/.github/workflows/publish-crates.yml
with:
plan: ${{ needs.plan.outputs.val }}
secrets: inherit
# publish jobs get escalated permissions
permissions:
"contents": "read"
"id-token": "write"
# Create a GitHub Release while uploading all files to it
publish-github:
needs:
- plan
- finalize-dist-manifest
- release-gate
- publish-docker
- publish-pypi
- assemble-release-artifacts
# Use `always()` so `publish-pypi` can skip prereleases while the required
# builds and Docker publication must still succeed.
# `publish-crates` is intentionally not a dependency: it's not
# critical to the release and isn't idempotent on retry.
if: ${{ always() && needs.finalize-dist-manifest.result == 'success' && needs.release-gate.result == 'success' && needs.assemble-release-artifacts.result == 'success' && needs.publish-docker.result == 'success' && (needs.publish-pypi.result == 'skipped' || needs.publish-pypi.result == 'success') }}
runs-on: "${{ github.repository_owner == 'astral-sh' && 'github-ubuntu-24.04-x86_64-4' || 'ubuntu-latest' }}"
environment:
name: release
permissions:
"attestations": "write"
"contents": "read"
"id-token": "write"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
submodules: recursive
# Create a GitHub Release while uploading all files to it
- name: "Download GitHub Artifacts"
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
artifact-ids: ${{ needs.finalize-dist-manifest.outputs.github-artifacts }}
path: artifacts
merge-multiple: true
- name: Attest
uses: actions/attest-build-provenance@00014ed6ed5efc5b1ab7f7f34a39eb55d41aa4f8
with:
subject-path: |
artifacts/*.json
artifacts/*.sh
artifacts/*.ps1
artifacts/*.zip
artifacts/*.tar.gz
- name: Get release token
id: release-token
uses: open-security-tools/ost-simple-sts@974a63a2daaaa40f7c6dec40d334f3da4421469e
with:
exchange-url: ${{ secrets.RELEASES_STS_API_URL }}/exchange
audience: ${{ secrets.RELEASES_STS_API_URL }}
repository: astral-sh/uv
# Workflow permission is required to create a release tag after `main` advances across workflow changes.
permissions: |
contents: write
workflows: write
- name: Create GitHub Release
env:
GH_TOKEN: ${{ steps.release-token.outputs.token }}
PRERELEASE_FLAG: "${{ fromJson(needs.finalize-dist-manifest.outputs.val).announcement_is_prerelease && '--prerelease' || '' }}"
ANNOUNCEMENT_TITLE: "${{ fromJson(needs.finalize-dist-manifest.outputs.val).announcement_title }}"
ANNOUNCEMENT_BODY: "${{ fromJson(needs.finalize-dist-manifest.outputs.val).announcement_github_body }}"
RELEASE_COMMIT: "${{ github.sha }}"
NEEDS_PLAN_OUTPUTS_TAG: ${{ needs.plan.outputs.tag }}
run: |
# Write and read notes from a file to avoid quoting breaking things
echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
scripts/dist-manifest-to-files.sh artifacts/dist-manifest.json > "$RUNNER_TEMP/release-assets.txt"
mapfile -t assets < "$RUNNER_TEMP/release-assets.txt"
gh release create "${NEEDS_PLAN_OUTPUTS_TAG}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" "${assets[@]}"
publish-docs:
needs:
- plan
- publish-github
# Use `always() && ...` so this job gates only on whether `publish-github`
# completed successfully.
if: ${{ always() && needs.publish-github.result == 'success' }}
permissions:
contents: read
id-token: write
uses: $/.github/workflows/publish-docs.yml
with:
plan: ${{ needs.plan.outputs.val }}
secrets: inherit
publish-versions:
needs:
- plan
- publish-github
if: ${{ always() && needs.publish-github.result == 'success' }}
permissions:
contents: read
id-token: write # for the credential broker
uses: $/.github/workflows/publish-versions.yml
with:
plan: ${{ needs.plan.outputs.val }}
secrets: inherit
publish-mirror:
needs:
- plan
- finalize-dist-manifest
- publish-github
- assemble-release-artifacts
if: ${{ always() && needs.publish-github.result == 'success' && needs.assemble-release-artifacts.result == 'success' }}
uses: $/.github/workflows/publish-mirror.yml
with:
plan: ${{ needs.plan.outputs.val }}
github-artifacts: ${{ needs.finalize-dist-manifest.outputs.github-artifacts }}
secrets: inherit
permissions:
"contents": "read"