mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-02 21:30:46 +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.
On this line hack/promote-gate-contract.bats fails on a release page
published before the registry steps, 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. The line has no harness
for its github-script steps, so both were run by hand against a stubbed
API: a missing draft, an orphaned draft, an older patch after a newer
minor, a newest stable, an rc, and an empty or missing changelog.
Assisted-by: LLM
(cherry picked from commit e1472e58de)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
4 files changed
+187
-89
No files matched your search
@@ -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
|
||||
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user