Skip to content

fix: publish releases after uploading assets - #219

Merged
uniqueg merged 6 commits into
devfrom
fix/216-immutable-releases
Oct 24, 2026
Merged

uniqueg merged 6 commits into
devfrom
fix/216-immutable-releases

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Summary

The release workflow's "Create release" step is now safe with immutable releases and re-runs:

  • It creates the release explicitly as a draft (gh release create --draft), uploads the chart and its Sigstore bundle (gh release upload --clobber, which works on drafts), and publishes it last. The final gh release edit --draft=false also sets the title, the curated notes, --prerelease and --latest.
  • On re-runs, it finishes a draft left by an earlier attempt.
  • On re-runs with a release that is already published (for example, by hand, as for v0.3.0), it uploads nothing. The new scripts/release_assets.py checks that the release has exactly the assets that the run built, with the same SHA-256 digests (the API's digest field). 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.
  • The release notes are generated on every run, so a finished draft gets the notes since the current previous release.
  • Several drafts for the tag, or drafts next to a published release, are errors. With gh 2.102.0, FetchRelease runs the published and the draft lookups at the same time and keeps whichever succeeds first, so gh release edit <tag> might pick a draft.
  • The "Determine the previous release" step is unchanged and keeps ignoring drafts (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.go sets draftWhileUploading = true and params["draft"] = true when there are assets and no --draft. It uploads, then calls publishRelease (a PATCH with draft: 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. coverage of scripts/release_assets.py: 100%. The scripts' tests together: 100% for scripts/.
  • Full pytest: 1044 passed, 228 skipped (before the review fixes, which touched only the script and its tests).
  • pre-commit run on the changed files (ruff, ruff format, mypy, actionlint, semgrep, etc.): passed. shellcheck is not installed locally, so actionlint ran without it; CI runs it.
  • I ran the step's run: script, taken from the workflow, under bash -eo pipefail with a stub gh, for each state:
    • no release: create the draft, upload, publish;
    • draft: upload, publish;
    • published with all assets: edit only, with a warning for a re-signed bundle;
    • published without assets: ::error::, exit 1;
    • published plus a draft: ::error::, exit 1.
  • Not run locally: 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

  • The state positional of scripts/release_assets.py has a single choice. It is kept for symmetry with release_version.py (command first) and leaves room for more commands.
  • "Drafts next to a published release only need a warning, as gh looks up the published release first". In gh 2.102.0, FetchRelease runs 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:

  • Add release asset validation that identifies draft, published, and missing releases and verifies published assets by SHA-256 digest.

Bug Fixes:

  • Make release workflow reruns safe for immutable releases by uploading assets before publishing and handling existing drafts or published releases correctly.

Enhancements:

  • Regenerate release notes on every run and update published releases only where immutable-release metadata remains editable.

Documentation:

  • Document immutable release handling, rerun behavior, and asset validation for maintainers.

Tests:

  • Add comprehensive tests covering release discovery, asset validation, digest mismatches, signatures, and invalid release data.

uniqueg and others added 4 commits October 24, 2026 03:05
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]>
@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The 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 publishing

sequenceDiagram
    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
Loading

State diagram for release rerun handling

stateDiagram-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 --> [*]
Loading

File-Level Changes

Change Details Files
Reworked the release workflow to create and populate releases as drafts before publishing, while making reruns safe for drafts and already-published releases.
  • Generate release notes on every run, preserving curated-note behavior.
  • Query all releases including drafts and determine whether to create, resume, or validate a release.
  • Create drafts explicitly, upload assets with clobbering, then publish through the final edit that sets title, notes, prerelease, and latest flags.
  • Avoid uploads for published releases and update only fields permitted for immutable releases.
.github/workflows/release.yaml
Added release-state and asset-integrity validation for immutable-release workflows.
  • Parse paginated GitHub release API responses and classify matching releases as none, draft, or published.
  • Compare published assets by name and SHA-256 digest, allowing only re-signed Sigstore bundles to differ with a warning.
  • Reject missing, changed, unexpected, duplicate-draft, and published-plus-draft states with actionable GitHub annotations.
scripts/release_assets.py
Documented immutable release behavior and added comprehensive validation coverage.
  • Document draft-first publishing, rerun behavior, immutable-release remediation, and asset checks.
  • Test release parsing, state classification, digest validation, warning/error behavior, and CLI failures.
docs/development.md
tests/test_release_assets.py

Assessment against linked issues

Issue Objective Addressed Explanation
#216 Create releases as drafts, upload assets and set notes before publishing as the final action; allow reruns to finish an existing draft. ✅
#216 On reruns with a published release, do not upload assets; verify expected assets by name and digest where available, fail clearly if they are missing or incorrect, and edit only fields that remain editable. ✅
#216 Keep the previous-release lookup excluding drafts. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (da73bec) to head (9688a1b).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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]>
@uniqueg
uniqueg marked this pull request as ready for review October 24, 2026 01:50

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread scripts/release_assets.py Resolved
Comment thread scripts/release_assets.py Resolved
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]>
@uniqueg
uniqueg merged commit 716c203 into dev Oct 24, 2026
19 checks passed
@uniqueg
uniqueg deleted the fix/216-immutable-releases branch October 24, 2026 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: publish releases after uploading assets

1 participant