Skip to content

Commit 53c046c

Browse files
committed
fix(release): publish the GitHub release only after its verified assets attach (#5555)
GitHub freezes a release when it is published, so the attach step's upload came back HTTP 422 "Cannot upload assets to an immutable release". Every release from v2.55.0 to v2.60.0 therefore shipped with zero assets and the desktop updater had nothing to download. Create the release as a draft and flip it to published in attach-release, after the verified bundle is uploaded. Release notes still come from the validated notes file written at creation.
1 parent f1b2180 commit 53c046c

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,19 @@ jobs:
578578
# run: source. tests/ci-workflows.test.ts enforces this repo-wide.
579579
RELEASE_VERSION: ${{ inputs.version }}
580580
run: |
581-
gh release upload "v${RELEASE_VERSION}" dist/release/* --clobber
581+
set -euo pipefail
582+
release_tag="v${RELEASE_VERSION}"
583+
gh release upload "$release_tag" dist/release/* --clobber
584+
585+
# A published release is immutable: GitHub rejects every later asset upload
586+
# with HTTP 422, which is why v2.55.0 through v2.60.0 shipped with zero
587+
# assets and left the desktop updater without anything to download. The
588+
# release is therefore created as a draft and becomes public here, once the
589+
# verified bundle is attached. The only edit permitted is this flip — the
590+
# notes still come from the validated notes file written at creation.
591+
if [ "$(gh release view "$release_tag" --json isDraft --jq .isDraft)" = "true" ]; then
592+
gh release edit "$release_tag" --draft=false
593+
fi
582594
583595
publish:
584596
needs: [validate-dispatch, verify-release]
@@ -981,6 +993,9 @@ jobs:
981993
exit 1
982994
fi
983995
else
984-
gh release create "$release_tag" --target "$GITHUB_SHA" --title "$release_tag" \
996+
# Draft first. Publication freezes a release under GitHub's immutable
997+
# releases, so attach-release attaches the verified bundle to the draft
998+
# and publishes it afterwards.
999+
gh release create "$release_tag" --draft --target "$GITHUB_SHA" --title "$release_tag" \
9851000
--notes-file "$notes_file" ${prerelease_flag:+$prerelease_flag}
9861001
fi

‎tests/ci-workflows/ci-workflows.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,14 @@ describe("GitHub Actions hardening", () => {
10331033
expect(releaseNotesBuilder).toContain("release changelog failed coverage validation");
10341034

10351035
expect(workflow).toMatch(/gh release create[\s\S]*?--notes-file "\$notes_file"/);
1036-
expect(workflow).not.toContain("gh release edit");
1036+
// The release is created as a draft and published only after the verified
1037+
// bundle is attached, because a published release is immutable and rejects
1038+
// every later upload. That draft flip is the one edit allowed: notes still
1039+
// come from the validated notes file, never from an edit or a regeneration.
1040+
for (const edit of workflow.match(/gh release edit[^\n]*/g) ?? []) {
1041+
expect(edit).toContain("--draft=false");
1042+
expect(edit).not.toContain("--notes");
1043+
}
10371044
expect(workflow).not.toContain("--generate-notes");
10381045

10391046
const createStep = workflow

‎tests/ci-workflows/release-pipeline-contract.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,22 @@ describe("release pipeline contract", () => {
153153
expect(upload).toBeGreaterThan(receiptCheck);
154154
});
155155

156+
test("the release is a draft until the verified assets are attached", () => {
157+
// GitHub freezes a release the moment it is published: every later asset upload
158+
// comes back HTTP 422 "Cannot upload assets to an immutable release". Creating
159+
// the release published and uploading afterwards is what left v2.55.0 through
160+
// v2.60.0 with zero assets and the desktop updater with nothing to fetch.
161+
const releaseText = readFileSync(repoPath(".github", "workflows", "release.yml"), "utf8");
162+
const createStep = releaseText.split("- name: Create GitHub release")[1] ?? "";
163+
expect(createStep).toMatch(/gh release create "\$release_tag" --draft/);
164+
165+
const attachRun = (release.jobs?.["attach-release"]?.steps ?? [])
166+
.map(candidate => candidate.run ?? "")
167+
.find(run => run.includes("gh release upload")) ?? "";
168+
expect(attachRun).toContain("--draft=false");
169+
expect(attachRun.indexOf("gh release upload")).toBeLessThan(attachRun.indexOf("--draft=false"));
170+
});
171+
156172
test("a partial publication has a recorded, explicit recovery path", () => {
157173
const releaseText = readFileSync(repoPath(".github", "workflows", "release.yml"), "utf8");
158174
// The only way npm publish is ever skipped: an explicit recovery input, requiring

0 commit comments

Comments
 (0)