Repository navigation
fix: publish releases after uploading assets - #287
Conversation
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]>
Reviewer's GuideThe 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 rerunssequenceDiagram
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
Entity relationship diagram for release assetserDiagram
RELEASE ||--o{ ASSET : contains
RELEASE {
string tag_name
boolean draft
boolean immutable
}
ASSET {
string name
string digest
string state
}
Flow diagram for release state validationflowchart 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
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 #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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
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]>
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
This ports elixir-cloud-aai/cloud-registry#219 to proTES, before the first release. The "Create release" step of the release workflow now:
gh release edit --draft=false, with title, curated notes,--prereleaseand--latest);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."Determine the previous release" keeps ignoring drafts (
--exclude-drafts).gh v2.102.0 (on
ubuntu-latest) already creates a draft, uploads and then publishes ingh release create TAG files…(draftWhileUploadinginpkg/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.pycoverage is 100%.pre-commit runon the changed files: passed. shellcheck is not installed locally; CI's actionlint runs it.bash -eo pipefailwith a stubghfor 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::.mkdocs build --strictand 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)
GET /repos/elixir-cloud-aai/proTES/immutable-releasesreturnsenabled: 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:
Enhancements:
Documentation:
Tests: