Repository navigation
fix: publish releases after uploading assets - #219
Conversation
Assets of a published immutable release can't be added, replaced or deleted, so re-runs of the release workflow failed after the release was published (e.g., by hand): `gh release upload --clobber` got HTTP 422. Create the release explicitly as a draft, upload the assets and publish it, with its notes and flags, last. Re-runs finish a draft of an earlier attempt. A published release gets no uploads; it must have all assets by name (digests that differ only warn, as signatures change with every attempt), or the step fails and says what to do. The release lookup and asset check are in `scripts/release_assets.py`, with tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A published release with another version of an asset than the run built is now an error (only Sigstore bundles, which every attempt makes anew, may differ), as its attestation and signature would not match. Drafts next to a published release are an error too, as `gh release edit <tag>` might pick a draft. Test `main` in process, one case per test, and document the script. Co-Authored-By: Claude Opus 5.5 <[email protected]>
For a release that is not immutable, the remedy for missing or changed assets is now to delete the release and re-run the job, which creates it anew: the run's artifacts don't include the Sigstore bundles, so replacing assets by hand could leave a bundle that signs another file. Also word the stray-drafts error consistently, test missing and changed assets together, and rewrap the docs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR changes release publishing to use a draft-upload-publish sequence compatible with immutable releases, adds digest-based validation for reruns and manually published releases, and covers the new state machine with tests and documentation. Sequence diagram for immutable release publishingsequenceDiagram
participant Workflow
participant Assets as release_assets.py
participant GitHub as GitHub Releases API
participant Storage as Release assets
Workflow->>GitHub: gh api --paginate releases
GitHub-->>Workflow: Draft and published releases
Workflow->>Assets: state TAG releases dist/*
Assets-->>Workflow: state=none, draft, or published
alt state=none
Workflow->>GitHub: gh release create TAG --draft
Workflow->>GitHub: gh release upload TAG dist/* --clobber
Workflow->>GitHub: gh release edit TAG --draft=false
else state=draft
Workflow->>GitHub: gh release upload TAG dist/* --clobber
Workflow->>GitHub: gh release edit TAG --draft=false
else state=published
Assets->>Storage: Compare asset names and SHA-256 digests
alt Assets match
Workflow->>GitHub: gh release edit TAG title, notes, flags
else Assets differ
Assets-->>Workflow: ::error:: with remediation
end
end
State diagram for release rerun handlingstateDiagram-v2
[*] --> none
[*] --> draft
[*] --> published
none --> draft: gh release create --draft
draft --> published: upload assets
published --> published: validate assets and edit metadata
published --> error: missing, changed, or unexpected asset
none --> error: multiple drafts or published plus draft
draft --> error: multiple drafts
error --> [*]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #219 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 15 16 +1
Lines 1198 1283 +85
=========================================
+ Hits 1198 1283 +85 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A published release must now have exactly the assets that the run built: assets without a digest count as changed, and assets that the run did not build are an error. The release notes are generated on every run, so that a draft of an earlier attempt is published with the notes since the current previous release (published releases keep generated notes, as before). Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="scripts/release_assets.py" line_range="108" />
<code_context>
+ missing.append(path.name)
+ elif uploaded[path.name] != sha256(path):
+ signature = path.name.endswith(SIGNATURE_SUFFIX)
+ (resigned if signature else changed).append(path.name)
+ names = {path.name for path in paths}
+ unexpected = sorted(str(name) for name in uploaded if name not in names)
</code_context>
<issue_to_address>
**Invalid signature bundle passes validation**
When a published release has a differing Sigstore bundle that does not verify the chart or tag, `check_published` treats every differing Sigstore bundle as a warning, and `release_state` returns `published` without verifying it, so the workflow succeeds with a bundle consumers cannot use to verify the release.
Verify each differing Sigstore bundle against the chart and tag, and treat bundles that fail verification as errors.
</issue_to_address>
### Comment 2
<location path="scripts/release_assets.py" line_range="97" />
<code_context>
+ uploaded = {
+ asset.get("name"): asset.get("digest")
+ for asset in release.get("assets") or []
+ if asset.get("state") == "uploaded"
+ }
+ missing: list[str] = []
</code_context>
<issue_to_address>
**Unfinished extra assets pass validation**
When a published release retains an unexpected asset whose API state is not `uploaded`, `check_published` filters out assets whose state is not `uploaded`, then checks unexpected names only against that filtered mapping. A published release with an unexpected asset still in another state is therefore accepted as complete.
Check all asset names for unexpected entries, while continuing to require `uploaded` state for expected assets.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and if the release-state check or draft-upload sequence is wrong, an incomplete or incorrect chart or signature bundle could be published. Published immutable release assets cannot be replaced or deleted, so reverting the workflow would not undo releases already published; they would need a new version.
Blocking findings: scripts/release_assets.py:108, scripts/release_assets.py:97
Look for unexpected assets of a published release among all of its assets, whatever their state, as unfinished uploads are visible too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
The release workflow's "Create release" step is now safe with immutable releases and re-runs:
gh release create --draft), uploads the chart and its Sigstore bundle (gh release upload --clobber, which works on drafts), and publishes it last. The finalgh release edit --draft=falsealso sets the title, the curated notes,--prereleaseand--latest.scripts/release_assets.pychecks that the release has exactly the assets that the run built, with the same SHA-256 digests (the API'sdigestfield). Only Sigstore bundles may differ, with a warning, because every attempt signs anew. Otherwise the step fails with an::error::that says what to do: a new patch version for immutable releases, or deleting the release and re-running if releases are not immutable. After that, only the title, flags and (curated) notes are edited; these stay editable on immutable releases.FetchReleaseruns the published and the draft lookups at the same time and keeps whichever succeeds first, sogh release edit <tag>might pick a draft.gh release list --exclude-drafts).Evidence for the old normal path (gh v2.102.0, the version on
ubuntu-latest, image 20261012.334.1):pkg/cmd/release/create/create.gosetsdraftWhileUploading = trueandparams["draft"] = truewhen there are assets and no--draft. It uploads, then callspublishRelease(a PATCH withdraft: false). Its help text says: "separate API calls are made to create the release as a draft, upload the assets, and then publish the release". GitHub's immutable releases docs say: "You can still edit the title and release notes of a published immutable release, and change whether it is marked as a pre-release or as the latest release". They recommend draft, then attach, then publish.Verification
pytest tests/test_release_assets.py: 24 passed.coverageofscripts/release_assets.py: 100%. The scripts' tests together: 100% forscripts/.pytest: 1044 passed, 228 skipped (before the review fixes, which touched only the script and its tests).pre-commit runon the changed files (ruff, ruff format, mypy, actionlint, semgrep, etc.): passed. shellcheck is not installed locally, so actionlint ran without it; CI runs it.run:script, taken from the workflow, underbash -eo pipefailwith a stubgh, for each state:::error::, exit 1;::error::, exit 1.mkdocs build --strict(mkdocs is not in my venv), which CI runs. I did no end-to-end run against a real repository; the maintainer asked to skip that for this PR.Declined review findings
statepositional ofscripts/release_assets.pyhas a single choice. It is kept for symmetry withrelease_version.py(command first) and leaves room for more commands.FetchReleaseruns both lookups concurrently and returns the first success, so the error stays.Open questions
None.
Closes #216
🤖 Generated with Claude Code
Summary by Sourcery
Make the release workflow safely create, validate, and publish immutable GitHub releases with correct assets and rerun behavior.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: