From c14998e86f2f495c41711f2721b8ded1e2a7caac Mon Sep 17 00:00:00 2001 From: Myasnikov Daniil Date: Fri, 27 Nov 2026 12:46:42 +0000 Subject: [PATCH] fix(ci): push the stable chart once, so a re-run keeps cozy-installer:X.Y.Z Since finalize publishes the release page last, a run that fails in Publish draft release is re-run after the chart is already pushed. The re-run packaged and pushed the chart again, and helm package does not give the same bytes twice (two packagings of the same tree with different file times give two digests), so cozy-installer:X.Y.Z moved to another digest. The chart step now pushes only when the registry answers that cozy- installer:X.Y.Z is missing, read as manifest_digest in hack/promote- retag.sh reads it; any other lookup error fails the step instead of being taken for a missing tag. cozy-installer:latest still follows the latest decision on every run. A bats test runs the step against stub skopeo, helm and yq: the first run pushes once, a re-run pushes nothing, an older patch leaves latest alone, a failed push fails the step, and a failed lookup fails it without packaging or pushing. Fixes: e1472e58de90 ("fix(ci): publish the release only after the stable images and chart exist") Assisted-by: LLM Signed-off-by: Myasnikov Daniil (cherry picked from commit e99a15dbee1264f7159371c0376cd3b60ec2694e) --- .github/workflows/pull-requests-release.yaml | 40 ++++++++----- docs/release.md | 2 +- hack/promote-gate-contract.bats | 63 ++++++++++++++++++++ 3 files changed, 90 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pull-requests-release.yaml b/.github/workflows/pull-requests-release.yaml index c5a670cf1..ae5b37d75 100644 --- a/.github/workflows/pull-requests-release.yaml +++ b/.github/workflows/pull-requests-release.yaml @@ -475,20 +475,32 @@ jobs: run: | set -eu STABLE_VERSION="${TAG#v}" - # Bake the correct platform version into the chart's DEFAULT values so - # the primary `helm --install --version X.Y.Z` path reports the stable - # version in telemetry — the operator image itself still carries the rc - # version baked at build time, and this env override is what corrects - # it. Done on the working tree only (never committed): committing it - # would leak platformVersion=vX.Y.Z onto main/the release line when the - # promote PR merges, mis-stamping the next rc built from that branch. - export STABLE_VERSION - yq -i '.cozystackOperator.platformVersion = "v" + strenv(STABLE_VERSION)' \ - packages/core/installer/values.yaml - PKG="$(helm package packages/core/installer \ - --version "${STABLE_VERSION}" --app-version "${STABLE_VERSION}" | awk '{print $NF}')" - helm push "$PKG" "oci://${REGISTRY}" - rm -f "$PKG" + # helm package does not give the same bytes twice, so pushing again on + # a re-run of this job would move cozy-installer:X.Y.Z to another + # digest. The first push stays, and only a registry that says the tag + # is missing gets one: any other lookup error stops the step. Absence + # is read as manifest_digest in hack/promote-retag.sh reads it. + if lookup="$(skopeo inspect --raw "docker://${REGISTRY}/cozy-installer:${STABLE_VERSION}" 2>&1)"; then + echo "cozy-installer:${STABLE_VERSION} is already in the registry, keeping it." + elif ! printf '%s\n' "$lookup" | grep -qiE 'manifest unknown|manifest not known|manifest for [^ ]* not found|not found|404'; then + echo "::error::cannot tell whether cozy-installer:${STABLE_VERSION} is in the registry: $lookup" + exit 1 + else + # Bake the correct platform version into the chart's DEFAULT values so + # the primary `helm --install --version X.Y.Z` path reports the stable + # version in telemetry — the operator image itself still carries the rc + # version baked at build time, and this env override is what corrects + # it. Done on the working tree only (never committed): committing it + # would leak platformVersion=vX.Y.Z onto main/the release line when the + # promote PR merges, mis-stamping the next rc built from that branch. + export STABLE_VERSION + yq -i '.cozystackOperator.platformVersion = "v" + strenv(STABLE_VERSION)' \ + packages/core/installer/values.yaml + PKG="$(helm package packages/core/installer \ + --version "${STABLE_VERSION}" --app-version "${STABLE_VERSION}" | awk '{print $NF}')" + helm push "$PKG" "oci://${REGISTRY}" + rm -f "$PKG" + fi # cozy-installer:latest tracks the newest stable, matching the image # :latest and the release's `latest` flag — never moved by a patch on # an older line. diff --git a/docs/release.md b/docs/release.md index e23fb853e..95a9bb49c 100644 --- a/docs/release.md +++ b/docs/release.md @@ -549,7 +549,7 @@ Published tags are **write-once** — once a `vX.Y.Z` or rc tag is pushed it is | File | Tag / branch handling | |------|------------------------| -| [`pull-requests-release.yaml`](../.github/workflows/pull-requests-release.yaml) | Creates `vX.Y.Z` at the PR merge commit **write-once** (create if absent, no-op if unchanged, fail loudly if it would move — the merge commit is new, so there is nothing to move). Cuts the `api/apps/v1alpha1/` Go-submodule tag write-once at the same commit, **stable only** (never rc/beta/alpha). The `release-X.Y` maintenance branch is fast-forward-only. Retags the rc image digests to the stable image tag (also write-once at the image level). | +| [`pull-requests-release.yaml`](../.github/workflows/pull-requests-release.yaml) | Creates `vX.Y.Z` at the PR merge commit **write-once** (create if absent, no-op if unchanged, fail loudly if it would move — the merge commit is new, so there is nothing to move). Cuts the `api/apps/v1alpha1/` Go-submodule tag write-once at the same commit, **stable only** (never rc/beta/alpha). The `release-X.Y` maintenance branch is fast-forward-only. Retags the rc image digests to the stable image tag (also write-once at the image level). Pushes the stable `cozy-installer` chart once: `helm package` does not give the same bytes twice, so a re-run that finds `cozy-installer:X.Y.Z` in the registry keeps it rather than moving the tag to another digest; a chart that went out wrong is replaced by deleting `cozy-installer:X.Y.Z` in GHCR before the re-run. A lookup that fails for any other reason than a missing tag fails the step. | | [`tags.yaml`](../.github/workflows/tags.yaml) | The `release-X.Y.Z-rc.N` staging branch is a mutable staging ref (compare-before-force: skipped when unchanged, force+log only when it genuinely moves). Fails fast on a stable `vX.Y.Z` tag with no pre-existing draft — stable tags come from `promote-rc.yaml`, never a hand push. | | [`promote-rc.yaml`](../.github/workflows/promote-rc.yaml) | Mutates no tags. Stages the `release-X.Y.Z` branch and opens the promote PR; the stable tag and the image retag both happen at merge (finalize). | diff --git a/hack/promote-gate-contract.bats b/hack/promote-gate-contract.bats index 4a462009d..f1ea78102 100644 --- a/hack/promote-gate-contract.bats +++ b/hack/promote-gate-contract.bats @@ -299,6 +299,20 @@ step_line() { # merged close together must not finalize at once. The group is built from the # job's own condition, so a PR that skips finalize never joins it, and every # merged release waits its turn instead of the waiting one being cancelled. +# Runs finalize's chart step as the workflow carries it, in /tree, against +# the stub skopeo, helm and yq in /bin, and prints ok or failed: the +# runner's translator makes every function here return 0, so the outcome has to +# travel on stdout. +# run_chart_step [] +run_chart_step() { + if (cd "$1/tree" && PATH="$1/bin:$PATH" TMP_DIR="$1" CALLS="$1/$2" TAG=v1.2.3 REGISTRY=ghcr.io/example \ + MAKE_LATEST="$3" CHART_EXISTS="$4" PUSH_FAILS="${5:-}" bash -e "$1/step.sh" > "$1/$2.out" 2>&1); then + echo ok + else + echo failed + fi +} + @test "finalize runs one release at a time, and only release PRs share the queue" { [ "$(yq '.jobs.finalize.concurrency.cancel-in-progress' "$FINALIZE")" = false ] [ "$(yq '.jobs.finalize.concurrency.queue' "$FINALIZE")" = max ] @@ -307,6 +321,55 @@ step_line() { [ "$(yq '.jobs.finalize.concurrency.group' "$FINALIZE")" = "\${{ ($cond) && 'release-finalize' || format('release-finalize-skipped-{0}', github.event.pull_request.number) }}" ] } + +# helm package does not give the same bytes twice, so a re-run that pushed the +# chart again would move cozy-installer:X.Y.Z to another digest. +@test "finalize pushes the stable chart once, and a re-run keeps the first push" { + tmp="$(mktemp -d)" + mkdir -p "$tmp/bin" "$tmp/tree" + yq '.jobs.finalize.steps[] | select(.name == "Publish stable cozy-installer chart") | .run' "$FINALIZE" > "$tmp/step.sh" + cat > "$tmp/bin/helm" <<'EOF' +#!/bin/sh +echo "helm $*" >> "$CALLS" +case "$1" in + package) echo "Successfully packaged chart and saved it to: $TMP_DIR/cozy-installer.tgz" ;; + push) [ -z "${PUSH_FAILS:-}" ] || exit 1 ;; +esac +EOF + # CHART_EXISTS: 1 finds the tag, unset answers as GHCR does for a missing tag, + # and error answers with any other failure. + cat > "$tmp/bin/skopeo" <<'EOF' +#!/bin/sh +echo "skopeo $*" >> "$CALLS" +[ "$1" = inspect ] || exit 0 +case "${CHART_EXISTS:-}" in + 1) echo '{"schemaVersion":2}' ;; + error) echo 'toomanyrequests: retry-after: 60s' >&2; exit 1 ;; + *) echo 'reading manifest 1.2.3 in ghcr.io/example/cozy-installer: manifest unknown' >&2; exit 2 ;; +esac +EOF + printf '#!/bin/sh\necho "yq $*" >> "$CALLS"\n' > "$tmp/bin/yq" + chmod +x "$tmp/bin/helm" "$tmp/bin/skopeo" "$tmp/bin/yq" + + [ "$(run_chart_step "$tmp" first true '')" = ok ] + grep -qx "helm push $tmp/cozy-installer.tgz oci://ghcr.io/example" "$tmp/first" + grep -qF 'docker://ghcr.io/example/cozy-installer:1.2.3 docker://ghcr.io/example/cozy-installer:latest' "$tmp/first" + + [ "$(run_chart_step "$tmp" rerun true 1)" = ok ] + if grep -q '^helm ' "$tmp/rerun"; then echo "FAIL: a re-run packaged or pushed the chart again"; false; fi + grep -qF 'docker://ghcr.io/example/cozy-installer:1.2.3 docker://ghcr.io/example/cozy-installer:latest' "$tmp/rerun" + + [ "$(run_chart_step "$tmp" older false '')" = ok ] + grep -q '^helm push ' "$tmp/older" + if grep -qF 'cozy-installer:latest' "$tmp/older"; then echo "FAIL: an older patch moved cozy-installer:latest"; false; fi + + [ "$(run_chart_step "$tmp" failing true '' 1)" = failed ] + + # A lookup that fails for another reason says nothing about the tag. + [ "$(run_chart_step "$tmp" lookup-error true error)" = failed ] + if grep -q '^helm ' "$tmp/lookup-error"; then echo "FAIL: a failed lookup packaged or pushed the chart"; false; fi + rm -rf "$tmp" +} @test "finalize checkout does not persist credentials so the app-token tag push triggers tags.yaml" { block="$(job_block finalize "$FINALIZE")" [ -n "$block" ]