From e99a15dbee1264f7159371c0376cd3b60ec2694e 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 --- .github/workflows/pull-requests-release.yaml | 40 +++++++++----- docs/release/tag-immutability.md | 2 +- hack/promote-packages-contract.bats | 55 ++++++++++++++++++++ 3 files changed, 82 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pull-requests-release.yaml b/.github/workflows/pull-requests-release.yaml index 2b576004d..ceb368161 100644 --- a/.github/workflows/pull-requests-release.yaml +++ b/.github/workflows/pull-requests-release.yaml @@ -462,20 +462,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/tag-immutability.md b/docs/release/tag-immutability.md index fe7418279..cfa8c9a26 100644 --- a/docs/release/tag-immutability.md +++ b/docs/release/tag-immutability.md @@ -4,7 +4,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) | Verifies the pinned packages candidate before creating a stable name. 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 verified packages artifact and rc container digests to the stable image tag (also write-once at the image level). | +| [`pull-requests-release.yaml`](../../.github/workflows/pull-requests-release.yaml) | Verifies the pinned packages candidate before creating a stable name. 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 verified packages artifact and rc container 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 stable tags. Before staging, verifies green full E2E from the latest rc tag-push run or a tag-correlated manual published-tag run (unless loudly bypassed). Commits and publishes the rewritten packages tree under a run-specific temporary `promotion-*` tag, adds a second commit pinning its digest on the `release-X.Y.Z` branch, generates the changelog there, and opens the promote PR with `release` but no automatic `full-e2e`; the PR gate verifies the candidate and finalize repeats that verification before the stable tag and image retag. The staging branch is force-pushed on re-dispatch, but an existing `docs/changelogs/vX.Y.Z.md` is preserved across the rebuild. | diff --git a/hack/promote-packages-contract.bats b/hack/promote-packages-contract.bats index 892cf1716..f8ccc734d 100644 --- a/hack/promote-packages-contract.bats +++ b/hack/promote-packages-contract.bats @@ -189,6 +189,61 @@ step_line() { printf '%s\n' "$chart_run" | code_lines | grep -A3 -F 'if [ "${MAKE_LATEST}" = "true" ]; then' | grep -qF 'cozy-installer:latest' } +# 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. The step runs +# here as the workflow carries it, against stub skopeo, helm and yq. +@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 [] + run_chart_step() { + (cd "$tmp/tree" && PATH="$tmp/bin:$PATH" TMP_DIR="$tmp" CALLS="$tmp/$1" TAG=v1.2.3 REGISTRY=ghcr.io/example \ + MAKE_LATEST="$2" CHART_EXISTS="$3" PUSH_FAILS="${4:-}" bash -e "$tmp/step.sh") + } + + run_chart_step first true '' + grep -qx 'helm push .*/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 rerun true 1 + 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 older false '' + 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 + + if run_chart_step failing true '' 1; then echo "FAIL: a failed helm push did not fail the step"; false; fi + + # A lookup that fails for another reason says nothing about the tag. + if run_chart_step lookup-error true error; then echo "FAIL: a failed lookup did not fail the step"; false; fi + if grep -q '^helm ' "$tmp/lookup-error"; then echo "FAIL: a failed lookup packaged or pushed the chart"; false; fi + rm -rf "$tmp" +} + @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")"