Repository navigation
802 lines (778 loc) · 42.9 KB
/
Copy pathzz_generated.auto_release.yaml
File metadata and controls
802 lines (778 loc) · 42.9 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
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
# DO NOT EDIT. Generated with:
#
# devctl
#
# https://github.com/giantswarm/devctl/blob/da5d8fd9f12cdfa92311ee00197d78e6626e2523/pkg/gen/input/workflows/internal/file/auto_release.yaml.template
#
# yamllint disable rule:truthy
# Push-based release tagger + release-page publisher.
#
# Runs on push to main (normal releases) and to backport branches
# (release-2.x, release-v3.7.x, etc. -- see `on:` block below for the
# exact pattern). Inspects conventional commits reachable from the pushed
# ref since the latest reachable v*.*.* tag via git-cliff, and:
#
# 1. creates the next git tag if a bump is warranted: a minor or major
# bump cuts the next vX.Y.0-rc.N release candidate, a patch of the last
# stable release (only fixes and chores since it) is tagged vX.Y.Z
# stable directly, so there is never a patch candidate
# 2. creates the matching GitHub Release with notes generated by git-cliff,
# a candidate flagged as a pre-release
# 3. checks that CircleCI picked the tag up and triggers the pipeline if
# the webhook got lost (repos with a .circleci/config.yml only)
#
# A minor or major vX.Y.0 is cut only by running this workflow by hand with
# `release-type: stable`, which promotes the latest release candidate, or
# the one `version` names: the stable tag lands on that candidate's commit,
# so what ships is what was tested.
#
# Tags and releases are created with the giantswarm-release GitHub App token,
# so GitHub Actions workflows listening on push.tags or release can start.
# Requires the App installed on this repository with Contents write and
# Workflows write (stable promotions, see the release token step), and the
# RELEASE_BOT_CLIENT_ID / RELEASE_BOT_PRIVATE_KEY secrets available to this
# workflow. Missing or unusable App credentials fail before creating a release;
# there is no GITHUB_TOKEN fallback, whose events cannot start those workflows.
#
# The tag push then triggers downstream publishing (for chart/service/CLI
# repos, this is the CircleCI architect pipeline firing on the same /^v.*/
# tag filter -- go-build + push-to-registries + push-to-app-catalog +
# upload-release-assets as appropriate for the repo type). Architect appends
# any binary artifacts to the release we just created here.
name: Auto-release
on:
push:
branches:
- main
# Maintenance / backport branches, matched whole: a branch that only
# starts like one (a pull-request branch off release-v3.x) must not
# cut a release from unreviewed commits.
#
# MATCHES: release-2.x, release-2.3.x, release-v2.x, release-v3.7.x
# NO MATCH: release-notes, release-v3.x-fix, release-v3.7.x-backport
- 'release-[0-9]+.x'
- 'release-[0-9]+.[0-9]+.x'
- 'release-v[0-9]+.x'
- 'release-v[0-9]+.[0-9]+.x'
# `auto` applies the same rule as a push, which is what a re-run wants.
# `stable` promotes the latest release candidate since the last stable
# release, and fails when there is none; `version` names an older one of
# those candidates to promote instead.
workflow_dispatch:
inputs:
release-type:
description: 'Which kind of release to cut'
type: choice
options: [auto, stable]
default: auto
version:
description: 'With stable: the release candidate to promote, vX.Y.Z-rc.N; empty promotes the latest'
type: string
required: false
default: ''
permissions: {}
# Scope the concurrency lock per branch so a backport tag on release-2.x
# doesn't block (or get blocked by) a main release, and vice versa. A second
# push to the same branch while a tag is being computed still waits.
concurrency:
group: auto-release-${{ github.ref_name }}
cancel-in-progress: false
jobs:
tag:
name: Tag
runs-on: ubuntu-26.04
permissions:
contents: read # checkout and fetch; the App creates tags/releases
# git-cliff's GitHub API lookups (commit.remote.pr_number / username
# in release notes) need PR read access via GITHUB_TOKEN.
pull-requests: read
# The stable run reads the commit statuses of the candidate it promotes,
# and every run with a tag those of the tag's CircleCI build.
statuses: read
# A promotion queues an auto run for commits left on the branch.
actions: write
outputs:
# The stable tag this run released, empty for a candidate or no release.
# Read from the release step, so a failure of the CircleCI check after
# it still reaches the changelog job.
stable: ${{ steps.release.outcome == 'success' && steps.decide.outputs.prerelease == 'false' && steps.decide.outputs.tag || '' }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # full history so git-cliff sees every commit
fetch-tags: true # ensure tags are present (shallow runners drop them by default)
# Install git-cliff once and call it from shell so we can do all the
# expensive work (commits walk + GitHub API PR lookups) in a single
# invocation, then cheaply re-render from the cached JSON context.
- name: Install git-cliff
uses: giantswarm/install-binary-action@5bef88f65012037dd836117c8d344b21bb559854 # v4.1.0
with:
binary: git-cliff
version: "2.13.1"
# yamllint disable-line rule:line-length
download_url: 'https://github.com/orhun/git-cliff/releases/download/v${version}/git-cliff-${version}-x86_64-unknown-linux-gnu.tar.gz'
tarball_binary_path: 'git-cliff-${version}/git-cliff'
smoke_test: '${binary} --version'
# A stable release promotes the latest release candidate since the last
# stable release rather than tagging the branch head: whatever merged
# after that candidate has not run as one. Checking the candidate out
# before git-cliff runs keeps the version, the notes and the tag's
# commit all on what was tested.
- name: Resolve the candidate to promote
id: promote
if: inputs.release-type == 'stable'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PROMOTE_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
# The same baseline as the decide step below.
last=${LINE_TAG:-$(git describe --tags --abbrev=0 --match='v*.*.*' --exclude='*-*' --exclude='*+*' 2>/dev/null || echo "")}
# `--merged HEAD` keeps a candidate cut on another branch out;
# `--no-merged` drops the candidates the last stable release already
# contains. `sort -V` orders rc.10 after rc.9 and a moved target
# (v2.0.0-rc.1 after v1.3.0-rc.2) after the one it replaced.
# `|| true`: grep exits 1 when there is no candidate at all.
candidates=$(git tag --list --merged HEAD ${last:+--no-merged "$last"} 'v*.*.*-rc.*' \
| { grep -E -- '-rc\.[0-9]+$' || true; } | sort -V)
if [ -z "$candidates" ]; then
echo "::error title=No release candidate to promote::no release candidate since ${last:-inception} on ${GITHUB_REF_NAME}. A minor or major push cuts one; a patch is tagged stable on its push and has none."
exit 1
fi
rc=$(tail -n 1 <<<"$candidates")
# A named candidate (`devctl release promote --version`) is promoted
# instead of the latest, when it is one of the same candidates: one
# that is built while a later one still builds, or the one proven.
if [ -n "${PROMOTE_VERSION:-}" ]; then
if ! grep -qxF -- "$PROMOTE_VERSION" <<<"$candidates"; then
echo "::error title=Not a release candidate to promote::${PROMOTE_VERSION} is not a release candidate since ${last:-inception} on ${GITHUB_REF_NAME}; the candidates are $(paste -sd ' ' <<<"$candidates")."
exit 1
fi
rc=$PROMOTE_VERSION
fi
# The tag alone does not say the candidate was built. Its GitHub
# pre-release is created with the tag, and the pipelines that build
# and publish it report on its commit: a failed or still running one
# refuses the promotion. A commit no pipeline reports on has nothing
# to wait for. A failed CircleCI job the release does not require
# (advisory_jobs, the rule `devctl release wait` and `devctl release
# promote` apply) is a warning, not a refusal.
if ! prerelease=$(gh release view "$rc" --json isPrerelease --jq .isPrerelease 2>/dev/null); then
echo "::error title=Candidate not released::${rc} has no GitHub release; the run that cut it did not finish. Cut a new candidate."
exit 1
fi
if [ "$prerelease" != true ]; then
echo "::error title=Candidate not a pre-release::the GitHub release of ${rc} is not a pre-release."
exit 1
fi
# The API now and then answers with an empty or truncated body or a
# 5xx: the read is retried with backoff, and only a failure on every
# try refuses the promotion. The answer's first line is the number
# of contexts, every further one a context's latest
# "<state> <context>".
request="repos/${GH_REPO}/commits/${rc}/status"
tries=4
for try in $(seq 1 "$tries"); do
if statuses=$(gh api -X GET "$request" -F per_page=100 --jq '.total_count, (.statuses[] | "\(.state) \(.context)")') \
&& count=$(head -n 1 <<<"$statuses") && [[ "$count" =~ ^[0-9]+$ ]]; then
break
fi
if [ "$try" = "$tries" ]; then
echo "::error title=Candidate status unreadable::GET ${request} failed ${tries} times (the job needs statuses: read); nothing is promoted."
exit 1
fi
echo "GET ${request} failed (try ${try} of ${tries}), retrying in $((2 ** try))s"
sleep $((2 ** try))
done
advisory_jobs=" sync-china-registry "
failed=() running=() advisory=()
while read -r state context; do
case "$state" in
success) ;;
failure | error)
if [[ "$context" == "ci/circleci: "* && "$advisory_jobs" == *" ${context#ci/circleci: } "* ]]; then
advisory+=("$context")
else
failed+=("${context} (${state})")
fi
;;
*) running+=("$context") ;;
esac
done < <(tail -n +2 <<<"$statuses")
commit="https://github.com/${GH_REPO}/commit/$(git rev-parse "${rc}^{commit}")"
if [ "${#failed[@]}" != 0 ]; then
printf -v list '%s, ' "${failed[@]}"
echo "::error title=Candidate not built::the commit statuses of ${rc} are failure: ${list%, } on ${commit}. Promote it once its pipelines passed."
exit 1
fi
if [ "${#running[@]}" != 0 ]; then
printf -v list '%s, ' "${running[@]}"
echo "::error title=Candidate not built::the commit statuses of ${rc} are pending: ${list%, } on ${commit}. Promote it once its pipelines passed."
exit 1
fi
for context in "${advisory[@]}"; do
echo "::warning title=Advisory status failed::the commit status ${context} of ${rc} failed; the release does not require it, so the candidate is judged without it."
done
after=$(git log --format='%h %s' "${rc}..HEAD")
git checkout -q --detach "$rc"
echo "promoting ${rc} at $(git rev-parse --short HEAD)"
if [ -n "$after" ]; then
echo "not in this release, merged after ${rc}; they go in the next candidate:"
echo "$after"
{
echo "### Not in this release"
echo "Merged after ${rc}; they go in the next candidate."
echo '```'
echo "$after"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
fi
echo "rc=${rc}" >> "$GITHUB_OUTPUT"
- name: Compute next version
id: cliff
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
# One context read: walks commits, queries the GitHub API for
# per-commit PR lookups, emits the JSON context for ONLY the bumped
# release.
#
# Flag choice matters here. Both `--latest` and `--unreleased`
# *look* like single-release filters, but only one composes with
# `--bump`:
# --latest --bump : returns the latest EXISTING tag -- drops the
# bump silently. We don't want this.
# --unreleased --bump : filters to commits that aren't in any tag
# yet, computes the bumped version from
# them, returns JSON for that bumped
# release only. This is what we want.
#
# Without either filter, --bump --context returns the full release
# history in JSON and the render step below would concatenate every
# past release into each new release's notes.
# GitHub metadata reads can fail on a transient timeout, truncated
# response or 5xx. Retry with bounded backoff. Keep stderr in the
# log, including the final cause, and replace any partial context
# on each attempt before downstream steps can use it.
cliff_context() {
local try tries=3 status
for ((try=1; try<=tries; try++)); do
if git-cliff "$@" > cliff-context.json; then
return 0
else
status=$?
fi
if [ "$try" -eq "$tries" ]; then
echo "::error title=git-cliff failed::git-cliff failed after ${tries} attempts (exit ${status}); see its error above." >&2
return "$status"
fi
echo "git-cliff failed (attempt ${try} of ${tries}, exit ${status}); retrying in $((2 ** try))s" >&2
sleep $((2 ** try))
done
}
cliff_context --unreleased --bump --context
NEXT=$(jq -r '.[0].version // empty' cliff-context.json)
echo "next computed: ${NEXT:-<empty>}"
echo "version=${NEXT}" >> "$GITHUB_OUTPUT"
# Every releasable push cuts the next candidate for the version
# git-cliff computed; `stable` tags that version itself, on the
# candidate the step above checked out.
- name: Decide whether to tag
id: decide
env:
NEXT: ${{ steps.cliff.outputs.version }}
WANT: ${{ inputs.release-type || 'auto' }}
PROMOTE: ${{ steps.promote.outputs.rc }}
CLIFF_CONTEXT: cliff-context.json
run: |
set -euo pipefail
# `git describe --tags --abbrev=0` returns the closest tag reachable
# from HEAD -- NOT the highest tag in the repo overall. This matters
# for backports: on release-2.x, HEAD's reachable history terminates
# before v3.0.0 was tagged, so describe correctly returns v2.3.5
# (the baseline of the 2.x line) and we end up tagging v2.3.6 rather
# than something nonsensical relative to v3.0.0.
#
# The excludes hold this baseline to the tags cliff.toml's
# `tag_pattern` counts as releases: `*-*` drops a pre-release name,
# `*+*` a build-metadata one. A tag only one of the two recognises
# splits `last` from `NEXT`, the `NEXT = last` comparison below can
# never be true again, and the job tags on every push even when
# there is nothing to release.
last=${LINE_TAG:-$(git describe --tags --abbrev=0 --match='v*.*.*' --exclude='*-*' --exclude='*+*' 2>/dev/null || echo "")}
echo "branch: ${GITHUB_REF_NAME}"
echo "last reachable stable tag: ${last:-<none>}"
unconventional=0
while IFS= read -r -d '' subject; do
# git-cliff takes letters, digits, `_` and `-` as a type.
if ! printf '%s' "$subject" | grep -qE '^[A-Za-z0-9_-]+(\([^)]*\))?!?: '; then
# git-cliff drops a subject it cannot parse as conventional
# (`filter_unconventional`): the commit neither bumps the
# version nor appears in any release's notes, silently. The
# title check guards the pull request's title, but a
# one-commit pull request squash-merges under its commit's
# own subject unless the repository names the squash commit
# after the title (squash_merge_commit_title PR_TITLE, the
# repository baseline). Say so where the run is read.
unconventional=$((unconventional + 1))
echo "::warning title=Unconventional commit subject::\"${subject}\" is not a conventional commit: git-cliff neither releases nor lists it. A one-commit pull request merges under its commit's subject unless the repository's squash commit title is PR_TITLE."
fi
done < <(git log ${last:+"${last}..HEAD"} -z --format='%s')
echo "unreleased commits: ${unconventional} unconventional (neither released nor listed)"
if [ "$WANT" = stable ]; then
is_rc=false
else
is_rc=true
fi
# `NEXT` equal to `last` means nothing releasable landed since the
# last stable release, so there is no candidate to cut either:
# without this the run cuts ${last}-rc.$(( n + 1 )), a candidate for
# a version that already shipped.
if [ -z "${NEXT}" ] || [ "${NEXT}" = "${last}" ]; then
echo "No releasable commits since ${last:-inception}; skipping tag."
echo "tag=" >> "$GITHUB_OUTPUT"
echo "prerelease=" >> "$GITHUB_OUTPUT"
exit 0
fi
# A patch of the last stable release (`NEXT` keeps its major and
# minor: only fixes and chores since it) takes the fast path and is
# tagged stable on this push: there is no patch candidate. A fix
# during a minor or major cycle moves no target and rides that
# cycle's next candidate.
if [ "$is_rc" = true ] && [ -n "$last" ] && [ "${NEXT%.*}" = "${last%.*}" ]; then
is_rc=false
echo "${NEXT} is a patch of ${last}: tagged stable, no candidate"
fi
if [ "$is_rc" = true ]; then
# Highest existing RC for this exact target, so a moved target
# (a breaking change during a cycle) restarts at rc.1, and rc.9 is
# followed by rc.10 rather than rc.2. `--merged HEAD` scopes the
# search the way the describe baseline above is scoped: a candidate
# for the same target cut on another branch must not shift the
# numbering on this one. A re-pinned fork line is the exception:
# its earlier candidates for the same target are on the history
# the rebase left behind, unreachable but this branch's own, and
# their tags still exist, so the count takes every tag of the
# target or the push would try to cut a tag that already exists.
# `|| true`: grep exits 1 on the first candidate of a series,
# when no ${NEXT}-rc.* tag exists yet, and pipefail would abort.
scope=(--merged HEAD)
if [ "${LINE_REPINNED:-}" = true ]; then
scope=()
fi
n=$(git tag --list ${scope[@]+"${scope[@]}"} "${NEXT}-rc.*" | sed 's/.*-rc\.//' | { grep -E '^[0-9]+$' || true; } | sort -n | tail -1)
# `NEXT` stays ahead of `last` until the stable release, so the
# comparison above cannot stop a push that carries only commits
# git-cliff skips (docs, style) or drops as non-conventional.
# Without this check that push spends an rc number, a GitHub
# pre-release and a publish pipeline on a README typo.
#
# cliff-context.json holds exactly the commits git-cliff counted
# for this release, so intersecting it with the range since the
# last candidate needs no second copy of cliff.toml's skip rules.
# A new conventional `test:` commit is also enough once this
# target has a candidate: a test fix must be able to replace a
# red candidate. It opens no cycle and changes no version or notes.
if [ -n "${n}" ]; then
counted=$(jq -r '.[0].commits[].id' "$CLIFF_CONTEXT")
since=$(git rev-list "${NEXT}-rc.${n}..HEAD")
fresh=0
if [ -n "$counted" ] && [ -n "$since" ]; then
fresh=$(printf '%s\n' "$since" | { grep -cxF "$counted" || true; })
fi
if [ "$fresh" -eq 0 ]; then
fresh=$(git log --format='%s' "${NEXT}-rc.${n}..HEAD" \
| { grep -cE '^test(\([^)]*\))?!?: ' || true; })
fi
if [ "$fresh" -eq 0 ]; then
echo "No releasable commits since ${NEXT}-rc.${n}; skipping tag."
echo "tag=" >> "$GITHUB_OUTPUT"
echo "prerelease=" >> "$GITHUB_OUTPUT"
exit 0
fi
fi
# The next number skips a name a tag already holds off this
# branch: a candidate tagged by hand on a pull request's branch to
# prove it, whose commits a rebase merge rewrote. The release is
# created through the API by its tag name, and GitHub attaches it
# to an existing tag's commit instead of creating the tag here.
n=${n:-0}
while git rev-parse -q --verify "refs/tags/${NEXT}-rc.$(( n + 1 ))" >/dev/null; do
echo "${NEXT}-rc.$(( n + 1 )) is taken by $(git rev-parse --short "${NEXT}-rc.$(( n + 1 ))^{commit}"), not on ${GITHUB_REF_NAME}; skipping the number"
n=$(( n + 1 ))
done
tag="${NEXT}-rc.$(( n + 1 ))"
elif [ "$WANT" != stable ]; then
tag="${NEXT}"
else
# git-cliff ran on the promoted candidate, so it has to land on
# that candidate's own version. A mismatch means the candidate's
# tag and its commits disagree; tagging either would ship a
# version nobody tested.
if [ "${PROMOTE%-rc.*}" != "${NEXT}" ]; then
echo "::error title=Candidate does not match::${PROMOTE} is a candidate for ${PROMOTE%-rc.*}, but its commits release ${NEXT}."
exit 1
fi
tag="${NEXT}"
fi
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
echo "prerelease=${is_rc}" >> "$GITHUB_OUTPUT"
echo "target=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
# One commit releases one version: the release tags of two versions on
# one commit give two answers to "which version is this", and every
# reader (a release wait, a rollout, a person) picks its own. A
# candidate and its promoted stable share a commit by design, and an
# upstream pre-release outside the release pattern names no release of
# this repository. The tags are read from the remote, not from this
# checkout: the fork baseline step may move one here, and a run on
# another branch may have tagged the commit since the checkout.
- name: Refuse another version's tag on the commit
id: one-version
if: steps.decide.outputs.tag != ''
env:
TAG: ${{ steps.decide.outputs.tag }}
TARGET: ${{ steps.decide.outputs.target }}
run: |
set -euo pipefail
release='^v?([0-9]+\.[0-9]+\.[0-9]+)(-rc\.[0-9]+)?$'
[[ "$TAG" =~ $release ]]
version=${BASH_REMATCH[1]}
# An annotated tag is listed twice, its peeled commit under ^{}:
# only that line matches the commit.
conflicts=()
while read -r sha ref; do
tag=${ref#refs/tags/}
tag=${tag%'^{}'}
if [ "$sha" = "$TARGET" ] && [[ "$tag" =~ $release ]] && [ "${BASH_REMATCH[1]}" != "$version" ]; then
conflicts+=("$tag")
fi
done < <(git ls-remote --tags origin)
if [ "${#conflicts[@]}" -gt 0 ]; then
echo "::error title=Another version on the commit::${TAG} would land on ${TARGET:0:8}, which already carries the release tag of another version: ${conflicts[*]}. One commit releases one version: no tag and no release are cut. Merge a change to cut the next candidate on a commit of its own."
exit 1
fi
echo "${TARGET:0:8} carries no other version's release tag: ${TAG} is its only version"
# A stable release can carry rules only the repository knows (a fork
# line's pins, its release ledger). Checked in the tag's own pipeline
# they come too late: the tag and the GitHub release exist by then, and
# a refusal leaves a release that looks published with nothing built.
# The repository-owned `.github/release-gate.custom.sh`, when the
# released commit carries it (the promoted candidate, or the push's head
# for a patch), runs here on its checkout with the version about to be
# tagged; a non-zero exit cuts no tag and no release. A repository
# without the script has no gate.
- name: Run the repository's stable gate
id: gate
if: steps.decide.outputs.prerelease == 'false' && steps.decide.outputs.tag != ''
env:
TAG: ${{ steps.decide.outputs.tag }}
run: |
set -euo pipefail
gate=.github/release-gate.custom.sh
if [ ! -f "$gate" ]; then
echo "no ${gate} on the released commit: no repository gate for ${TAG}"
exit 0
fi
if ! bash "$gate" "$TAG"; then
echo "::error title=Stable gate refused::${gate} refused ${TAG}: no tag and no release are cut. Fix the cause on the branch and release it again."
exit 1
fi
echo "${gate} passed ${TAG}"
# cliff-context.json names the stable target git-cliff bumped to, and
# the tag actually cut is ${NEXT}-rc.N for a candidate. cliff.toml puts
# `{{ version }}` in the "Full Changelog" compare link, so the context has
# to carry the chosen tag before the render or the link points at a tag
# that does not exist. The render reads the cached context, so the one
# expensive git-cliff call above stays the only one.
- name: Render release notes
id: notes
if: steps.decide.outputs.tag != ''
env:
TAG: ${{ steps.decide.outputs.tag }}
run: |
set -euo pipefail
# `error` rather than a silent `[{version: $tag}]`: jq builds that
# object out of an empty context, and the render would then produce
# empty notes for a tag that is about to be created.
jq --arg tag "$TAG" \
'if (.[0].version // "") == "" then error("cliff-context.json carries no version") else .[0].version = $tag end' \
cliff-context.json > cliff-context.tagged.json
# Cheap render from the cached context -- no API calls, no git walk.
# `--strip all` drops header/footer; body-only is what gh release
# create --notes-file expects.
git-cliff --from-context cliff-context.tagged.json --strip all --output release-notes.md
# Mint just before publishing, after the release guards have passed.
# With owner/repositories unset, the token is scoped to this repository.
# A stable promotion tags the candidate's commit, which can be behind
# .github/workflows changes on the branch (an align-files commit). GitHub
# refuses an App that tag without `workflows`. Other runs tag the branch
# head; for them the empty input is left out of the token.
- name: Generate the giantswarm-release token
id: release-token
if: steps.decide.outputs.tag != ''
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ secrets.RELEASE_BOT_CLIENT_ID }}
private-key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }}
permission-contents: write
permission-workflows: ${{ inputs.release-type == 'stable' && 'write' || '' }}
# Create the tag AND the GitHub Release in one atomic API call. GitHub's
# release-create endpoint accepts a tag_name + target_commitish and, if
# the tag doesn't already exist, creates it pointing at that commitish
# as part of the same operation. Either both exist or neither does --
# no risk of a tag-without-release "stuck" state, no race window with
# CircleCI's `upload-release-assets` job that starts polling the
# release the instant it sees the tag.
#
# Trade-off: the tag created this way is **lightweight** (just a ref),
# not annotated. For our use -- git describe, architect's tag filter,
# gitsemver, gh release view -- both behave identically. Nothing in the
# giantswarm stack distinguishes them.
- name: Create release (and the tag, atomically)
id: release
if: steps.decide.outputs.tag != ''
env:
GH_TOKEN: ${{ steps.release-token.outputs.token }}
GH_REPO: ${{ github.repository }}
TAG: ${{ steps.decide.outputs.tag }}
PRERELEASE: ${{ steps.decide.outputs.prerelease }}
TARGET: ${{ steps.decide.outputs.target }}
run: |
set -euo pipefail
# A release candidate is flagged as a GitHub pre-release so it does
# not surface as the repository's "Latest release".
flags=()
if [ "$PRERELEASE" = "true" ]; then
flags+=(--prerelease)
fi
# GitHub marks a stable release as "Latest" by default. A release of
# a maintenance branch (release-v3.x) is an older line's: it must not
# take the marker from the release branch's newest stable, which
# `gh release view`, releases/latest and install scripts resolve to.
if [ "$GITHUB_REF_NAME" != 'main' ]; then
flags+=(--latest=false)
fi
gh release create "$TAG" \
--title "$TAG" \
--notes-file release-notes.md \
--target "$TARGET" \
${flags[@]+"${flags[@]}"}
# The stable tag is on the promoted candidate, not the branch head.
# A push already handled before that tag used the previous stable as
# its baseline, so its candidate may now be older than the new stable.
# Re-run auto against the branch with the new baseline without waiting
# for another push. Fetch the branch again: it may have advanced during
# promotion. Queue this before the CircleCI check, whose failure must
# not strand commits after an already published stable release.
- name: Queue releases for commits after the promoted candidate
id: catch-up
if: inputs.release-type == 'stable' && steps.release.outcome == 'success'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
TARGET: ${{ steps.decide.outputs.target }}
STABLE: ${{ steps.decide.outputs.tag }}
run: |
set -euo pipefail
git fetch --no-tags origin "refs/heads/${GITHUB_REF_NAME}"
head=$(git rev-parse 'FETCH_HEAD^{commit}')
if ! git merge-base --is-ancestor "$TARGET" "$head"; then
echo "::error::${GITHUB_REF_NAME} no longer contains the promoted commit ${TARGET}; inspect the branch before releasing it."
exit 1
fi
if [ "$head" = "$TARGET" ]; then
echo "${GITHUB_REF_NAME} has no commits after the promoted candidate; nothing to queue."
exit 0
fi
# A superseded RC on the head cannot acquire another version's
# tag. Land a preparation PR through the normal checks instead:
# its merge supplies the new commit and triggers auto-release.
# Read remote tags, including peeled annotated tags, as the guard
# does; the checkout can predate the branch's latest candidate.
rc='^v[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+$'
tags=$(git ls-remote --tags origin)
while read -r sha ref; do
tag=${ref#refs/tags/}
tag=${tag%'^{}'}
if [ "$sha" = "$head" ] && [[ "$tag" =~ $rc ]] && [ "${tag%-rc.*}" = "$STABLE" ]; then
echo "${tag} already tags ${head:0:8}; preparing a checked catch-up PR."
echo "prepare=true" >> "$GITHUB_OUTPUT"
echo "head=$head" >> "$GITHUB_OUTPUT"
exit 0
fi
done <<<"$tags"
echo "Queuing auto-release for commits on ${GITHUB_REF_NAME} after the promoted candidate:"
git log --format='%h %s' "${TARGET}..${head}"
gh workflow run zz_generated.auto_release.yaml --ref "$GITHUB_REF_NAME" -f release-type=auto
# The release App bypasses the review rule for its generated PRs,
# never the required checks. Its push/merge triggers CI, unlike a
# GITHUB_TOKEN push. No write to the protected branch happens here.
- name: Generate the release token for catch-up
id: catch-up-token
if: steps.catch-up.outputs.prepare == 'true'
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ secrets.RELEASE_BOT_CLIENT_ID }}
private-key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
permission-workflows: write
- name: Check out the catch-up head
if: steps.catch-up.outputs.prepare == 'true'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ steps.catch-up.outputs.head }}
fetch-depth: 0
token: ${{ steps.catch-up-token.outputs.token }}
# Keep the promoted checkout for its CircleCI verification below.
path: .release-catch-up-worktree
- name: Prepare a new commit for catch-up through a checked PR
id: catch-up-pr
if: steps.catch-up.outputs.prepare == 'true'
working-directory: .release-catch-up-worktree
env:
GH_TOKEN: ${{ steps.catch-up-token.outputs.token }}
GH_REPO: ${{ github.repository }}
STABLE: ${{ steps.decide.outputs.tag }}
CATCH_UP_HEAD: ${{ steps.catch-up.outputs.head }}
GIT_AUTHOR_NAME: giantswarm-release[bot]
GIT_AUTHOR_EMAIL: giantswarm-release[bot]@users.noreply.github.com
GIT_COMMITTER_NAME: giantswarm-release[bot]
GIT_COMMITTER_EMAIL: giantswarm-release[bot]@users.noreply.github.com
run: |
set -euo pipefail
branch="release/catch-up-${STABLE}-${CATCH_UP_HEAD:0:12}"
# A rerun reuses the same PR, including one already merged. Never
# rewrite its head or cut a second preparation commit for it.
pr=$(gh pr list --head "$branch" --base "$GITHUB_REF_NAME" --state all --json url --jq '.[0].url // empty')
if [ -z "$pr" ]; then
# The branch push can succeed before PR creation fails. Reuse
# that branch on a retry, without a force push.
remote=$(git ls-remote --heads origin "refs/heads/${branch}")
if [ -z "$remote" ]; then
git checkout -q --detach "$CATCH_UP_HEAD"
mkdir -p .github
printf 'stable=%s\nhead=%s\n' "$STABLE" "$CATCH_UP_HEAD" > .github/release-catch-up
git add .github/release-catch-up
git commit -m "docs(release): resume releases after ${STABLE}"
git push origin "HEAD:refs/heads/${branch}"
fi
pr=$(gh pr create --head "$branch" --base "$GITHUB_REF_NAME" \
--title "docs(release): resume releases after ${STABLE}" \
--body "Promotion of ${STABLE} left a superseded candidate on the branch head. This marker gives catch-up its own commit, preserving one version per commit. Merge after required checks; the merge triggers auto-release for the remaining changes.")
fi
state=$(gh pr view "$pr" --json state --jq .state)
if [ "$state" = MERGED ]; then
echo "Catch-up PR already merged: ${pr}"
elif [ "$state" = OPEN ]; then
gh pr merge "$pr" --auto --squash
echo "Catch-up waits for the required checks: ${pr}"
else
echo "::error::Catch-up PR was closed without merging: ${pr}; reopen it to resume releases."
exit 1
fi
echo "Catch-up PR: ${pr}" >> "$GITHUB_STEP_SUMMARY"
# A tag that never reaches CircleCI is a silent failure: the GitHub
# Release above exists and looks finished, but nothing gets built or
# published. GitHub delivers the tag-push webhook exactly once and never
# retries it; on 2026-09-04 ~22:00 UTC CircleCI's receiver answered
# three of ~55 tag pushes with an empty HTTP 400 and those releases had
# no pipeline until somebody noticed. So watch for the tag's build: a
# CircleCI commit status on the tag's commit from a workflow that
# started after the release. The commit's statuses are the commit's,
# not the tag's: the branch build of the same commit posts the same
# contexts, and keeps posting when its jobs finish after the tag, but
# its workflows started before the release.
#
# This step reads GitHub with the workflow's own token and holds no
# CircleCI credential, so it detects and never triggers: CircleCI has
# no service accounts, and a pipeline started through its API is a
# person's. The fix is a person's `devctl repo follow-circleci`, which
# runs an unbuilt latest release on the GitHub App pipeline (and sets
# that pipeline up when it is missing). A commit without any CircleCI
# status has no pipeline building the repository yet -- a new
# repository before its creator's set-up -- and is a warning.
- name: Verify CircleCI picked up the tag
if: steps.decide.outputs.tag != '' && hashFiles('.circleci/config.yml') != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.decide.outputs.tag }}
TARGET: ${{ steps.decide.outputs.target }}
# A healthy CircleCI posts the first status 1-10 s after the tag push.
CIRCLECI_STATUS_WAIT_SECONDS: "120"
run: |
set -euo pipefail
fix="devctl repo follow-circleci ${GITHUB_REPOSITORY}"
# counts: "<CircleCI statuses on the commit> <of them the GitHub App
# pipeline's> <tag pipelines started since the release>". Only the
# App pipeline's statuses (circleci-app[bot]) are judged: they link
# their workflow (…/workflow/<id>/job/<id>), while an OAuth
# follow's link a job alone, which tells a branch job from the
# tag's no better than its time. A generated (dynamic) pipeline
# starts with one setup workflow, so its setup workflows started
# since the release are the tag's; the branch build's continuation,
# started after its own setup, never counts. A commit without any
# setup status (a static configuration) counts every App workflow
# started since the release.
counts() {
gh api --paginate "repos/${GITHUB_REPOSITORY}/commits/${TARGET}/statuses?per_page=100" \
--jq '[.[] | select(.context | startswith("ci/circleci"))]' |
jq -rs --argjson since "$since" '
add // [] |
def wf: (.target_url // "") as $u | (($u | capture("/workflows?/(?<id>[^/]+)")? | .id) // $u);
(length) as $all |
(map(select((.creator.login // "") != "" and .creator.login != "circleci-app[bot]" and (.created_at | fromdateiso8601) >= $since)) | length) as $oauth |
map(select(.creator.login == "circleci-app[bot]")) |
(length) as $app |
(if any(.[]; .context == "ci/circleci: setup") then map(select(.context == "ci/circleci: setup")) else . end) as $starts |
($starts | group_by(wf) | map(min_by(.created_at)) | map(select((.created_at | fromdateiso8601) >= $since)) | length) as $tag |
"\($all) \($app) \($tag) \($oauth)"'
}
deadline=$((SECONDS + CIRCLECI_STATUS_WAIT_SECONDS))
since="" all="" app="" tag="" oauth=""
while :; do
# A failed read (rate limit, a 502) is retried within the wait;
# only a wait without one good read fails the step.
if [ -z "$since" ] && published=$(gh release view "$TAG" --json publishedAt --jq .publishedAt); then
since=$(jq -rn --arg at "$published" '($at | fromdateiso8601) - 10')
fi
if [ -n "$since" ] && out=$(counts); then
read -r all app tag oauth <<<"$out"
if [ "$tag" -gt 0 ]; then
echo "CircleCI builds ${TAG}: ${tag} pipeline(s) on ${TARGET:0:8} started after the release"
exit 0
fi
# An OAuth follow's statuses after the release settle nothing
# by waiting when the App pipeline builds nothing here. Where it
# builds too (an OAuth trigger left in place), its tag build may
# be seconds behind the OAuth one: keep waiting for it.
[ "$oauth" -eq 0 ] || [ "$app" -gt 0 ] || break
echo "no CircleCI status of ${TAG}'s build yet"
else
echo "reading the release or the commit statuses of ${TARGET:0:8} failed"
fi
[ "$SECONDS" -lt "$deadline" ] || break
echo "retrying in 10 s"
sleep 10
done
if [ -z "$all" ]; then
echo "::error::could not read the release or the commit statuses of ${TARGET:0:8} within ${CIRCLECI_STATUS_WAIT_SECONDS} s; cannot tell whether CircleCI built ${TAG}." \
"Check https://app.circleci.com/pipelines/github/${GITHUB_REPOSITORY} and, if the tag is missing: ${fix}"
exit 1
fi
if [ "$all" -eq 0 ]; then
echo "::warning::${TAG} is released and no CircleCI pipeline builds this repository yet: ${TARGET:0:8} carries no CircleCI status at all." \
"Set the GitHub App pipeline up as you, which also runs ${TAG}: ${fix}"
exit 0
fi
if [ "$app" -eq 0 ] || [ "$oauth" -gt 0 ]; then
echo "::warning::${TAG}: an OAuth follow builds ${TARGET:0:8} without the GitHub App pipeline's build of the tag, and its statuses cannot tell the tag's build from a branch build; not verified." \
"Move the repository to the GitHub App pipeline as you: ${fix} --migrate"
exit 0
fi
echo "::error::CircleCI never built ${TAG}: no CircleCI status on ${TARGET:0:8} from a workflow started in the ${CIRCLECI_STATUS_WAIT_SECONDS} s after the release" \
"(GitHub delivers the webhook once and never retries). Run it as you: ${fix}"
exit 1