Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(release): never delete the staging version after a promote

Yudhi Armyndharis6f22226784ec
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 0511939f6..898ce35f9 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -821,7 +821,9 @@ jobs:
# This lives in its own `if: always()` job — not inside promote — because the failure path is
# exactly when cleanup matters most: when boot-smoke or image-scan fails, promote is skipped and
# the staging tag would otherwise leak. On the happy path the release tags share the staging
- # version, so the step below keeps it (the deliberate retention documented above); on a failed
+ # version, so the step below does not run at all (the deliberate retention documented above): the
+ # package-versions API is eventually consistent, and a read that does not list the new release
+ # tags yet would count the staging tag alone and delete the version just published. On a failed
# run the staging tag is alone and gets removed.
cleanup-staging:
name: Clean up the staging tag
@@ -833,6 +835,10 @@ jobs:
needs: [docker, boot-smoke, image-scan, promote]
steps:
- name: Remove the staging tag (only when it is alone on its version)
+ # Never after a successful promote: the release tags share this version by construction, so
+ # a tag count of 1 there can only be a stale read. The count below still guards a promote
+ # that failed after attaching some release tags.
+ if: needs.promote.result != 'success'
# Best-effort: a failed tidy-up must not turn an otherwise successful release red.
continue-on-error: true
env:
@@ -875,10 +881,9 @@ jobs:
name: Verify published tags (anonymous)
runs-on: ubuntu-latest
timeout-minutes: 15
- # After cleanup-staging, not beside it: GHCR's package-versions API is eventually consistent, so
- # that job can read a version whose release tags are not listed yet and delete the version the
- # release just published. This check is the net for exactly that, so it has to run last. It is a
- # best-effort job, so gate on promote rather than on its result.
+ # After cleanup-staging, not beside it: that job deletes registry versions, so this check has to
+ # see the registry after it, and run last. It is a best-effort job, so gate on promote rather
+ # than on its result.
needs: [docker, promote, cleanup-staging]
if: always() && needs.promote.result == 'success'
# attestations: read for `gh attestation verify` below. GH_TOKEN is an API credential for the
diff --git a/src/common/release-staging-cleanup.spec.ts b/src/common/release-staging-cleanup.spec.ts
new file mode 100644
index 000000000..24599b73a
--- /dev/null
+++ b/src/common/release-staging-cleanup.spec.ts
@@ -0,0 +1,31 @@
+import { readFileSync } from 'node:fs';
+import { join } from 'node:path';
+import * as yaml from 'js-yaml';
+
+/**
+ * GHCR deletes by version, and after a successful promote the release tags share the staging tag's
+ * version. The cleanup job decides from a read of the package-versions API, which is eventually
+ * consistent: a read that does not list the new release tags yet shows the staging tag alone, and
+ * deleting that version unpublishes X.Y.Z, X.Y and latest together. So the delete step must not
+ * run at all once promote succeeded, whatever the read says.
+ */
+describe('release staging-tag cleanup', () => {
+ type Step = { if?: string; run?: string };
+ type Job = { if?: string; needs?: string[]; steps?: Step[] };
+ const workflow = yaml.load(
+ readFileSync(join(__dirname, '..', '..', '.github', 'workflows', 'release.yml'), 'utf8'),
+ ) as { jobs?: Record<string, Job> };
+ const job = workflow.jobs?.['cleanup-staging'];
+
+ it('still runs on the failure path, after promote', () => {
+ expect(job?.if).toBe('always()');
+ expect(job?.needs).toContain('promote');
+ });
+
+ it('skips every delete once promote succeeded', () => {
+ const deleting = (job?.steps ?? []).filter(step => /-X DELETE/.test(step.run ?? ''));
+ // Vacuity guard: a renamed job or a reworded command would leave nothing to check.
+ expect(deleting.length).toBeGreaterThan(0);
+ for (const step of deleting) expect(step.if).toBe("needs.promote.result != 'success'");
+ });
+});