[Backport release-1.7] fix(ci): push the stable chart once, so a re-run keeps cozy-installer:X.Y.Z (#5487)

## What this PR does

Port of #5486 to release-1.7, finalize runs from base branch copy of the
workflow. Cherry-picked with `-x`, docs edit goes to `docs/release.md`.

### Downstream repositories

- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

### Release note

```release-note
fix(ci): a re-run of finalize no longer pushes the stable cozy-installer chart again
```
This commit is contained in:
Aleksei Sviridkin authored and GitHub committed 2026-11-27 17:57:15 +03:00
commit c44bded72d
3 files changed
+82 -15

No files matched your search

+26 -14
View File
@@ -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.
+1 -1
View File
@@ -637,7 +637,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/<vTAG>` 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/<vTAG>` 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. |
+55
View File
@@ -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 <case> <MAKE_LATEST> <CHART_EXISTS> [<PUSH_FAILS>]
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")"