Repository navigation
742 lines (663 loc) · 27 KB
/
Copy pathgo.yml
File metadata and controls
742 lines (663 loc) · 27 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
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
name: Go
on:
push:
branches: [ "main" ]
tags: [ "v*" ]
pull_request:
branches: [ "main" ]
# GoReleaser builds, signs and uploads releases, so it is pinned like every
# other tool here rather than floating on "~> v2" (#324). Dependabot does not
# read action inputs: to bump it, change this one line after checking the
# GoReleaser release notes; the release-snapshot job runs the new version on
# that push, before any tag uses it.
env:
GORELEASER_VERSION: v2.20.2
jobs:
# Two legs: "minimum" proves the go.mod floor (1.26.0) still builds and
# passes; "stable" is the toolchain releases are built with, and is where
# lint and govulncheck run (#38).
build:
timeout-minutes: 20
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
go: [ minimum, stable ]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
- name: Read Go language minimum
if: matrix.go == 'minimum'
id: go-minimum
shell: bash
run: echo "version=$(sed -n 's/^go //p' go.mod)" >> "$GITHUB_OUTPUT"
- name: Set up Go (go.mod minimum)
if: matrix.go == 'minimum'
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
with:
go-version: ${{ steps.go-minimum.outputs.version }}
cache: false
- name: Set up Go (latest stable)
if: matrix.go == 'stable'
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
with:
go-version: stable
check-latest: true
cache: false
- name: Cache Go build artifacts
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go }}-
- name: Verify dependencies
run: go mod verify
# verify checks hashes, not tidiness: this fails on a go.mod or go.sum
# that `make tidy` would change.
- name: Check go.mod and go.sum are tidy
run: go mod tidy -diff
- name: Check go directive
shell: bash
run: |
want='go 1.26.0'
got=$(grep -m1 '^go ' go.mod)
if [ "$got" != "$want" ]; then
echo "go.mod directive drifted: got '$got', want '$want'. Run 'make tidy'."
exit 1
fi
- name: Build
run: go build -v -buildvcs=false -ldflags "-X main.Version=$(git describe --tags --dirty)" ./...
- name: Test
run: go test -v -race -shuffle=on -coverpkg=./... -coverprofile=coverage.out ./...
# Coverage is printed and kept per run, and must stay above a floor (#170).
# -coverpkg counts code a package is exercised through from another (the
# CLI tests drive internal/report, for one), so the floor can sit near the
# real total, about 92% (#261).
- name: Coverage
if: matrix.go == 'stable'
shell: bash
run: |
total=$(go tool cover -func=coverage.out | awk '/^total:/ { sub("%", "", $3); print $3 }')
echo "Total coverage: ${total}%" | tee -a "$GITHUB_STEP_SUMMARY"
awk -v t="$total" 'BEGIN { exit !(t >= 85) }' || { echo "coverage ${total}% is below the 85% floor"; exit 1; }
- name: Upload coverage
if: matrix.go == 'stable'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: coverage
path: coverage.out
retention-days: 14
# Every generated completion script must parse in the shell it targets
# (#117); pwsh is preinstalled on the runner.
- name: Check completion scripts
if: matrix.go == 'stable'
run: |
sudo apt-get update -qq
sudo apt-get install -y -qq --no-install-recommends zsh fish
dir=$(mktemp -d)
go run . generate-assets "$dir"
bash -n "$dir/completions/subenum.bash"
zsh -n "$dir/completions/_subenum"
fish --no-execute "$dir/completions/subenum.fish"
pwsh -NoProfile -Command "\$null = [ScriptBlock]::Create((Get-Content -Raw '$dir/completions/subenum.ps1'))"
# Lint on the stable leg: golangci-lint must be built with a Go at least as
# new as the toolchain it analyses (v2.12 could not type-check Go 1.27).
- name: Run golangci-lint
if: matrix.go == 'stable'
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9
with:
version: v2.15.0
# Fails on vulnerabilities reachable from this code, in dependencies or in
# the Go standard library of the toolchain releases are built with.
- name: Run govulncheck
if: matrix.go == 'stable'
run: go run golang.org/x/vuln/cmd/govulncheck@v1.9.0 ./...
# The unit tests on macOS and Windows, whose binaries ship too: file
# replacement, signals and paths differ there (#170). The race detector
# runs on Linux, in build.
test-os:
timeout-minutes: 20
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
os: [ macos-latest, windows-latest ]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
with:
go-version: stable
check-latest: true
cache: false
- name: Test
run: go test -shuffle=on ./...
# Runs the composite action (action.yml, #126) from this checkout against
# a lab zone on every runner OS: a scan, then a diff against its results.
action:
timeout-minutes: 20
runs-on: ${{ matrix.os }}
permissions:
contents: read
actions: read # the baseline-artifact download (#352)
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
with:
go-version-file: 'go.mod'
cache: false
- name: Scan a lab zone with the action
id: scan
uses: ./
with:
version: source
domain: lab.example
# One flag per line: every line must reach subenum (the takeover
# check below needs -type CNAME from the second line, #363).
args: |
-simulate-zone examples/labs/lab1-first-scan.zone
-type A,CNAME
sarif: takeovers.sarif
- name: Check the first scan
shell: bash
run: |
set -euo pipefail
test "${{ steps.scan.outputs.verdict }}" = complete
test "${{ steps.scan.outputs.found }}" -ge 5
test "${{ steps.scan.outputs.takeovers }}" -ge 1
test "${{ steps.scan.outputs.internal }}" = 0
test -z "${{ steps.scan.outputs.changes }}"
grep -q 'dangling-cname' takeovers.sarif
cp "${{ steps.scan.outputs.results }}" previous.jsonl
echo "gone.lab.example" >> previous.jsonl
# Thousands of removed names make the job summary's list far longer
# than a pipe buffer, which the action must cut to 50 without
# failing its step (#345).
for i in $(seq 1 3000); do echo "gone$i.lab.example"; done >> previous.jsonl
- name: Diff against it
id: diff
uses: ./
with:
version: source
domain: lab.example
args: -simulate-zone examples/labs/lab1-first-scan.zone -type A,CNAME
previous: previous.jsonl
- name: Check the diff
shell: bash
run: |
test "${{ steps.diff.outputs.added }}" = 0
test "${{ steps.diff.outputs.removed }}" = 3001
grep -q '"change":"removed"' "${{ steps.diff.outputs.changes }}"
grep -q 'gone.lab.example' "${{ steps.diff.outputs.changes }}"
# A failed scan (a wildcard zone without -force exits 1 with an
# unreliable verdict) passes the step under fail-on: never (#363).
- name: Scan a wildcard zone with fail-on never
id: wildcard
uses: ./
with:
version: source
domain: lab.example
args: -simulate-zone examples/labs/lab2-wildcard.zone
fail-on: never
- name: Check the failed scan
shell: bash
run: test "${{ steps.wildcard.outputs.verdict }}" = unreliable
# A use that exits before writing its report must not report the
# previous use's verdict (#363).
- name: Use the action with a bad flag
id: bad
continue-on-error: true
uses: ./
with:
version: source
domain: lab.example
args: -simulate -no-such-flag
- name: Check it reported nothing
shell: bash
run: |
test "${{ steps.bad.outcome }}" = failure
test -z "${{ steps.bad.outputs.verdict }}"
# -version exits 0 before the outputs are opened, so no report is written.
# The step must still fail rather than pass on the previous use's outputs (#407).
- name: Use the action with -version
id: version
continue-on-error: true
uses: ./
with:
version: source
domain: lab.example
args: -version
- name: Check it failed without a report
shell: bash
run: |
test "${{ steps.version.outcome }}" = failure
test -z "${{ steps.version.outputs.verdict }}"
# found counts the -permute hits too (#363).
- name: Scan with -permute
id: permute
uses: ./
with:
version: source
domain: example.com
wordlist: examples/labs/words.txt
args: -simulate -seed 7 -hit-rate 80 -permute
- name: Check found counts the permutation hits
shell: bash
run: |
set -euo pipefail
names=$(jq -n '[inputs | select(.subdomain)] | length' "${{ steps.permute.outputs.results }}")
echo "found=${{ steps.permute.outputs.found }} names=$names"
test "${{ steps.permute.outputs.found }}" = "$names"
test "$names" -gt 100
# A time-boxed scan carries its resume state in the baseline artifact,
# and the next use continues it rather than starting over (#352). -rate
# 5 makes the 31-name wordlist outlast the first use's 2s budget. The
# later uses read the copy the action kept in this job, not the artifact
# list, which can lag the upload by seconds.
- name: Stop a scan at its time budget
id: stopped
uses: ./
with:
version: source
domain: example.com
wordlist: examples/labs/words.txt
args: -simulate -seed 7 -rate 5 -t 1
max-duration: 2s
baseline-artifact: subenum-ci-resume-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.os }}
- name: Continue it
id: resumed
uses: ./
with:
version: source
domain: example.com
wordlist: examples/labs/words.txt
args: -simulate -seed 7 -rate 5 -t 1
max-duration: 5m
baseline-artifact: subenum-ci-resume-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.os }}
- name: Diff the next scan against the finished one
id: after
uses: ./
with:
version: source
domain: example.com
wordlist: examples/labs/words.txt
args: -simulate -seed 7 -rate 5 -t 1
baseline-artifact: subenum-ci-resume-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.os }}
- name: Check the scan resumed and then set the baseline
shell: bash
run: |
set -euo pipefail
test "${{ steps.stopped.outputs.verdict }}" = degraded
test "${{ steps.stopped.outputs.resumed }}" = false
test "${{ steps.resumed.outputs.resumed }}" = true
test "${{ steps.resumed.outputs.verdict }}" = complete
test "${{ steps.resumed.outputs.found }}" -ge 1
# The stopped use had no baseline yet, so neither did its resumption.
test -z "${{ steps.resumed.outputs.changes }}"
test "${{ steps.after.outputs.resumed }}" = false
test "${{ steps.after.outputs.verdict }}" = complete
test -n "${{ steps.after.outputs.changes }}"
test "${{ steps.after.outputs.added }}" = 0
test "${{ steps.after.outputs.removed }}" = 0
# A resumed scan that finishes degraded leaves no state of its own; the
# artifact must drop the spent state so the next use starts over rather
# than resuming the same remainder forever (#396). Lab 5's timeouts make
# every pass degraded.
- name: Stop a failing scan at its time budget
id: stopped-degraded
uses: ./
with:
version: source
domain: example.com
wordlist: examples/labs/words.txt
args: -simulate-zone examples/labs/lab5-failures.zone -seed 7 -rate 5 -t 1
max-duration: 2s
baseline-artifact: subenum-ci-resume-degraded-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.os }}
- name: Continue it to a degraded finish
id: resumed-degraded
uses: ./
with:
version: source
domain: example.com
wordlist: examples/labs/words.txt
args: -simulate-zone examples/labs/lab5-failures.zone -seed 7 -rate 5 -t 1
max-duration: 5m
baseline-artifact: subenum-ci-resume-degraded-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.os }}
- name: Start over after the degraded finish
id: after-degraded
uses: ./
with:
version: source
domain: example.com
wordlist: examples/labs/words.txt
args: -simulate-zone examples/labs/lab5-failures.zone -seed 7 -rate 5 -t 1
max-duration: 2s
baseline-artifact: subenum-ci-resume-degraded-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.os }}
- name: Check the spent state was not resumed again
shell: bash
run: |
set -euo pipefail
test "${{ steps.stopped-degraded.outputs.resumed }}" = false
test "${{ steps.resumed-degraded.outputs.resumed }}" = true
test "${{ steps.resumed-degraded.outputs.verdict }}" = degraded
test "${{ steps.after-degraded.outputs.resumed }}" = false
# The action's default install path, as users get it: download the latest
# release, check it against checksums.txt and its attestation, unpack it
# (#325). The action job above builds from source and never reaches that
# branch. Pushes to main only, since it needs a published release and the
# network. A fresh job with no Go setup and no earlier build, so the scan
# can only run the binary the release install put on PATH. The permissions
# match the monitoring guide's example workflow. The scan uses -simulate
# rather than a lab zone file from this checkout, whose format can be
# newer than the release.
action-release:
timeout-minutes: 15
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Scan with the latest release
id: scan
uses: ./
with:
version: latest
domain: lab.example
args: -simulate
- name: Check the scan
shell: bash
run: |
set -euo pipefail
test "${{ steps.scan.outputs.verdict }}" = complete
test "${{ steps.scan.outputs.found }}" -ge 1
test -s "${{ steps.scan.outputs.results }}"
# Builds the Dockerfile for both published platforms without pushing, so a
# broken image is caught on the PR rather than during a release.
docker:
timeout-minutes: 30
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
- name: Build image (no push)
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
with:
context: .
platforms: linux/amd64,linux/arm64
push: false
build-args: VERSION=ci
# Runs the full GoReleaser pipeline in snapshot mode on every push to main
# (no signing, no publishing), so .goreleaser.yaml is exercised long before
# a tag depends on it (#61).
release-snapshot:
timeout-minutes: 30
needs: build
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
with:
go-version: stable
check-latest: true
cache: false
- name: Install syft (SBOMs)
uses: anchore/sbom-action/download-syft@66cbf4bc1f1c0d2edc94016e65bc221b6bb0ad6c # v0.24.3
- name: GoReleaser snapshot
uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7.3.0
with:
version: ${{ env.GORELEASER_VERSION }}
args: release --snapshot --clean --skip=sign
- name: Assert static Linux binaries
shell: bash
run: |
for f in dist/subenum_linux_*/subenum; do
file "$f"
file "$f" | grep -q 'statically linked'
done
# The archives ship generated completions and a man page (#88); make sure
# each one parses in its own shell, and the man page renders cleanly.
- name: Check completions and man page
shell: bash
run: |
sudo apt-get update -qq
sudo apt-get install -y -qq --no-install-recommends zsh fish groff
tar -xzf dist/subenum_*_linux_amd64.tar.gz -C "$RUNNER_TEMP"
bash -n "$RUNNER_TEMP/completions/subenum.bash"
zsh -n "$RUNNER_TEMP/completions/_subenum"
fish -n "$RUNNER_TEMP/completions/subenum.fish"
pwsh -NoProfile -Command "\$e = \$null; [void][System.Management.Automation.Language.Parser]::ParseFile('$RUNNER_TEMP/completions/subenum.ps1', [ref]\$null, [ref]\$e); if (\$e) { \$e; exit 1 }"
test -z "$(groff -man -ww -z "$RUNNER_TEMP/man/subenum.1" 2>&1)"
# Builds and publishes a release from a v* tag with GoReleaser (#61):
# static binaries (#46), archives with LICENSE/README/CHANGELOG,
# checksums.txt, SBOMs, a keyless cosign signature over the checksums, and
# release notes from the tag's CHANGELOG.md section. GoReleaser creates the
# release as a draft; it is published only after provenance is attested, so
# the public never sees a partial release (cleanup-failed-release removes a
# failed draft). It waits for every test job, the macOS and Windows tests
# and the action included, since their binaries and the action ship too.
release:
timeout-minutes: 30
needs: [ build, test-os, action, docker ]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
attestations: write
# Needed to start the GitHub Pages rebuild after the release is public
# (#370). Pages cannot be started by the release event itself, because
# GITHUB_TOKEN events do not trigger other workflows.
actions: write
steps:
# GoReleaser and gh take the token from the environment, so the checkout
# keeps no credentials in .git/config (#324).
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
persist-credentials: false
# Release binaries use the latest stable Go so they ship a patched
# standard library; go.mod's version is only the minimum (#38). No build
# cache here, so release artifacts are always built from scratch.
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
with:
go-version: stable
check-latest: true
cache: false
- name: Install syft (SBOMs)
uses: anchore/sbom-action/download-syft@66cbf4bc1f1c0d2edc94016e65bc221b6bb0ad6c # v0.24.3
- name: Install cosign (keyless signing)
uses: sigstore/cosign-installer@756fe2d284c7292c4e9b62c8a28f1e5629c59532 # v4.1.3
# CITATION.cff must name the release being cut (#102); checked before
# anything is built or published.
- name: Check CITATION.cff version
shell: bash
run: |
want="${GITHUB_REF_NAME#v}"
got=$(sed -n 's/^version: *//p' CITATION.cff)
if [ "$got" != "$want" ]; then
echo "::error::CITATION.cff says version $got but the tag is ${GITHUB_REF_NAME}; update version and date-released"
exit 1
fi
- name: Release notes from CHANGELOG.md
shell: bash
run: .github/scripts/release-notes.sh "${GITHUB_REF_NAME}" > "${RUNNER_TEMP}/notes.md"
- name: GoReleaser
uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7.3.0
with:
version: ${{ env.GORELEASER_VERSION }}
args: release --clean --release-notes=${{ runner.temp }}/notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Assert static Linux binaries
shell: bash
run: |
for f in dist/subenum_linux_*/subenum; do
file "$f"
file "$f" | grep -q 'statically linked'
done
- name: Attest build provenance
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4
with:
subject-path: |
dist/*.tar.gz
dist/*.zip
dist/checksums.txt
# Flipping draft to false is the moment the release becomes public.
- name: Publish release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: gh release edit "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" --draft=false
# pages.yml has a `release: published` trigger, but GitHub does not start a
# workflow for an event caused by GITHUB_TOKEN, so a GoReleaser publish
# never fires it (#370). Start the rebuild directly. It checks out main and
# the header reads the latest release from the Pages metadata, so the site
# shows the tag that was just published. The release is already public
# here and publish-image needs this job, so a failed rebuild is a warning,
# not a failed release; rerun pages.yml by hand if it happens.
- name: Rebuild GitHub Pages
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
before=$(date -u -d '10 seconds ago' +%Y-%m-%dT%H:%M:%SZ)
gh workflow run "GitHub Pages" --repo "${GITHUB_REPOSITORY}" --ref main
run_id=""
for _ in $(seq 1 10); do
run_id=$(gh run list --repo "${GITHUB_REPOSITORY}" --workflow "GitHub Pages" \
--event workflow_dispatch --limit 10 --json databaseId,createdAt \
| jq -r --arg before "$before" '[.[] | select(.createdAt > $before)][0].databaseId // empty')
if [ -n "${run_id}" ]; then
break
fi
sleep 3
done
if [ -z "${run_id}" ]; then
echo "GitHub Pages workflow run did not start" >&2
exit 1
fi
gh run watch "${run_id}" --repo "${GITHUB_REPOSITORY}" --exit-status
# Publishes a multi-arch image to GHCR once the release itself is public
# (#40). The Dockerfile cross-compiles in a build-platform builder stage, so
# arm64 needs no QEMU. `latest` only moves for non-prerelease tags.
publish-image:
timeout-minutes: 30
needs: release
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
attestations: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
# GHCR requires lowercase repository names; the owner is mixed case.
- name: Compute image name
id: image
shell: bash
env:
OWNER: ${{ github.repository_owner }}
run: echo "name=ghcr.io/${OWNER,,}/subenum" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
- name: Log in to GHCR
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Image metadata
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6
with:
images: ${{ steps.image.outputs.name }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ !contains(github.ref_name, '-') }}
- name: Build and push
id: push
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: VERSION=${{ github.ref_name }}
- name: Attest image provenance
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4
with:
subject-name: ${{ steps.image.outputs.name }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
# Failure-path cleanup. If the release job fails partway, the draft release
# GoReleaser created would otherwise linger
# invisibly until someone removes it by hand. This job runs only when a
# tag-triggered release run failed. It deletes the draft release for this tag
# and the tag ref so a partial release leaves nothing behind. It only ever
# deletes a draft (never a published release) and is a no-op when there is
# nothing to clean, so it is safe and idempotent.
cleanup-failed-release:
timeout-minutes: 5
needs: [release]
if: ${{ failure() && startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Remove draft release and tag for failed run
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ github.ref_name }}
REPO: ${{ github.repository }}
shell: bash
run: |
set -euo pipefail
# Every page: past 30 releases the draft is not on the first one.
rel=$(gh api --paginate "repos/${REPO}/releases?per_page=100" \
--jq ".[] | select(.tag_name==\"${TAG}\") | [.id, .draft] | @tsv" | awk 'NR==1')
if [ -z "${rel}" ]; then
echo "No release found for ${TAG}; nothing to clean."
exit 0
fi
id=$(printf '%s' "${rel}" | cut -f1)
draft=$(printf '%s' "${rel}" | cut -f2)
if [ "${draft}" != "true" ]; then
echo "Release ${id} for ${TAG} is published (draft=${draft}); leaving it intact."
exit 0
fi
echo "Deleting draft release ${id} for ${TAG}."
gh api -X DELETE "repos/${REPO}/releases/${id}"
echo "Deleting tag ref ${TAG}."
gh api -X DELETE "repos/${REPO}/git/refs/tags/${TAG}" || echo "Tag ref already removed."
echo "Cleanup complete for ${TAG}."