mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
fix(ci): publish the release only after the stable images and chart exist
Finalize undrafted the release before it retagged the images and
published the cozy-installer chart, so for the length of the retag the
release page announced a version whose images and chart returned
manifest unknown. The retag took 80-95 seconds on the 1.6.x patches and
several minutes on v1.7.0. A failure in either step also left a public
release that a re-run could not repair, because the re-run looked for a
draft and found none.
Move the draft lookup and the latest decision into their own step that
runs before any registry write, hand the decision to the retag, the
chart and the release page as step outputs, and undraft last. A missing
draft now fails while no stable name exists, and a failed retag leaves
the draft in place for a re-run. The comments and docs that took the
release to be public by the time finalize pushes the stable tag now say
when it is published.
Deciding latest before the retag opens minutes in which two release PRs
merged close together would both decide they are the newest, leaving
latest on the older line on the page, the image aliases and the chart.
Finalize therefore runs one release at a time, in a concurrency group
that only release PRs join and that queues every merged release rather
than cancelling the one waiting.
The finalize bats suites run both github-script steps under node against
a stubbed API: a missing draft, an orphaned draft, an older patch after
a newer minor, and every shipped changelog's tag. A contract test fails
on a registry step allowed to fail, a publish step that runs after a
failure, a `latest` that moves without the decision, or finalize runs
that may overlap.
Assisted-by: LLM
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
(cherry picked from commit e1472e58de)
This commit is contained in:
7 files changed
+325
-97
No files matched your search
@@ -120,6 +120,75 @@ step_line() {
|
||||
printf '%s\n' "$setup" | code_lines | grep -qF 'uses: fluxcd/flux2/action@'
|
||||
}
|
||||
|
||||
# The release page announces the version, so it must not go public before the
|
||||
# stable images and chart it points at exist. A step that fails after the draft
|
||||
# is undrafted also cannot be re-run: the draft lookup in resolve no longer finds
|
||||
# anything to publish.
|
||||
@test "finalize publishes the release page only after the stable images and chart exist" {
|
||||
resolve="$(step_line 'Resolve draft release' "$FINALIZE")"
|
||||
retag="$(step_line 'Retag rc images to stable' "$FINALIZE")"
|
||||
chart="$(step_line 'Publish stable cozy-installer chart' "$FINALIZE")"
|
||||
publish="$(step_line 'Publish draft release' "$FINALIZE")"
|
||||
[ -n "$resolve" ] && [ -n "$retag" ] && [ -n "$chart" ] && [ -n "$publish" ]
|
||||
[ "$resolve" -lt "$retag" ]
|
||||
[ "$retag" -lt "$chart" ]
|
||||
[ "$chart" -lt "$publish" ]
|
||||
|
||||
# One latest decision, made before the first registry write; the registry
|
||||
# steps and the release page read it instead of recomputing it.
|
||||
for step in 'Retag rc images to stable' 'Publish stable cozy-installer chart' 'Publish draft release'; do
|
||||
step_block "$step" "$FINALIZE" | code_lines | grep -qF 'steps.resolve.outputs.make_latest'
|
||||
done
|
||||
}
|
||||
|
||||
# Finalize decides `latest` minutes before it moves it, so two release PRs
|
||||
# merged close together must not finalize at once. The group is built from the
|
||||
# job's own condition: a PR that skips finalize must not take the shared
|
||||
# group's one pending slot from a release waiting in it.
|
||||
@test "finalize runs one release at a time, and only release PRs share the queue" {
|
||||
[ "$(yq '.jobs.finalize.concurrency.cancel-in-progress' "$FINALIZE")" = false ]
|
||||
# One pending job per group is GitHub's default: a third release merged while
|
||||
# two are in line would cancel the one waiting.
|
||||
[ "$(yq '.jobs.finalize.concurrency.queue' "$FINALIZE")" = max ]
|
||||
cond="$(yq '.jobs.finalize.if' "$FINALIZE" | tr '\n' ' ' | sed 's/[[:space:]][[:space:]]*/ /g; s/^ //; s/ $//')"
|
||||
[ -n "$cond" ]
|
||||
want="\${{ ($cond) && 'release-finalize' || format('release-finalize-skipped-{0}', github.event.pull_request.number) }}"
|
||||
[ "$(yq '.jobs.finalize.concurrency.group' "$FINALIZE")" = "$want" ]
|
||||
}
|
||||
|
||||
# Order alone does not hold the page back. A registry step allowed to fail
|
||||
# without failing the job, or a publish step that runs whatever happened before
|
||||
# it, publishes over a missing image or chart all the same. And a patch on an
|
||||
# older line must move no `latest`: the image and chart aliases follow the one
|
||||
# decision, not a default.
|
||||
@test "finalize publishes nothing after a failed registry step, and latest moves only on the resolved decision" {
|
||||
for step in 'Resolve draft release' 'Retag rc images to stable' 'Publish stable cozy-installer chart' 'Publish draft release'; do
|
||||
STEP="$step" yq --exit-status '.jobs.finalize.steps[] | select(.name == strenv(STEP)) | has("continue-on-error") | not' "$FINALIZE" >/dev/null
|
||||
done
|
||||
# No condition at all on the publish step, so it runs only when every step
|
||||
# before it succeeded; and no registry command whose failure is swallowed.
|
||||
yq --exit-status '.jobs.finalize.steps[] | select(.name == "Publish draft release") | has("if") | not' "$FINALIZE" >/dev/null
|
||||
[ "$(yq '.jobs.finalize.steps[] | select(.name == "Retag rc images to stable") | .run' "$FINALIZE")" = './hack/promote-retag.sh "${STABLE_TAG}"' ]
|
||||
chart_code="$(yq '.jobs.finalize.steps[] | select(.name == "Publish stable cozy-installer chart") | .run' "$FINALIZE" | code_lines)"
|
||||
[ "$(printf '%s\n' "$chart_code" | head -n 1)" = 'set -eu' ]
|
||||
if printf '%s\n' "$chart_code" | grep -qF '||'; then
|
||||
echo "Publish stable cozy-installer chart swallows a failure with ||" >&2; false
|
||||
fi
|
||||
|
||||
# A registry step skipped for a stable tag publishes over a missing artifact
|
||||
# just as a failed one would; only a prerelease skips them.
|
||||
for step in 'Retag rc images to stable' 'Publish stable cozy-installer chart'; do
|
||||
[ "$(STEP="$step" yq '.jobs.finalize.steps[] | select(.name == strenv(STEP)) | .if' "$FINALIZE")" = "\${{ !contains(steps.get_tag.outputs.tag, '-') }}" ]
|
||||
done
|
||||
|
||||
move_latest="$(yq '.jobs.finalize.steps[] | select(.name == "Retag rc images to stable") | .env.MOVE_LATEST' "$FINALIZE")"
|
||||
[ "$move_latest" = "\${{ steps.resolve.outputs.make_latest == 'true' && '1' || '0' }}" ]
|
||||
|
||||
chart_run="$(yq '.jobs.finalize.steps[] | select(.name == "Publish stable cozy-installer chart") | .run' "$FINALIZE")"
|
||||
[ "$(printf '%s\n' "$chart_run" | code_lines | grep -cF 'cozy-installer:latest')" -eq 1 ]
|
||||
printf '%s\n' "$chart_run" | code_lines | grep -A3 -F 'if [ "${MAKE_LATEST}" = "true" ]; then' | grep -qF 'cozy-installer:latest'
|
||||
}
|
||||
|
||||
@test "promote rejects an old target base before publishing a candidate" {
|
||||
validate="$(step_block 'Validate rc is promotable' "$PROMOTE")"
|
||||
prepare_line="$(step_line 'Prepare stable branch' "$PROMOTE")"
|
||||
|
||||
@@ -189,6 +189,31 @@ JS
|
||||
[ -s "$6/calls" ] || { echo "step '$3' recorded nothing" >&2; return 1; }
|
||||
}
|
||||
|
||||
# finalize decides in Resolve draft release and publishes in Publish draft
|
||||
# release, which gets the decision as step outputs wired to env in the workflow.
|
||||
# Runs both and reads that wiring from the workflow itself, so a renamed output
|
||||
# or env key fails here instead of publishing with an empty release id. The
|
||||
# publish step's calls and log land in <out>, the resolve step's in <out>.resolve.
|
||||
#
|
||||
# run_publish <tree> <releases.json> <out> <tag>
|
||||
run_publish() {
|
||||
run_step "$FINALIZE" finalize 'Resolve draft release' "$1" "$2" "$3.resolve" "$4" || return 1
|
||||
[ "$(tail -n 1 "$3.resolve/calls")" = ok ] || {
|
||||
echo "Resolve draft release did not finish:" >&2
|
||||
sed 's/^/ /' "$3.resolve/calls" "$3.resolve/log" >&2; return 1; }
|
||||
wiring="$(yq '.jobs.finalize.steps[] | select(.name == "Publish draft release") | .env | to_entries | .[] | .key + " " + .value' "$FINALIZE")"
|
||||
[ -n "$wiring" ] || { echo "Publish draft release is wired to no env" >&2; return 1; }
|
||||
exports=""
|
||||
while read -r key expr; do
|
||||
name="$(printf '%s' "$expr" | sed -n 's/^\${{ steps\.resolve\.outputs\.\([a-z_]*\) }}$/\1/p')"
|
||||
[ -n "$name" ] || { echo "$key is not wired to a Resolve draft release output: $expr" >&2; return 1; }
|
||||
exports="$exports export $key='$(sed -n "s/^setOutput $name=//p" "$3.resolve/calls")';"
|
||||
done <<EOF
|
||||
$wiring
|
||||
EOF
|
||||
( eval "$exports"; run_step "$FINALIZE" finalize 'Publish draft release' "$1" "$2" "$3" "$4" )
|
||||
}
|
||||
|
||||
# The body finalize publishes for v1.7.0 in place of one over 100000 bytes.
|
||||
LINK_V170='The release notes for v1.7.0 are too long for a GitHub release description; the full changelog is [docs/changelogs/v1.7.0.md](https://github.com/cozystack/cozystack/blob/v1.7.0/docs/changelogs/v1.7.0.md).'
|
||||
|
||||
@@ -530,8 +555,8 @@ v1.6.0=reject:format"
|
||||
return 0
|
||||
}
|
||||
|
||||
# finalize's Publish draft release step, run as the workflow carries it, one
|
||||
# merge-commit tree per case. Whatever the tree holds, the release is
|
||||
# finalize's Resolve and Publish draft release steps, run as the workflow carries
|
||||
# them, one merge-commit tree per case. Whatever the tree holds, the release is
|
||||
# published: with the release notes, else the changelog, else the draft's own
|
||||
# body, and with a link in place of anything over 100000 bytes, since the tags
|
||||
# already exist and a body GitHub refuses would strand the release.
|
||||
@@ -562,10 +587,10 @@ EOF
|
||||
|
||||
for spec in notes:$notes blanknotes:$cl changelog:$cl at:$cl over:link multibyte:link overnotes:link neither:none blank:none; do
|
||||
c="${spec%%:*}"; want="${spec#*:}"
|
||||
run_step "$FINALIZE" finalize 'Publish draft release' "$tmp/$c" "$tmp/releases.json" "$tmp/out.$c" v1.7.0
|
||||
run_publish "$tmp/$c" "$tmp/releases.json" "$tmp/out.$c" v1.7.0
|
||||
with_body=' body'
|
||||
[ "$want" != none ] || with_body=''
|
||||
expected="$(printf 'ok\nsetOutput make_latest=true\nupdateRelease 1 draft=false make_latest=true prerelease=false%s\n' "$with_body")"
|
||||
expected="$(printf 'ok\nupdateRelease 1 draft=false make_latest=true prerelease=false%s\n' "$with_body")"
|
||||
[ "$(sort "$tmp/out.$c/calls")" = "$expected" ] || {
|
||||
echo "$c: finalize did something other than publishing v1.7.0:" >&2
|
||||
sed 's/^/ /' "$tmp/out.$c/calls" "$tmp/out.$c/log" >&2; exit 1; }
|
||||
@@ -590,6 +615,89 @@ EOF
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
# The draft lookup is the first thing finalize does after the tags exist, and it
|
||||
# runs before the retag, so a release with no draft stops the job while no stable
|
||||
# image name has been written.
|
||||
@test "finalize: a missing draft fails in Resolve draft release, before anything is published" {
|
||||
need_node
|
||||
tmp="$(mktemp -d)"
|
||||
printf '[{"id": 2, "draft": false, "prerelease": false, "tag_name": "v1.6.5", "name": "v1.6.5", "body": "v1.6.5"}]\n' > "$tmp/releases.json"
|
||||
mkdir -p "$tmp/tree"
|
||||
run_step "$FINALIZE" finalize 'Resolve draft release' "$tmp/tree" "$tmp/releases.json" "$tmp/out" v1.7.0
|
||||
grep -qF 'threw Draft release for v1.7.0 not found' "$tmp/out/calls" || {
|
||||
echo "a missing draft did not stop Resolve draft release:" >&2
|
||||
sed 's/^/ /' "$tmp/out/calls" "$tmp/out/log" >&2; exit 1; }
|
||||
if grep -q '^updateRelease' "$tmp/out/calls"; then
|
||||
echo "Resolve draft release wrote to a release it could not resolve" >&2; exit 1
|
||||
fi
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
# An older patch cut after a newer minor must not take `latest`: it is published
|
||||
# without it, and the newest release is asserted as latest again.
|
||||
@test "finalize: an older patch is published without latest and the newest release keeps it" {
|
||||
need_node
|
||||
tmp="$(mktemp -d)"
|
||||
cat > "$tmp/releases.json" <<'EOF'
|
||||
[
|
||||
{"id": 5, "draft": true, "prerelease": false, "tag_name": "v1.6.6", "name": "v1.6.6", "body": "draft"},
|
||||
{"id": 3, "draft": false, "prerelease": false, "tag_name": "v1.7.0", "name": "v1.7.0", "body": "v1.7.0"},
|
||||
{"id": 2, "draft": false, "prerelease": false, "tag_name": "v1.6.5", "name": "v1.6.5", "body": "v1.6.5"}
|
||||
]
|
||||
EOF
|
||||
mkdir -p "$tmp/tree/docs/changelogs"
|
||||
write_changelog "$tmp/tree/docs/changelogs/v1.6.6.md" 1.6.6
|
||||
run_publish "$tmp/tree" "$tmp/releases.json" "$tmp/out" v1.6.6
|
||||
want="ok
|
||||
updateRelease 3 make_latest=true
|
||||
updateRelease 5 draft=false make_latest=false prerelease=false body"
|
||||
[ "$(sort "$tmp/out/calls")" = "$want" ] || {
|
||||
echo "an older patch did not leave latest with v1.7.0:" >&2
|
||||
sed 's/^/ /' "$tmp/out/calls" "$tmp/out/log" >&2; exit 1; }
|
||||
grep -qx 'setOutput make_latest=false' "$tmp/out.resolve/calls" || {
|
||||
echo "Resolve draft release did not decide make_latest=false for an older patch" >&2; exit 1; }
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
# A tag deleted and pushed again orphans its draft: GitHub renames the draft's
|
||||
# tag_name to untagged-<hash> and keeps its name. Resolve repairs the tag before
|
||||
# any registry write, and Publish undrafts the release Resolve settled on, not
|
||||
# one it looks up again. A draft that shares only the name, because it belongs
|
||||
# to another tag, is never taken over.
|
||||
@test "finalize: an orphaned draft is repaired in Resolve and published by its id, another tag's draft is not taken" {
|
||||
need_node
|
||||
tmp="$(mktemp -d)"
|
||||
cat > "$tmp/releases.json" <<'EOF'
|
||||
[
|
||||
{"id": 7, "draft": true, "prerelease": false, "tag_name": "untagged-0123456789abcdef", "name": "v1.7.0", "body": "draft"},
|
||||
{"id": 2, "draft": false, "prerelease": false, "tag_name": "v1.6.5", "name": "v1.6.5", "body": "v1.6.5"}
|
||||
]
|
||||
EOF
|
||||
mkdir -p "$tmp/tree/docs/changelogs"
|
||||
write_changelog "$tmp/tree/docs/changelogs/v1.7.0.md" 1.7.0
|
||||
run_publish "$tmp/tree" "$tmp/releases.json" "$tmp/out" v1.7.0
|
||||
grep -qx 'updateRelease 7 tag_name=v1.7.0' "$tmp/out.resolve/calls" || {
|
||||
echo "Resolve draft release did not repair the orphaned draft's tag:" >&2
|
||||
sed 's/^/ /' "$tmp/out.resolve/calls" >&2; exit 1; }
|
||||
grep -qx 'setOutput draft_id=7' "$tmp/out.resolve/calls" || {
|
||||
echo "Resolve draft release did not hand the repaired draft to Publish draft release" >&2; exit 1; }
|
||||
want="ok
|
||||
updateRelease 7 draft=false make_latest=true prerelease=false body"
|
||||
[ "$(sort "$tmp/out/calls")" = "$want" ] || {
|
||||
echo "the repaired draft is not the release that was published:" >&2
|
||||
sed 's/^/ /' "$tmp/out/calls" "$tmp/out/log" >&2; exit 1; }
|
||||
|
||||
printf '[{"id": 8, "draft": true, "prerelease": true, "tag_name": "v1.7.0-rc.2", "name": "v1.7.0", "body": "draft"}]\n' > "$tmp/other.json"
|
||||
run_step "$FINALIZE" finalize 'Resolve draft release' "$tmp/tree" "$tmp/other.json" "$tmp/out.other" v1.7.0
|
||||
grep -qF 'threw Draft release for v1.7.0 not found' "$tmp/out.other/calls" || {
|
||||
echo "a draft of another tag was taken for v1.7.0:" >&2
|
||||
sed 's/^/ /' "$tmp/out.other/calls" >&2; exit 1; }
|
||||
if grep -q '^updateRelease' "$tmp/out.other/calls"; then
|
||||
echo "Resolve draft release edited the draft of another tag" >&2; exit 1
|
||||
fi
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
# A release with no release notes publishes exactly what finalize published
|
||||
# before they existed. Every shipped changelog is a fixture; one over 100000
|
||||
# bytes, which GitHub may refuse, publishes the link instead.
|
||||
@@ -604,7 +712,16 @@ EOF
|
||||
mkdir -p "$tmp/$tag/docs/changelogs"
|
||||
cp "$f" "$tmp/$tag/docs/changelogs/"
|
||||
printf '[{"id": 1, "draft": true, "prerelease": false, "tag_name": "%s", "name": "%s", "body": "draft"}]\n' "$tag" "$tag" > "$tmp/$tag.json"
|
||||
run_step "$FINALIZE" finalize 'Publish draft release' "$tmp/$tag" "$tmp/$tag.json" "$tmp/out.$tag" "$tag"
|
||||
run_publish "$tmp/$tag" "$tmp/$tag.json" "$tmp/out.$tag" "$tag"
|
||||
# The prerelease flag reaches Publish as an output of Resolve, so it is
|
||||
# asserted here, on every shipped tag, rather than assumed from the body.
|
||||
case "$tag" in
|
||||
*-*) flags='make_latest=false prerelease=true' ;;
|
||||
*) flags='make_latest=true prerelease=false' ;;
|
||||
esac
|
||||
grep -qxF "updateRelease 1 draft=false $flags body" "$tmp/out.$tag/calls" || {
|
||||
echo "$tag: published with the wrong flags, want $flags:" >&2
|
||||
sed 's/^/ /' "$tmp/out.$tag/calls" >&2; exit 1; }
|
||||
if [ "$(wc -c < "$f")" -le 100000 ]; then
|
||||
cmp -s "$tmp/out.$tag/body.1" "$f" || { echo "$tag: not published byte for byte" >&2; exit 1; }
|
||||
verbatim=$((verbatim + 1))
|
||||
|
||||
Reference in new issue
Block a user