Skip to content

fix: publish releases after uploading assets - #452

Merged
uniqueg merged 3 commits into
devfrom
fix/451-immutable-releases
Oct 24, 2026
Merged

uniqueg merged 3 commits into
devfrom
fix/451-immutable-releases

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Summary

The github-release job of the release workflow is now safe with immutable releases (enabled for this repository) and re-runs. The same fix is in elixir-cloud-aai/cloud-registry#219 and elixir-cloud-aai/protes#287.

  • It creates the GitHub release explicitly as a draft (gh release create --draft --generate-notes), uploads the distributions (gh release upload --clobber, which works on drafts), and publishes it last (gh release edit --draft=false).
  • On re-runs, it finishes a draft left by an earlier attempt.
  • On re-runs with a release that is already published, it uploads nothing. The new scripts/release_assets.py (the same as cloud-registry's, with tests) checks that the release has exactly the distributions that the run built, with the same SHA-256 digests (the API's digest field). Otherwise the step fails with an ::error:: that says what to do (a new patch version).
  • Several drafts for the tag, or drafts next to a published release, are errors.
  • The job now checks out the repository and sets up Python 3.13 for the script.

release-chart.yml is not affected: it pushes the chart to GHCR and creates no GitHub release.

Evidence for the old normal path (gh v2.102.0 on ubuntu-latest): gh release create TAG files… already creates a draft, uploads and then publishes (draftWhileUploading in pkg/cmd/release/create/create.go). The broken part was the re-run path, which ran gh release upload --clobber on a published release. That fails on immutable releases with HTTP 422, as it did for cloud-registry v0.3.0.

Verification

  • pytest tests/test_release_assets.py: 24 passed. tests/test_citation.py also passes.
  • mypy (whole configured scope): no issues. pre-commit run on the changed files: passed (ruff, actionlint, semgrep, etc.).
  • I ran the step's run: script 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 and complete: no calls;
    • published without assets: ::error::, exit 1;
    • published plus a draft: ::error::, exit 1.
  • Not run locally: the full test suite (needs MongoDB). CI runs it.

Declined review findings

  • --latest on publish: publishing through gh release edit sends no make_latest, exactly like the old gh release create (GitHub's default applies). Before 1.0.0 all releases are pre-releases, so this has no effect. Computing latest like cloud-registry does would be a separate change.
  • A draft's generated notes are fixed when the draft is created (cloud-registry regenerates them; FOCA uses --generate-notes and has no previous-release step). This is unlikely with one release run at a time, and it is kept minimal here.
  • The script prints state=<state> (a GITHUB_OUTPUT line) and the job strips the prefix. This is kept identical to cloud-registry's script.
  • Not removing the mktemp file: GitHub-hosted runners are not reused.

Open questions

None.

Closes #451

🤖 Generated with Claude Code

Summary by Sourcery

Make the GitHub release workflow robust to immutable releases and reruns by validating existing assets and publishing drafts only after uploads complete.

New Features:

  • Add release asset validation that compares published release contents and SHA-256 digests with the distributions built by the workflow, while allowing regenerated Sigstore bundles with warnings.

Bug Fixes:

  • Make release workflow reruns safe for immutable GitHub releases by uploading assets to drafts before publishing and avoiding uploads to already published releases.
  • Detect and fail on ambiguous release states, including multiple drafts or drafts alongside a published release, with actionable remediation messages.

Enhancements:

  • Update release contribution guidance to document draft-based publishing, immutable assets, and rerun behavior.

Documentation:

  • Document the immutable-release publishing and recovery procedure in the contributor release guidance.

Tests:

  • Add comprehensive tests covering release discovery, asset digest validation, rerun states, malformed input, warnings, and failure cases.

uniqueg and others added 2 commits October 24, 2026 03:30
Assets of a published immutable release can't be added, replaced or
deleted, so a re-run of the release workflow after its GitHub release
was published failed (`gh release upload --clobber` gets HTTP 422), and
a re-run never published a leftover draft.

Create the GitHub release explicitly as a draft, upload the
distributions and publish it last. Re-runs finish a draft of an earlier
attempt. A published release gets no uploads: it must have all
distributions, with the same digests, or the step fails and says what
to do. The release lookup and asset check are in
`scripts/release_assets.py` (as in cloud-registry), with tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A published release must now have exactly the distributions that the
run built: assets without a digest count as changed, and assets that the
run did not build are an error (as in cloud-registry). Reflow 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 release process now creates and uploads assets to a draft before publishing, safely completes drafts on reruns, and validates already-published releases by asset name and SHA-256 digest to avoid modifying immutable releases. A standard-library validation script, extensive tests, workflow Python setup, and contributor documentation support the new behavior.

Sequence diagram for immutable release publishing and reruns

sequenceDiagram
    participant Workflow
    participant Validator as release_assets.py
    participant GitHub as GitHub Releases API
    participant GH as gh CLI

    Workflow->>GitHub: gh api --paginate --slurp releases
    Workflow->>Validator: state TAG --releases FILE dist/*
    Validator->>Validator: release_state(TAG, releases, assets)
    alt No release
        Validator-->>Workflow: state=none
        Workflow->>GH: gh release create TAG --draft --generate-notes
        Workflow->>GH: gh release upload TAG dist/* --clobber
        Workflow->>GH: gh release edit TAG --draft=false
    else Existing draft
        Validator-->>Workflow: state=draft
        Workflow->>GH: gh release upload TAG dist/* --clobber
        Workflow->>GH: gh release edit TAG --draft=false
    else Published release with matching assets
        Validator->>Validator: check_published(TAG, release, assets)
        Validator-->>Workflow: state=published
        Workflow-->>Workflow: Exit without uploads
    else Published release with missing or changed assets
        Validator->>Validator: check_published(TAG, release, assets)
        Validator-->>Workflow: error annotation, exit 1
    end
Loading

Flow diagram for release state validation

flowchart TD
    A[Fetch all releases including drafts] --> B[release_state TAG releases assets]
    B --> C{Release state}
    C -->|none| D[Create draft release]
    C -->|draft| E[Upload assets with clobber]
    C -->|published| F[check_published]
    C -->|Ambiguous drafts or draft plus published| G[Fail with error annotation]
    F --> H{Names and SHA-256 digests match}
    H -->|Yes| I[Skip uploads]
    H -->|No| J[Fail and request a new patch version]
    D --> E
    E --> K[Publish draft]
Loading

File-Level Changes

Change Details Files
Reworked the release workflow to handle immutable GitHub releases and safe retries by uploading to drafts before publishing.
  • Checks out the repository and sets up Python 3.13 for release-state validation.
  • Fetches all releases, creates a draft when absent, uploads distributions with replacement enabled, and publishes only after upload.
  • Finishes an existing draft on retry while avoiding uploads to an already published release.
.github/workflows/release.yml
Added release-state and asset-integrity validation for retry scenarios.
  • Parses paginated GitHub release data and distinguishes missing, draft, published, and invalid duplicate states.
  • Validates published asset names and SHA-256 API digests, allowing regenerated Sigstore bundles with warnings.
  • Emits actionable GitHub annotations and remediation guidance for incomplete or inconsistent releases.
scripts/release_assets.py
Added comprehensive automated coverage for release discovery, digest validation, annotations, and failure handling.
  • Tests flat and paginated release responses, draft and published state transitions, duplicate-release errors, and asset upload states.
  • Covers missing, changed, unexpected, and re-signed assets with immutable and mutable remediation messages.
  • Verifies command-line output, warnings, errors, and invalid input handling.
tests/test_release_assets.py
Updated contributor guidance to document immutable-release behavior and retry requirements.
  • Explains draft-first publishing and how reruns handle drafts or validate published releases.
  • Documents the requirement to rerun failed jobs rather than rebuild all release artifacts.
docs/contributing.md

Assessment against linked issues

Issue Objective Addressed Explanation
#451 Create releases as drafts, upload distributions before publishing, and publish only as the final release action. ✅
#451 Make reruns finish an existing draft, while avoiding uploads to a release that is already published. ✅
#451 For an already-published release, verify the expected assets and their digests, and fail with actionable guidance if they do not match. ✅

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 (6eee618) to head (2ecf2e0).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #452   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         2872      2872           
=========================================
  Hits          2872      2872           
Flag Coverage Δ
test_unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@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 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<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>
**Unuploaded extras pass validation**

When a published release contains an unexpected asset whose state is not `uploaded`, `check_published` filters out assets in other states before checking for unexpected names, so the release passes validation and the workflow exits successfully despite the extra asset.

Check for unexpected asset names across all release assets before filtering by upload state.

Also at `scripts/release_assets.py:98`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and a workflow error could publish incorrect or incomplete assets under an immutable release tag, where reverting the workflow cannot replace or remove them; recovery may require issuing a new patch release. The impact is bounded to the affected release.

Blocking findings: 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
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 b4f2f5d into dev Oct 24, 2026
26 checks passed
@uniqueg
uniqueg deleted the fix/451-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