Repository navigation
568 lines (536 loc) · 22.8 KB
/
Copy pathrelease.yml
File metadata and controls
568 lines (536 loc) · 22.8 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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
name: Release
# Publish the release assets of this repository. For each port of scripts/ports:
#
# pacman-static-<arch>, .json a static pacman and its evidence file
# rootfs-<arch>.tar.gz the filesystem of the published image
# rootfs-<arch>.json the evidence file of that image
# bootstrap-set-<arch>.txt its package set: name version sha256
# oci-<arch>.tar.gz the image, for docker load or podman load
#
# and manifest.json (every published tag) and SHA256SUMS (every asset).
#
# Triggers:
# push of a v* tag publish that tag
# schedule day 1 of each month: publish the next patch tag after
# the newest vX.Y.Z tag. The release makes the tag.
# workflow_dispatch build the assets and stop. Nothing is published.
#
# ⭐ A run is idempotent. A new release starts as a draft at the commit of the
# run. Each asset is uploaded with --clobber, then the draft is published,
# which makes the tag. A second run at the same commit finishes the draft. A
# draft at another commit is deleted and made again at the commit of the run.
#
# ⛔ A run never changes a published release. To make one again, delete it
# first: gh release delete TAG.
#
# ⛔ A port with no published image is left out, and the notes name it. Any
# other failure publishes nothing.
#
# ⚠ A git tag (vX.Y.Z) is a version of the tooling and the assets. Image tags
# are dates. The two namespaces are separate.
on:
push:
tags:
- "v*"
schedule:
- cron: "15 6 1 * *"
workflow_dispatch:
defaults:
run:
shell: bash
permissions: {}
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
#--------------------------------------------------------------------------#
# ⛔ First. Choose the tag, refuse a tag that is not on the default branch,
# and run the static suite before any build.
#--------------------------------------------------------------------------#
guard:
name: Check the tag
runs-on: ubuntu-24.04
timeout-minutes: 30
permissions:
contents: read
outputs:
tag: ${{ steps.tag.outputs.tag }}
publish: ${{ steps.tag.outputs.publish }}
matrix: ${{ steps.ports.outputs.matrix }}
steps:
# fetch-depth 0: the tag check reads the history and every tag.
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Choose the tag
id: tag
env:
EVENT: ${{ github.event_name }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
case "$EVENT" in
push)
tag="$GITHUB_REF_NAME"
default="$(timeout -k 5 60 gh api "repos/$GITHUB_REPOSITORY" --jq .default_branch)"
if ! git merge-base --is-ancestor HEAD "origin/$default"; then
echo "::error::$tag is not on origin/$default. A release builds only from the default branch."
echo "reproduce: git merge-base --is-ancestor $tag origin/$default"
exit 1
fi
publish=true
;;
schedule)
# A draft has no git tag, so a later run gets the same tag. The
# publish job deletes a draft at another commit and makes it
# again.
tag="$(git tag -l 'v*' | scripts/release-notes --next-tag)"
publish=true
;;
*)
tag=""
publish=false
;;
esac
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "publish=$publish" >> "$GITHUB_OUTPUT"
echo "::notice::tag $tag, publish $publish"
- name: Read the port table
id: ports
run: |
set -euo pipefail
echo "matrix=$(scripts/ports matrix)" >> "$GITHUB_OUTPUT"
- name: Run the static suite
id: static
run: tests/run.sh -j 4 static
#--------------------------------------------------------------------------#
# The static pacman binaries, from the workflow that owns the recipe.
#--------------------------------------------------------------------------#
pacman:
name: Static pacman
needs: guard
uses: ./.github/workflows/pacman-static.yml
permissions:
contents: read
#--------------------------------------------------------------------------#
# One job per port: take four assets out of the published image.
#
# ⛔ The published image, never a new build: the assets are the bytes that
# consumers pull, and the digest is the digest of the registry.
#--------------------------------------------------------------------------#
rootfs:
name: Rootfs ${{ matrix.arch }}
needs: guard
runs-on: ubuntu-24.04
timeout-minutes: 60
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.guard.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# GHCR <first alias> is the rolling tag of the port. 404 means that the
# port has no published image: the port is left out. Any other answer
# that is not 200 stops the job.
- name: Find the published image
id: image
env:
ARCH: ${{ matrix.arch }}
OWNER: ${{ github.repository_owner }}
run: |
set -euo pipefail
PROG=release
. scripts/lib.sh
mkdir -p assets meta
alias="$(scripts/ports aliases "$ARCH" | awk 'NR == 1')"
repo="$(printf '%s' "$OWNER" | tr '[:upper:]' '[:lower:]')/archlinux"
rc=0
res="$(reg_head ghcr.io "$repo" "$alias")" || rc=$?
[ "$rc" -eq 0 ] || die "no answer from ghcr.io for $repo:$alias" \
"reproduce: curl -sSI --connect-timeout 15 --max-time 60 https://ghcr.io/v2/$repo/manifests/$alias"
read -r code digest <<< "$res"
case "$code" in
200)
echo "state=published" >> "$GITHUB_OUTPUT"
echo "image=ghcr.io/$repo@$digest" >> "$GITHUB_OUTPUT"
echo "digest=$digest" >> "$GITHUB_OUTPUT"
echo "::notice::$ARCH is ghcr.io/$repo:$alias at $digest"
;;
404)
echo "state=absent" >> "$GITHUB_OUTPUT"
jq -n --arg arch "$ARCH" --arg reason "ghcr.io/$repo:$alias does not exist" \
'{arch: $arch, reason: $reason}' > "meta/absent-$ARCH.json"
echo "::warning::$ARCH has no published image at ghcr.io/$repo:$alias. The release leaves it out."
;;
*)
die "ghcr.io answered HTTP $code for $repo:$alias" \
"only 404 means that no image is published" \
"reproduce: curl -sSI --connect-timeout 15 --max-time 60 https://ghcr.io/v2/$repo/manifests/$alias"
;;
esac
- name: Register the emulator
if: steps.image.outputs.state == 'published'
env:
ARCH: ${{ matrix.arch }}
run: scripts/binfmt-register "$ARCH"
# --platform is necessary: the pushed image is an index with an
# attestation, and a pull with no platform picks the runner's.
- name: Pull the published image
if: steps.image.outputs.state == 'published'
env:
IMAGE: ${{ steps.image.outputs.image }}
PLATFORM: ${{ matrix.platform }}
run: timeout -k 10 900 docker pull --platform "$PLATFORM" "$IMAGE"
# The evidence file of the build comes from the status branch when its
# digest is the published digest. Else gen-evidence makes it again from
# the current databases, and the notes say so. ⚠ That can fail when the
# databases moved after the build.
#
# ⛔ CONTAINER_RUNTIME=docker: the image is in the docker store, and
# gen-evidence picks podman when it finds one.
- name: Get the evidence file
id: evidence
if: steps.image.outputs.state == 'published'
env:
ARCH: ${{ matrix.arch }}
IMAGE: ${{ steps.image.outputs.image }}
DIGEST: ${{ steps.image.outputs.digest }}
PLATFORM: ${{ matrix.platform }}
CONTAINER_RUNTIME: docker
run: |
set -euo pipefail
ev="assets/rootfs-$ARCH.json"
source=""
reason=""
rc=0
timeout -k 5 120 git fetch -q --depth 1 origin status || rc=$?
if [ "$rc" -ne 0 ]; then
reason="git fetch origin status exited $rc"
elif ! git cat-file -e "FETCH_HEAD:evidence/$ARCH.json"; then
reason="the status branch has no evidence/$ARCH.json"
else
git show "FETCH_HEAD:evidence/$ARCH.json" > "$ev"
got="$(jq -r '.digest // "-"' "$ev")"
if [ "$got" = "$DIGEST" ]; then
source=status-branch
else
reason="evidence/$ARCH.json is for $got, the published digest is $DIGEST"
rm -f "$ev"
fi
fi
if [ -z "$source" ]; then
echo "::warning::$ARCH: $reason. Making the evidence again without a database snapshot."
# ⛔ No SOURCE_COMMIT and no BUILD_DATE: gen-evidence then reads
# them from the labels of the image. The commit and the time of
# this run are not the build of the image.
env -u SOURCE_COMMIT -u BUILD_DATE scripts/gen-evidence "$ARCH" "$IMAGE" "$PLATFORM" "$ev"
source=regenerated
fi
jq -n --arg arch "$ARCH" --arg image "$IMAGE" --arg digest "$DIGEST" \
--arg evidence "$source" --arg reason "$reason" \
'{arch: $arch, image: $image, digest: $digest, evidence: $evidence, reason: $reason}' \
> "meta/rootfs-$ARCH.json"
echo "::notice::$ARCH evidence: $source"
- name: Test the image
if: steps.image.outputs.state == 'published'
env:
ARCH: ${{ matrix.arch }}
IMAGE: ${{ steps.image.outputs.image }}
PLATFORM: ${{ matrix.platform }}
run: |
set -euo pipefail
IMAGE="$IMAGE" PLATFORM="$PLATFORM" CONTAINER_RUNTIME=docker \
EVIDENCE="assets/rootfs-$ARCH.json" tests/run.sh image
# docker export writes the filesystem of a container. docker save writes
# the image with its layers and metadata. Both are assets.
- name: Export the rootfs and the OCI archive
if: steps.image.outputs.state == 'published'
env:
ARCH: ${{ matrix.arch }}
IMAGE: ${{ steps.image.outputs.image }}
PLATFORM: ${{ matrix.platform }}
run: |
set -euo pipefail
cid="$(docker create --platform "$PLATFORM" "$IMAGE" true)"
docker export "$cid" | gzip -9 > "assets/rootfs-$ARCH.tar.gz"
docker rm -f "$cid" > /dev/null
docker save "$IMAGE" | gzip -9 > "assets/oci-$ARCH.tar.gz"
# ⛔ gzip -t reads the whole stream. A small or broken archive stops
# the job.
for f in "assets/rootfs-$ARCH.tar.gz" "assets/oci-$ARCH.tar.gz"; do
gzip -t "$f"
bytes="$(stat -c %s "$f")"
if [ "$bytes" -lt 1000000 ]; then
echo "::error::$f has $bytes bytes, too small for a root filesystem"
exit 1
fi
echo "$f: $bytes bytes"
done
members="$(tar -tzf "assets/rootfs-$ARCH.tar.gz" | awk '$0 == "etc/os-release" || $0 == "./etc/os-release" { n++ } END { print n + 0 }')"
if [ "$members" -eq 0 ]; then
echo "::error::assets/rootfs-$ARCH.tar.gz has no etc/os-release"
echo "reproduce: tar -tzf assets/rootfs-$ARCH.tar.gz | grep os-release"
exit 1
fi
- name: Write the package set
if: steps.image.outputs.state == 'published'
env:
ARCH: ${{ matrix.arch }}
run: |
set -euo pipefail
scripts/gen-bootstrap-set "assets/rootfs-$ARCH.json" "assets/bootstrap-set-$ARCH.txt"
awk 'NR <= 14' "assets/bootstrap-set-$ARCH.txt"
- name: Upload the assets
if: steps.image.outputs.state == 'published'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: rootfs-${{ matrix.arch }}
path: assets/*
if-no-files-found: error
overwrite: true
retention-days: 7
- name: Upload the notes
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: meta-${{ matrix.arch }}
path: meta/*
if-no-files-found: error
overwrite: true
retention-days: 7
#--------------------------------------------------------------------------#
# Every published tag with its digest, read from the registry.
#--------------------------------------------------------------------------#
manifest:
name: Manifest of tags
needs: guard
runs-on: ubuntu-24.04
timeout-minutes: 30
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Generate
env:
OWNER: ${{ github.repository_owner }}
run: |
set -euo pipefail
mkdir -p assets
owner="$(printf '%s' "$OWNER" | tr '[:upper:]' '[:lower:]')"
SOURCE_COMMIT="$GITHUB_SHA" scripts/gen-manifest "ghcr.io/$owner/archlinux" assets/manifest.json
jq '{schema, image, tag_count, resolved_count, generated}' assets/manifest.json
- name: Upload
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: manifest
path: assets/*
if-no-files-found: error
overwrite: true
retention-days: 7
#--------------------------------------------------------------------------#
# Publish. Only when guard chose to publish and every job above succeeded.
# ⛔ contents: write is on this job only.
#--------------------------------------------------------------------------#
publish:
name: Publish the release
needs: [guard, pacman, rootfs, manifest]
if: needs.guard.outputs.publish == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 90
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Each artifact in its own directory: dl/<artifact name>/.
- name: Download every artifact
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
path: dl
- name: Sort the assets and the notes
run: |
set -euo pipefail
mkdir -p assets meta
for d in dl/*/; do
case "$(basename "$d")" in
meta-*) cp -- "$d"* meta/ ;;
*) cp -- "$d"* assets/ ;;
esac
done
ls -l assets meta
# ⛔ release-notes refuses a release with a hole. Each port of the port
# table has every asset, or meta/absent-<arch>.json says it has no image.
- name: Write the notes and SHA256SUMS
id: notes
env:
TAG: ${{ needs.guard.outputs.tag }}
run: |
set -euo pipefail
RELEASE_ARCHES="$(scripts/ports list | tr '\n' ' ')" \
scripts/release-notes assets "$TAG" meta > body.md
cat body.md >> "$GITHUB_STEP_SUMMARY"
# A new release starts as a draft. A draft has no git tag. The tag
# comes when the draft is published, after every asset is in place.
#
# The output state: "draft" when the draft has every asset of this run,
# "published" when the release is published already. ⛔ Then nothing is
# uploaded and the steps below do not run.
#
# ⛔ A draft at another commit is from an older run: its assets and its
# target are not this run. It is deleted and made again. gh release
# delete with no --cleanup-tag removes no git tag.
- name: Publish
id: publish
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.guard.outputs.tag }}
TARGET: ${{ github.sha }}
run: |
set -euo pipefail
rc=0
view="$(timeout -k 5 120 gh release view "$TAG" --repo "$GITHUB_REPOSITORY" \
--json isDraft,targetCommitish 2> view.err)" || rc=$?
make=1
if [ "$rc" -ne 0 ]; then
if ! awk 'index($0, "release not found") { hit = 1 } END { exit hit ? 0 : 1 }' view.err; then
echo "::error::gh release view $TAG exited $rc: $(tr '\n' ' ' < view.err)"
exit 1
fi
else
draft="$(jq -r '.isDraft' <<< "$view")"
at="$(jq -r '.targetCommitish' <<< "$view")"
if [ "$draft" != true ]; then
echo "state=published" >> "$GITHUB_OUTPUT"
echo "::notice::$TAG is published already, at $at. This run does not change it. To make it again, delete it first: gh release delete $TAG"
exit 0
fi
if [ "$at" = "$TARGET" ]; then
make=0
echo "::notice::$TAG is a draft at $TARGET. This run finishes it."
else
echo "::warning::$TAG is a draft at $at, and this run is at $TARGET. Deleting the draft to make it again."
timeout -k 5 120 gh release delete "$TAG" --repo "$GITHUB_REPOSITORY" --yes
fi
fi
if [ "$make" -eq 1 ]; then
timeout -k 5 300 gh release create "$TAG" --draft --repo "$GITHUB_REPOSITORY" \
--target "$TARGET" --title "$TAG" --notes-file body.md
echo "::notice::made the draft release $TAG at $TARGET"
fi
# ⛔ An asset that this run did not make is removed. SHA256SUMS
# covers only the assets of this run.
timeout -k 5 120 gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json assets \
--jq '.assets[].name' > remote-names.txt
while IFS= read -r name; do
[ -n "$name" ] || continue
if [ ! -f "assets/$name" ]; then
echo "::notice::removing $name from the draft $TAG: this run did not make it"
timeout -k 5 120 gh release delete-asset "$TAG" "$name" --repo "$GITHUB_REPOSITORY" --yes
fi
done < remote-names.txt
for n in 1 2 3; do
rc=0
timeout -k 10 3600 gh release upload "$TAG" --repo "$GITHUB_REPOSITORY" --clobber assets/* || rc=$?
[ "$rc" -eq 0 ] && break
echo "::warning::gh release upload exited $rc (try $n of 3)"
[ "$n" -lt 3 ] && sleep $((n * 30))
done
[ "$rc" -eq 0 ] || { echo "::error::the upload failed 3 times. Run the workflow again to finish $TAG."; exit 1; }
timeout -k 5 300 gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --notes-file body.md
echo "state=draft" >> "$GITHUB_OUTPUT"
# ⛔ The draft has each local asset with the same size, and no other
# asset, before it is published.
- name: Check the uploaded assets
id: verify
if: steps.publish.outputs.state == 'draft'
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.guard.outputs.tag }}
run: |
set -euo pipefail
timeout -k 5 120 gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json assets \
--jq '.assets[] | "\(.name) \(.size)"' > remote.txt
missing=""
for f in assets/*; do
want="$(basename "$f") $(stat -c %s "$f")"
if ! awk -v w="$want" '$0 == w { hit = 1 } END { exit hit ? 0 : 1 }' remote.txt; then
missing="$missing $(basename "$f")"
fi
done
if [ -n "$missing" ]; then
echo "::error::these assets are missing on $TAG or have another size:$missing"
echo "reproduce: gh release view $TAG --json assets"
exit 1
fi
extra="$(awk 'NR == FNR { local[$1] = 1; next } !($1 in local) { printf "%s ", $1 }' \
<(find assets -maxdepth 1 -type f -printf '%f\n') remote.txt)"
if [ -n "$extra" ]; then
echo "::error::$TAG also has assets that this run did not make: $extra"
echo "reproduce: gh release view $TAG --json assets"
exit 1
fi
echo "::notice::$(awk 'END { print NR }' remote.txt) assets on $TAG"
- name: Publish the draft
id: undraft
if: steps.publish.outputs.state == 'draft'
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.guard.outputs.tag }}
run: |
set -euo pipefail
timeout -k 5 300 gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --draft=false
echo "::notice::published https://github.com/$GITHUB_REPOSITORY/releases/tag/$TAG"
#--------------------------------------------------------------------------#
# ⭐ A scheduled run fires once a month, so one failure raises
# failing-release. scripts/watch-schedules raises the same key only after 3
# failed runs, and leaves it open while the newest run failed. A scheduled
# run that succeeds clears it.
#--------------------------------------------------------------------------#
report:
name: Report
needs: [guard, pacman, rootfs, manifest, publish]
if: ${{ always() && github.event_name == 'schedule' }}
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: read
issues: write
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Raise or clear failing-release
id: report
env:
GH_TOKEN: ${{ github.token }}
NEEDS: ${{ toJSON(needs) }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
set -euo pipefail
results="$(jq -r 'to_entries | map("\(.key) \(.value.result)") | join(", ")' <<< "$NEEDS")"
failed="$(jq -r '[.[].result | select(. == "failure" or . == "cancelled")] | length' <<< "$NEEDS")"
if [ "$failed" -eq 0 ]; then
scripts/track-issue clear failing-release "The scheduled release run succeeded: $RUN_URL"
exit 0
fi
body="$RUNNER_TEMP/failing-release.md"
{
echo "The scheduled release run failed: $RUN_URL"
echo
echo "Job results: $results"
echo
echo "reproduce: gh run view ${RUN_URL##*/} --log-failed"
} > "$body"
scripts/track-issue raise failing-release "release: the scheduled run failed" "$body"