Skip to content

fix: publish releases after uploading assets - #287

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

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

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Summary

This ports elixir-cloud-aai/cloud-registry#219 to proTES, before the first release. The "Create release" step of the release workflow now:

  • creates the release explicitly as a draft, uploads the chart and its Sigstore bundle, and publishes it last (gh release edit --draft=false, with title, curated notes, --prerelease and --latest);
  • finishes a leftover draft on re-runs;
  • uploads nothing to a release that is already published. scripts/release_assets.py (new, with tests, identical to cloud-registry's) checks that the release has all assets with the same digests; only Sigstore bundles may differ, with a warning. Otherwise the step fails with an ::error:: that says what to do.
  • treats several drafts, or drafts next to a published release, as errors.

"Determine the previous release" keeps ignoring drafts (--exclude-drafts).

gh v2.102.0 (on ubuntu-latest) already creates a draft, uploads and then publishes in gh release create TAG files… (draftWhileUploading in pkg/cmd/release/create/create.go). The bug was the re-run path, which uploads to a published release. GitHub's docs: title, notes, pre-release and latest stay editable on published immutable releases.

Verification

  • pytest tests/test_release_assets.py: 23 passed; scripts/release_assets.py coverage is 100%.
  • pre-commit run on the changed files: passed. shellcheck is not installed locally; CI's actionlint runs it.
  • I ran the step's script from the workflow under bash -eo pipefail with a stub gh for each state: no release, draft, published (complete), published (no assets), and published plus a draft. Each did the expected calls or failed with the expected ::error::.
  • Not run locally: mkdocs build --strict and the full test suite (CI runs both).

Declined review findings

Reviewed in cloud-registry, as the change is identical; see that PR.

Maintainer action (not blocking)

  • Immutable releases are not enabled for proTES (GET /repos/elixir-cloud-aai/proTES/immutable-releases returns enabled: false), but are for cloud-registry and FOCA. The docs now list them among the required settings, as in cloud-registry. Please enable them before the first release (Settings, General, Releases). I did not change any settings. The workflow works either way.

Closes #280

🤖 Generated with Claude Code

Summary by Sourcery

Ensure releases are published only after their assets are uploaded while safely handling re-runs and existing release states.

Bug Fixes:

  • Prevent release workflow re-runs from uploading assets to already published releases.

Enhancements:

  • Make releases draft-first so assets are uploaded before publication, support completing leftover drafts, validate published release assets and handle ambiguous draft states safely.

Documentation:

  • Document immutable release requirements and the release workflow’s draft, asset validation, and re-run behavior.

Tests:

  • Add comprehensive tests for release state detection, asset digest validation, warnings, and workflow error conditions.

uniqueg and others added 2 commits October 24, 2026 03:25
Assets of a published immutable release can't be added, replaced or
deleted, so a re-run of the release workflow after its release was
published (e.g., by hand) would fail: `gh release upload --clobber`
gets HTTP 422, as for cloud-registry v0.3.0.

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,
with the same digests (only Sigstore bundles, which every attempt makes
anew, may differ), or the step fails and says what to do. Drafts next to
a published release, or several drafts, are errors too. The release
lookup and asset check are in `scripts/release_assets.py`, with tests,
as in cloud-registry.

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 makes release publication safe for immutable GitHub releases by explicitly creating drafts, uploading and validating chart assets before publishing, and handling reruns without modifying published assets. A standard-library validator detects ambiguous release states and asset mismatches with actionable annotations, backed by comprehensive tests and updated release documentation.

Sequence diagram for safe release publication and reruns

sequenceDiagram
    participant Workflow
    participant Validator as release_assets.py
    participant GitHub as GitHub Releases

    Workflow->>GitHub: gh api --paginate --slurp releases
    Workflow->>Validator: state TAG releases dist/*
    alt state=none
        Validator-->>Workflow: state=none
        Workflow->>GitHub: gh release create TAG --draft
        Workflow->>GitHub: gh release upload TAG dist/* --clobber
    else state=draft
        Validator-->>Workflow: state=draft
        Workflow->>GitHub: gh release upload TAG dist/* --clobber
    else state=published
        Validator->>Validator: check_published(TAG, release, assets)
        Validator-->>Workflow: state=published
    end
    Workflow->>GitHub: gh release edit TAG --draft=false --latest
Loading

Entity relationship diagram for release assets

erDiagram
    RELEASE ||--o{ ASSET : contains
    RELEASE {
        string tag_name
        boolean draft
        boolean immutable
    }
    ASSET {
        string name
        string digest
        string state
    }
Loading

Flow diagram for release state validation

flowchart TD
    A[Read releases and built assets] --> B[release_state]
    B --> C{Release state for tag?}
    C -->|none| D[Create draft]
    C -->|draft| E[Upload or replace assets]
    C -->|published| F[check_published]
    F --> G{All assets and digests match?}
    G -->|yes| H[Upload nothing]
    G -->|no| I[Fail with actionable error]
    C -->|Several drafts or draft plus published| I
    D --> J[Publish with release metadata]
    E --> J
    H --> J
Loading

File-Level Changes

Change Details Files
Reworked the release workflow to stage assets in a draft and publish only after uploads complete.
  • Enumerates releases including drafts to determine the tag's current state.
  • Creates new releases explicitly as drafts with generated or curated notes.
  • Uploads chart assets only while the release is draft, then publishes with the final title, notes, prerelease, and latest flags.
  • Finishes a single leftover draft on reruns and avoids uploads to published releases.
  • Preserves the existing previous-release lookup behavior that excludes drafts.
.github/workflows/release.yaml
Added release-state and published-asset validation for safe reruns and immutable releases.
  • Parses paginated GitHub release JSON and classifies releases as absent, draft, or published.
  • Rejects multiple drafts and combinations of published releases with remaining drafts.
  • Checks uploaded asset presence and SHA-256 digests, allowing differing Sigstore bundles with warnings.
  • Emits actionable GitHub error annotations for missing or changed assets, with remedies based on release immutability.
  • Uses only the Python standard library for workflow execution.
scripts/release_assets.py
Added comprehensive automated coverage for release discovery, validation, and command-line annotations.
  • Tests paginated and invalid release JSON parsing.
  • Covers draft completion, published releases, missing or changed assets, unsigned legacy digests, resigned bundles, and conflicting release states.
  • Verifies success output, warnings, errors, and file-read/parse failures.
tests/test_release_assets.py
Documented the draft-upload-publish lifecycle, rerun safeguards, asset validation, and repository prerequisites.
  • Explains immutable-release behavior and recovery guidance for incomplete published releases.
  • Documents the asset validation helper and its test coverage.
  • Adds immutable releases to the required repository settings.
docs/development.md

Assessment against linked issues

Issue Objective Addressed Explanation
#280 Create releases as drafts, upload assets and set release details before publishing as the final action; allow reruns to finish an existing draft. ✅
#280 On reruns for an already-published release, do not upload assets; verify expected asset names and digests, and fail with clear manual recovery steps if assets are missing or changed. Otherwise update only editable release metadata. ✅
#280 Keep previous-release lookup limited to published releases by 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

@read-the-docs-community

read-the-docs-community Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35370384 | 📁 Comparing 7d6fcca against latest (dcb644c)

  🔍 Preview build  

5 files changed · ± 5 modified

± Modified

@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 (fc39975) to head (7d6fcca).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #287   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           28        29    +1     
  Lines         2159      2244   +85     
=========================================
+ Hits          2159      2244   +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.

@uniqueg
uniqueg marked this pull request as ready for review October 24, 2026 01:31

@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 6 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="104" />
<code_context>
+    for path in assets:
+        if path.name not in uploaded:
+            missing.append(path.name)
+        elif (digest := uploaded[path.name]) and digest != sha256(path):
+            signature = path.name.endswith(SIGNATURE_SUFFIX)
+            (resigned if signature else changed).append(path.name)
</code_context>
<issue_to_address>
**Digestless assets pass validation**

When gitHub returns an expected uploaded asset with no digest, `check_published` skips the hash comparison, so `release_state` reports the release as `published` and the workflow skips uploads without verifying the asset contents.

Compare the uploaded digest with `sha256(path)` even when the digest is null, treating a missing digest as a mismatch.

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

### Comment 2
<location path=".github/workflows/release.yaml" line_range="499" />
<code_context>
           fi
-          # On reruns, complete an existing release instead of failing
-          if gh release view "${TAG}" > /dev/null 2>&1; then
-              gh release upload "${TAG}" dist/* --clobber
-              edit=(--prerelease="${PRERELEASE}" --latest="${LATEST}")
+          # All releases of the repository, drafts included, to find those of
</code_context>
<issue_to_address>
**Uploads use stale draft state**

When a maintainer publishes the draft after the API snapshot reports it as a draft but before the upload runs, the workflow uses the stale `draft` state and runs `gh release upload` against the published release; immutable releases reject the upload, while non-immutable releases have their assets changed, and a partially uploaded release remains incomplete.

Refresh the release state immediately before uploading, and validate rather than upload if the release has been published.

Also at `.github/workflows/release.yaml:500`.
</issue_to_address>

### Comment 3
<location path="scripts/release_assets.py" line_range="93-101" />
<code_context>
+        another digest); both empty if the release has all assets, with the
+        same digests. Assets without a digest (older uploads) count by name.
+    """
+    uploaded = {
+        asset.get("name"): asset.get("digest")
+        for asset in release.get("assets") or []
+        if asset.get("state") == "uploaded"
+    }
+    missing: list[str] = []
+    changed: list[str] = []
+    resigned: list[str] = []
+    for path in assets:
+        if path.name not in uploaded:
+            missing.append(path.name)
</code_context>
<issue_to_address>
**Unexpected release assets remain visible**

When a published release contains all expected assets plus an unexpected asset, `check_published` only checks local assets against the uploaded map, so it accepts the extra uploaded asset and the workflow succeeds with that asset still visible to users.

Reject uploaded asset names that are not present among the local assets.
</issue_to_address>

### Comment 4
<location path="scripts/release_assets.py" line_range="170" />
<code_context>
+            [],
+        )
+    if published:
+        errors, warnings = check_published(tag, published[0], assets)
+        return (None if errors else "published"), errors, warnings
+    if len(drafts) > 1:
</code_context>
<issue_to_address>
**Incomplete duplicate releases go unnoticed**

When the API returns multiple published releases with the same tag, `release_state` checks only `published[0]`, so another release with the same tag can have missing or mismatched assets while the workflow treats the tag as complete and skips uploads.

Check every published release returned for the tag and report an error if any has missing or mismatched assets.

Also at `.github/workflows/release.yaml:506`.
</issue_to_address>

### Comment 5
<location path=".github/workflows/release.yaml" line_range="506" />
<code_context>
-              --prerelease="${PRERELEASE}" \
-              --latest="${LATEST}"
+          # Publishes a draft
+          gh release edit "${TAG}" "${edit[@]}" --draft=false
</code_context>
<issue_to_address>
**Draft release notes become stale**

When a draft exists while a lower-version release is published before the draft is rerun, and the draft has no curated notes file, a draft created before a lower-version release is published keeps its original generated notes on rerun: the workflow only regenerates notes when state is `none`, and the final edit updates notes only when a curated notes file exists, so the published release can repeat changes already covered by the newly published prior release.

Regenerate and set generated notes when finishing a draft, using the current previous-release tag.
</issue_to_address>

### Comment 6
<location path="tests/test_release_assets.py" line_range="142" />
<code_context>
+        {"name": path.name, "digest": None, "state": "uploaded"} for path in files
+    ]
+    assert release_assets.release_state(TAG, [_release(assets=assets)], files)[0] == (
+        "published"
+    )
+
</code_context>
<issue_to_address>
**Digestless errors go unnoticed**

When `release_state` returns `published` together with unexpected errors or warnings for digestless assets, `test_state_published_without_digests` checks only the returned state, so it passes if `release_state` also returns errors or warnings for these assets. That lets the test certify a contradictory result as valid.

Assert the full expected result tuple, including empty errors and warnings.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 6 findings to address first, and if the workflow publishes the wrong chart or signature, the immutable release assets cannot be replaced or removed, and reverting only changes future runs; a new patch release can supersede it but cannot undo distribution of the original assets.

Blocking findings: scripts/release_assets.py:104, .github/workflows/release.yaml:499, scripts/release_assets.py:101, scripts/release_assets.py:170, .github/workflows/release.yaml:506, and 1 more


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

Comment thread scripts/release_assets.py Resolved
Comment thread .github/workflows/release.yaml Resolved
Comment thread scripts/release_assets.py Resolved
Comment thread scripts/release_assets.py Resolved
Comment thread .github/workflows/release.yaml Resolved
Comment thread tests/test_release_assets.py Resolved
uniqueg and others added 2 commits October 24, 2026 03:42
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 and others added 2 commits October 24, 2026 03:55
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 b674f9f into dev Oct 24, 2026
19 checks passed
@uniqueg
uniqueg deleted the fix/280-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