diff --git a/.github/workflows/pull-requests-release.yaml b/.github/workflows/pull-requests-release.yaml index 5e61bac42..c5a670cf1 100644 --- a/.github/workflows/pull-requests-release.yaml +++ b/.github/workflows/pull-requests-release.yaml @@ -45,6 +45,19 @@ jobs: contains(github.event.pull_request.labels.*.name, 'release') && github.event.pull_request.user.login == 'cozystack-ci[bot]' + # One finalize at a time across release PRs. Each decides `latest` from the + # releases already published, then moves it on the release page, the image + # :latest aliases and cozy-installer:latest minutes later, so two + # overlapping runs could both decide they are the newest and leave `latest` + # on the older line. The group repeats the `if:` above so a PR that skips + # finalize never joins it, and `queue: max` lets every merged release wait + # its turn: by default GitHub keeps one pending job per group and cancels + # the older one when a third arrives. + concurrency: + group: ${{ (github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release') && github.event.pull_request.user.login == 'cozystack-ci[bot]') && 'release-finalize' || format('release-finalize-skipped-{0}', github.event.pull_request.number) }} + cancel-in-progress: false + queue: max + env: # The registry promotion writes to: component images and the cozy-installer # chart. GHCR — the release registry tags.yaml builds rc images into — NOT @@ -314,9 +327,12 @@ jobs: } } - # Publish draft release and ensure correct latest flag - - name: Publish draft release - id: publish + # Pick the draft this run publishes and decide whether it becomes `latest`, + # before any registry write: a missing draft then fails the job while no + # stable image name exists yet, and the retag, the chart and the release + # page all act on this one decision. + - name: Resolve draft release + id: resolve uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7 with: github-token: ${{ steps.app-token.outputs.token }} @@ -399,10 +415,16 @@ jobs: const isOutdated = maxRelease && compareSemver(currentSemver, maxRelease.semver) < 0; const makeLatest = (isRc || isOutdated) ? 'false' : 'true'; - // The image retag step below reuses this exact decision to gate + // The retag and chart steps below reuse this exact decision to gate // whether :latest moves — the release's `latest` and the images' // :latest must agree (a patch on an old line moves neither). core.setOutput('make_latest', makeLatest); + core.setOutput('prerelease', String(isRc)); + core.setOutput('draft_id', String(draft.id)); + if (isOutdated && maxRelease) { + core.setOutput('restore_latest_id', String(maxRelease.id)); + core.setOutput('restore_latest_tag', maxRelease.tag); + } if (isRc) { console.log(`🏷️ ${tag} is a prerelease, make_latest: false`); @@ -412,6 +434,88 @@ jobs: console.log(`🏷️ ${tag} is the highest version, make_latest: true`); } + # ── Transactional promotion: the registry side effects run HERE, after the + # stable tag is cut and before the release is published, once the promote + # PR's e2e passed and the PR merged. promote-rc.yaml did none of this at + # dispatch time, so an abandoned promotion left no stable-named bytes. + # + # The checked-out merge commit is the promoted stable tree: the rc's + # digests with the tag string rewritten to stable. skopeo retags those + # digests to the stable image tag; helm packages+pushes the stable chart. + # + # The toolchain and the GHCR logins these two steps need are established + # earlier in this job, by "Set up promotion toolchain (flux, skopeo, yq, + # helm)" and "Login to registry (GHCR)" — both moved ahead of the tag + # creation so the candidate verification can refuse a release before any + # write-once name exists. Same job, so both are still in scope here. + + # Retag every rc image/digest to the stable tag. No rebuild — bit-for-bit + # the e2e-tested rc. :latest moves only when this stable is the newest + # published version, gated by the SAME make_latest decision the release got. + - name: Retag rc images to stable + if: ${{ !contains(steps.get_tag.outputs.tag, '-') }} + env: + STABLE_TAG: ${{ steps.get_tag.outputs.tag }} + MOVE_LATEST: ${{ steps.resolve.outputs.make_latest == 'true' && '1' || '0' }} + run: ./hack/promote-retag.sh "${STABLE_TAG}" + + # Publish the stable cozy-installer OCI chart — the documented install path + # (`helm upgrade --install cozystack oci://…/cozy-installer --version X.Y.Z`). + # The retag above covers component images + the cozystack-packages artifact, + # but the chart is a separate OCI artifact referenced in no values.yaml, so + # the stable install 404s (manifest unknown) unless it is published here. + # No rebuild: the chart is packaged from the merged stable tree, which pins + # the retagged images + artifact by digest; only the chart's version and + # its platformVersion default are stamped. + - name: Publish stable cozy-installer chart + if: ${{ !contains(steps.get_tag.outputs.tag, '-') }} + env: + TAG: ${{ steps.get_tag.outputs.tag }} + MAKE_LATEST: ${{ steps.resolve.outputs.make_latest }} + 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" + # 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. + if [ "${MAKE_LATEST}" = "true" ]; then + skopeo copy --multi-arch all \ + "docker://${REGISTRY}/cozy-installer:${STABLE_VERSION}" \ + "docker://${REGISTRY}/cozy-installer:latest" + fi + + # Last on purpose: the release page is what announces this version, so it + # goes public only once the stable images and chart it points at exist. A + # failed retag leaves the draft in place, where a re-run finds it again. + - name: Publish draft release + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7 + env: + PRERELEASE: ${{ steps.resolve.outputs.prerelease }} + MAKE_LATEST: ${{ steps.resolve.outputs.make_latest }} + DRAFT_ID: ${{ steps.resolve.outputs.draft_id }} + RESTORE_LATEST_ID: ${{ steps.resolve.outputs.restore_latest_id }} + RESTORE_LATEST_TAG: ${{ steps.resolve.outputs.restore_latest_tag }} + with: + github-token: ${{ steps.app-token.outputs.token }} + script: | + const tag = '${{ steps.get_tag.outputs.tag }}'; + const isRc = process.env.PRERELEASE === 'true'; + const makeLatest = process.env.MAKE_LATEST; + // Release body comes from the changelog that merged with THIS PR // (promote-rc.yaml commits it onto the release-X.Y.Z branch), read // from the merge commit already checked out here. @@ -449,7 +553,7 @@ jobs: await github.rest.repos.updateRelease({ owner: context.repo.owner, repo: context.repo.repo, - release_id: draft.id, + release_id: Number(process.env.DRAFT_ID), draft: false, prerelease: isRc, make_latest: makeLatest, @@ -458,77 +562,14 @@ jobs: console.log(`🚀 Published release ${tag}`); // If this is a backport/outdated release, ensure the correct release is marked as latest - if (isOutdated && maxRelease) { - console.log(`🔧 Ensuring ${maxRelease.tag} remains the latest release...`); + if (process.env.RESTORE_LATEST_ID) { + const restoreTag = process.env.RESTORE_LATEST_TAG; + console.log(`🔧 Ensuring ${restoreTag} remains the latest release...`); await github.rest.repos.updateRelease({ owner: context.repo.owner, repo: context.repo.repo, - release_id: maxRelease.id, + release_id: Number(process.env.RESTORE_LATEST_ID), make_latest: 'true' }); - console.log(`✅ Restored ${maxRelease.tag} as latest release`); + console.log(`✅ Restored ${restoreTag} as latest release`); } - - # ── Transactional promotion: the registry side effects run HERE, after the - # stable tag is cut and the release is published — i.e. after the promote - # PR's e2e passed and the PR merged. promote-rc.yaml did none of this at - # dispatch time, so an abandoned promotion left no stable-named bytes. - # - # The checked-out merge commit is the promoted stable tree: the rc's - # digests with the tag string rewritten to stable. skopeo retags those - # digests to the stable image tag; helm packages+pushes the stable chart. - # - # The toolchain and the GHCR logins these two steps need are established - # earlier in this job, by "Set up promotion toolchain (flux, skopeo, yq, - # helm)" and "Login to registry (GHCR)" — both moved ahead of the tag - # creation so the candidate verification can refuse a release before any - # write-once name exists. Same job, so both are still in scope here. - - # Retag every rc image/digest to the stable tag. No rebuild — bit-for-bit - # the e2e-tested rc. :latest moves only when this stable is the newest - # published version, gated by the SAME make_latest decision the release got. - - name: Retag rc images to stable - if: ${{ !contains(steps.get_tag.outputs.tag, '-') }} - env: - STABLE_TAG: ${{ steps.get_tag.outputs.tag }} - MOVE_LATEST: ${{ steps.publish.outputs.make_latest == 'true' && '1' || '0' }} - run: ./hack/promote-retag.sh "${STABLE_TAG}" - - # Publish the stable cozy-installer OCI chart — the documented install path - # (`helm upgrade --install cozystack oci://…/cozy-installer --version X.Y.Z`). - # The retag above covers component images + the cozystack-packages artifact, - # but the chart is a separate OCI artifact referenced in no values.yaml, so - # the stable install 404s (manifest unknown) unless it is published here. - # No rebuild: the chart is packaged from the merged stable tree, which pins - # the retagged images + artifact by digest; only the chart's version and - # its platformVersion default are stamped. - - name: Publish stable cozy-installer chart - if: ${{ !contains(steps.get_tag.outputs.tag, '-') }} - env: - TAG: ${{ steps.get_tag.outputs.tag }} - MAKE_LATEST: ${{ steps.publish.outputs.make_latest }} - 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" - # 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. - if [ "${MAKE_LATEST}" = "true" ]; then - skopeo copy --multi-arch all \ - "docker://${REGISTRY}/cozy-installer:${STABLE_VERSION}" \ - "docker://${REGISTRY}/cozy-installer:latest" - fi diff --git a/.github/workflows/tags.yaml b/.github/workflows/tags.yaml index 7f0d78e8c..0875800fa 100644 --- a/.github/workflows/tags.yaml +++ b/.github/workflows/tags.yaml @@ -419,9 +419,9 @@ jobs: # `at_tag` — is it present in THIS checkout (the tag commit)? Under the # promote flow it normally is, because the promote PR carried it onto # release-1.6 and the stable tag sits on that merge commit. So this is the - # usual state on arrival: `exists` false, `at_tag` true, a reviewed and - # already-published changelog sitting right here — port it rather than - # regenerate. + # usual state on arrival: `exists` false, `at_tag` true, the reviewed + # changelog finalize publishes as the release body sitting right here — port + # it rather than regenerate. # # Only when both are false is there genuinely no changelog to publish, and # only then does the AI run. @@ -443,8 +443,8 @@ jobs: # flow it normally is: promote-rc.yaml commits it onto release-X.Y.Z and # it reaches the tag via the merge commit. That PR targets the maintenance # line, so the file lands on release-1.6 and never reaches main — - # `exists` above is false even though a reviewed, already-PUBLISHED - # changelog exists right here. + # `exists` above is false even though the reviewed changelog finalize + # publishes as the body exists right here. # # Regenerating in that case would spend a second AI run and, once the # backstop PR merged, update-releasenotes.yaml would overwrite the @@ -491,7 +491,7 @@ jobs: CHANGELOG_BRANCH="changelog-v${VERSION}" # Two ways the file can be here: ported verbatim from the tag commit - # (at_tag=true — the reviewed, already-published changelog reaching main + # (at_tag=true — the reviewed changelog finalize publishes, reaching main # for the first time), or freshly generated above. Either is valid. if [ ! -f "$CHANGELOG_FILE" ]; then echo "::error::Changelog file $CHANGELOG_FILE is absent — it was neither present at the tag nor produced by the Generate changelog using AI step" diff --git a/docs/release.md b/docs/release.md index f24a6ff56..e23fb853e 100644 --- a/docs/release.md +++ b/docs/release.md @@ -79,8 +79,8 @@ A regular release sequence runs as follows: 1. Creates the tag `v1.2.0` at the newly created merge commit — write-once. The tag is published here for the first time, never moved. 2. Cuts the write-once `api/apps/v1alpha1/v1.2.0` Go-module tag at the same commit. 3. Ensures the `release-1.2` maintenance branch exists at the tag commit. - 4. Publishes the release page (`draft` → `latest`). - 5. Retags the rc's images by digest to `v1.2.0` (and `:latest` only when `v1.2.0` is the newest published stable), and publishes the stable `cozy-installer` chart — no rebuild. + 4. Retags the rc's images by digest to `v1.2.0` (and `:latest` only when `v1.2.0` is the newest published stable), and publishes the stable `cozy-installer` chart — no rebuild. + 5. Publishes the release page (`draft` → `latest`). It goes last, so the page never announces a version whose images and chart are not in the registry yet. 6. The maintainer can now announce the release to the community. ```mermaid @@ -170,8 +170,8 @@ gitGraph 6. CI workflow triggers on merge (all irreversible side effects, post-e2e): 1. Creates the tag `v1.2.1` at the newly created merge commit — write-once. The tag is published here for the first time, never moved. 2. Cuts the write-once `api/apps/v1alpha1/v1.2.1` Go-module tag at the same commit. - 3. Publishes the release page (`draft` → `latest`; `latest` moves only if `v1.2.1` is the newest published stable). - 4. Retags the rc's images by digest to `v1.2.1` and publishes the stable `cozy-installer` chart — no rebuild. + 3. Retags the rc's images by digest to `v1.2.1` and publishes the stable `cozy-installer` chart — no rebuild. + 4. Publishes the release page (`draft` → `latest`; `latest` moves only if `v1.2.1` is the newest published stable). It goes last, so the page never announces a version whose images and chart are not in the registry yet. 7. The maintainer can now announce the release to the community. ## What CI does during the release process @@ -181,7 +181,7 @@ The numbered process above is implemented by five workflows. Knowing which job d 1. [`cut-prerelease.yaml`](../.github/workflows/cut-prerelease.yaml) — manual dispatch (from `main` or `release-X.Y`): the sole entry point for creating a pre-release tag. Validates the `-alpha`/`-beta`/`-rc` tag, then pushes it (write-once, at the branch tip) as the CI app so `tags.yaml` fires. Stable tags are never created here. 2. [`tags.yaml`](../.github/workflows/tags.yaml) — fires on an rc tag push: runs `prepare-release`, then `generate-changelog`, then `update-website-docs`. 3. [`promote-rc.yaml`](../.github/workflows/promote-rc.yaml) — manual dispatch: stages the `release-X.Y.Z` tree (rc digests, tag string rewritten to stable), drafts the stable release, and opens the `release-X.Y.Z` promote PR. No registry mutation — transactional. -4. [`pull-requests-release.yaml`](../.github/workflows/pull-requests-release.yaml) — fires when the `release-X.Y.Z` PR merges; finalizes the release: cuts the write-once stable + Go-module tags, publishes, then retags the rc images to stable by digest (`:latest` gated on newest-stable) and publishes the stable chart. +4. [`pull-requests-release.yaml`](../.github/workflows/pull-requests-release.yaml) — fires when the `release-X.Y.Z` PR merges; finalizes the release: cuts the write-once stable + Go-module tags, retags the rc images to stable by digest (`:latest` gated on newest-stable), publishes the stable chart, and last publishes the release. 5. [`update-releasenotes.yaml`](../.github/workflows/update-releasenotes.yaml) — fires on every push to `main`; syncs `docs/changelogs/v*.md` content into the corresponding GitHub Release body. ### Phase 1 — `prepare-release` (hard gate) @@ -232,13 +232,14 @@ Reviewer checklist: ### Phase 5 — `pull-requests-release.yaml` (finalize) -Fires on merge of a PR that is merged, carries the `release` label, and is authored by `cozystack-ci[bot]` (the last guard closes the "name a branch `release-X.Y.Z`, get it labelled, merge it" hole). Head branch must match `release-X.Y.Z[-suffix]`. This is where **every irreversible side effect of a promotion happens** — after the PR's e2e passed and the PR merged, making promotion transactional. Steps: +Fires on merge of a PR that is merged, carries the `release` label, and is authored by `cozystack-ci[bot]` (the last guard closes the "name a branch `release-X.Y.Z`, get it labelled, merge it" hole). Head branch must match `release-X.Y.Z[-suffix]`. This is where **every irreversible side effect of a promotion happens** — after the PR's e2e passed and the PR merged, making promotion transactional. Finalize runs one release at a time: two release PRs merged close together finalize one after the other, so the second decides `latest` against a release the first has already published. Steps: 1. **Create the tag at the merge commit** (write-once). The merge commit of `Prepare release vX.Y.Z` did not exist before the PR opened, so there is nothing to move — the tag is created here for the first time. A pre-existing tag at a different commit fails the step loudly rather than being force-moved (see [Tag immutability](#tag-immutability)). 2. **Cut the `api/apps/v1alpha1/vX.Y.Z` Go-module tag** (write-once, stable only) at the same commit, so Go consumers of `api/apps/v1alpha1` get the release. Moved here from `tags.yaml`, whose `prepare-release` body is skipped for a promoted stable (the draft already exists). 3. **Ensure the maintenance branch `release-X.Y` exists** at the tag commit. Created if missing; updated fast-forward-only — a non-fast-forward update warns and is left for a maintainer rather than being force-updated. -4. **Publish the draft release.** `make_latest` is computed against published-non-prerelease tags: prereleases stay `false`; tags older than the current max stay `false` (and the current max is force-restored to `latest` if necessary, so an older patch tag cut after a newer minor won't downgrade `latest`). -5. **Retag the rc images to stable** by digest (`hack/promote-retag.sh`, no rebuild) and **publish the stable `cozy-installer` chart**. `:latest` (on both the images and the chart) moves only when this release's `make_latest` was `true` — the same decision as step 4, so the release's `latest` and the images' `:latest` never disagree. The chart is packaged with `platformVersion` stamped into its default values so the documented `helm --install --version X.Y.Z` path reports the stable version. +4. **Resolve the draft release** and decide whether it becomes `latest`, before anything is written to the registry, so a missing draft fails the job while no stable image name exists yet. `make_latest` is computed against published-non-prerelease tags: prereleases stay `false`; tags older than the current max stay `false`. +5. **Retag the rc images to stable** by digest (`hack/promote-retag.sh`, no rebuild) and **publish the stable `cozy-installer` chart**. `:latest` (on both the images and the chart) moves only when this release's `make_latest` was `true` — the decision step 4 made, so the release's `latest` and the images' `:latest` agree within a run. The chart is packaged with `platformVersion` stamped into its default values so the documented `helm --install --version X.Y.Z` path reports the stable version. +6. **Publish the draft release**, with `docs/changelogs/vX.Y.Z.md` from the merge commit as its body. It runs last on purpose: the release page is what announces the version, so it goes public only once the images and chart it points at exist, and a failed retag leaves the draft in place for a re-run. For an older patch tag cut after a newer minor, the current max is force-restored to `latest` if necessary, so `latest` is not downgraded. ### Phase 6 — `update-releasenotes.yaml` (sync GitHub Release body) @@ -524,14 +525,14 @@ For RCs and final releases, run this before merging the release PR. Each item is - [ ] **Apply-mutate-reapply** on the kubernetes umbrella HelmRelease (catches second-reconcile bugs). - [ ] **For every CRD-source bump** (kubevirt, cert-manager, flux, cilium, kamaji): `helm template | kubectl apply --dry-run=server` against the freshly-installed CRDs. - [ ] **For every flux / helm-controller / kubevirt-operator / cert-manager bump:** paste the upstream breaking-changes section of the bump's CHANGELOG into the PR body before merge. -- [ ] **After cutting the tag,** watch `pull-requests-release.yaml::Finalize Release`. If it fails on `Draft release for v... not found`, undraft the release manually and file the workflow regression — this has been a known recurring failure since the `Publish draft release` step lost its explicit `github-token` in refactor `66a756b6`. +- [ ] **After cutting the tag,** watch `pull-requests-release.yaml::Finalize Release`. If it fails on `Draft release for v... not found` while the release is still a draft, nothing has been written to the registry yet, so undrafting the release by hand would publish it without its stable images and chart. If the release is already published, this is a re-run after `Publish draft release` failed past the undraft: the images and the chart went out in the earlier attempt, so only check that `latest` sits on the newest stable (`gh release edit --latest`). Fix the cause and re-run the failed job; a re-run uses the same workflow file, so for a workflow regression run `hack/promote-retag.sh` and push the stable chart by hand first (the commands are the `Retag rc images to stable` and `Publish stable cozy-installer chart` steps), then undraft. If the step lost its `github-token` again, file the workflow regression: it lists releases with the CI app token, and while it ran without it, until `7d2fe2f7`, the lookup found no draft on any release. - [ ] **Changelog PR exists and was verified** per [Changelog pre-publish verification](#changelog-pre-publish-verification). ## CI failures release engineers commonly hit | Symptom | Class | Diagnosis | Block release? | |---------|-------|-----------|----------------| -| `Draft release for vX.Y.Z not found` on every release-* merge | Workflow regression — `Publish draft release` lost its `github-token` in a past refactor; default `GITHUB_TOKEN` cannot list drafts | At `pull-requests-release.yaml:163`. Undraft manually, file the fix | No | +| `Draft release for vX.Y.Z not found` in finalize | No draft the CI app token can see: the draft for the tag is missing, or the `Resolve draft release` step lost its `github-token` again (it lists releases with the CI app token; while it ran without it, until `7d2fe2f7`, the lookup found no draft on any release) | In the `Resolve draft release` step of `pull-requests-release.yaml`. A release that is already published means a re-run after `Publish draft release` failed past the undraft: the images and the chart went out in the earlier attempt, so only check that `latest` sits on the newest stable. Otherwise the job stops before the retag and the chart, so do not undraft first: fix the cause and re-run the job, or run those two steps by hand and then undraft. File the fix when the token is gone | No | | Changelog Copilot job returns 402 | Token quota — `COPILOT_GITHUB_TOKEN` premium-request quota empty | All tag CI runs that day fail the changelog phase | No — `continue-on-error: true`, generate changelog by hand following [`agents/changelog.md`](./agents/changelog.md) | | E2E `kubernetes-test` fails with `CSINode does not contain driver csi.kubevirt.io` | Test ordering bug | Tenant's `kubernetes-${test_name}-csi` HelmRelease still installing when NFS PVC is created. Fix: wait for `csinode/` to advertise the driver before creating the PVC | Yes — flaky and masks real CSI bugs | | `tenant-root` HR in perpetual upgrade-rollback loop after OIDC patch | Real bug at the intersection of #2602's readiness change and the cozystack reconcile cadence | Look for `rate: Wait(n=1) would exceed context deadline` in operator logs; multiple tenant child HRs stuck `InProgress` | Yes | diff --git a/hack/promote-gate-contract.bats b/hack/promote-gate-contract.bats index d5c5d9837..4a462009d 100644 --- a/hack/promote-gate-contract.bats +++ b/hack/promote-gate-contract.bats @@ -251,6 +251,62 @@ step_line() { [ "$tooling_step" -lt "$verify" ] } +# 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. The registry steps and the page read the one +# `latest` decision resolve made before the first registry write. +@test "finalize publishes the release page only after the stable images and chart exist" { + block="$(job_block finalize "$FINALIZE")" + [ -n "$block" ] + resolve="$(step_line 'Resolve draft release' "$block")" + retag="$(step_line 'Retag rc images to stable' "$block")" + chart="$(step_line 'Publish stable cozy-installer chart' "$block")" + publish="$(step_line 'Publish draft release' "$block")" + [ -n "$resolve" ] + [ -n "$retag" ] + [ -n "$chart" ] + [ -n "$publish" ] + [ "$resolve" -lt "$retag" ] + [ "$retag" -lt "$chart" ] + [ "$chart" -lt "$publish" ] + [ "$(yq '.jobs.finalize.steps[] | select(.name == "Retag rc images to stable") | .env.MOVE_LATEST' "$FINALIZE")" = "\${{ steps.resolve.outputs.make_latest == 'true' && '1' || '0' }}" ] + [ "$(yq '.jobs.finalize.steps[] | select(.name == "Publish stable cozy-installer chart") | .env.MAKE_LATEST' "$FINALIZE")" = "\${{ steps.resolve.outputs.make_latest }}" ] + [ "$(yq '.jobs.finalize.steps[] | select(.name == "Publish draft release") | .env.MAKE_LATEST' "$FINALIZE")" = "\${{ steps.resolve.outputs.make_latest }}" ] +} + +# Order alone does not hold the page back. A registry step allowed to fail, or +# skipped for a stable tag, or a publish step that runs whatever happened before +# it, publishes over a missing image or chart all the same; and the chart's +# `latest` moves only on the decision. +@test "finalize publishes nothing after a failed registry step" { + [ "$(yq '.jobs.finalize.steps[] | select(.name == "Resolve draft release") | has("continue-on-error")' "$FINALIZE")" = false ] + [ "$(yq '.jobs.finalize.steps[] | select(.name == "Retag rc images to stable") | has("continue-on-error")' "$FINALIZE")" = false ] + [ "$(yq '.jobs.finalize.steps[] | select(.name == "Publish stable cozy-installer chart") | has("continue-on-error")' "$FINALIZE")" = false ] + [ "$(yq '.jobs.finalize.steps[] | select(.name == "Publish draft release") | has("continue-on-error")' "$FINALIZE")" = false ] + [ "$(yq '.jobs.finalize.steps[] | select(.name == "Publish draft release") | has("if")' "$FINALIZE")" = false ] + [ "$(yq '.jobs.finalize.steps[] | select(.name == "Retag rc images to stable") | .if' "$FINALIZE")" = "\${{ !contains(steps.get_tag.outputs.tag, '-') }}" ] + [ "$(yq '.jobs.finalize.steps[] | select(.name == "Publish stable cozy-installer chart") | .if' "$FINALIZE")" = "\${{ !contains(steps.get_tag.outputs.tag, '-') }}" ] + [ "$(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' ] + [ "$(printf '%s\n' "$chart_code" | grep -cF '||')" -eq 0 ] + [ "$(printf '%s\n' "$chart_code" | grep -cF 'cozy-installer:latest')" -eq 1 ] + printf '%s\n' "$chart_code" | grep -A3 -F 'if [ "${MAKE_LATEST}" = "true" ]; then' | grep -qF 'cozy-installer:latest' +} + +# 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, so a PR that skips finalize never joins it, and every +# merged release waits its turn instead of the waiting one being cancelled. +@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 ] + cond="$(yq '.jobs.finalize.if' "$FINALIZE" | tr '\n' ' ' | sed 's/[[:space:]][[:space:]]*/ /g; s/^ //; s/ $//')" + [ -n "$cond" ] + [ "$(yq '.jobs.finalize.concurrency.group' "$FINALIZE")" = "\${{ ($cond) && 'release-finalize' || format('release-finalize-skipped-{0}', github.event.pull_request.number) }}" ] +} + @test "finalize checkout does not persist credentials so the app-token tag push triggers tags.yaml" { block="$(job_block finalize "$FINALIZE")" [ -n "$block" ]