← 输入框|github.com|刷新
Skip to content

fix(github): publish release as draft first to attach assets - #1479

Closed
farhan wants to merge 1 commit into
python-semantic-release:masterfrom
farhan:fix/github-immutable-release-draft-first
Closed

farhan wants to merge 1 commit into
python-semantic-release:masterfrom
farhan:fix/github-immutable-release-draft-first

Conversation

@farhan

@farhan farhan commented Aug 27, 2026 •

Copy link
Copy Markdown

What

The GitHub publish flow creates and publishes the release first, then uploads distribution assets in a separate request. GitHub's immutable releases freeze a release's assets the moment it is published, so that second upload now fails on any org with the feature enabled:

HTTPError: 422 Client Error: Unprocessable Entity
Cannot upload assets to an immutable release

The release still gets created, but with no assets, and it can never be backfilled because it is immutable. Closes #1478.

The fix

create_release now creates the release as a draft when assets are present, uploads the assets while it is still mutable, then publishes it via a new publish_release method — the sequence immutable releases require.

  • No-assets path is unchanged. With no assets there is nothing to freeze, so the release is created published directly (draft: False), as today. The extra publish round-trip only happens when assets are actually uploaded.
  • Fail-safe on upload error. If an asset upload fails, the release is left as a draft and IncompleteReleaseError is raised, so nothing is published without its assets. The leftover draft is not auto-published or cleaned up on a re-run — it stays for the user to inspect, retry, or delete.

Scoped to the GitHub HVCS; the other providers don't have this ordering.

Testing

  • test_create_release_with_assets_creates_draft_then_publishes — asserts create-as-draft, all assets uploaded, then a publish request.
  • test_create_release_leaves_draft_when_asset_upload_fails — asserts the draft is never published on upload failure.
  • All existing test_github.py tests pass unmodified, confirming the no-assets path is untouched.

pytest tests/unit/semantic_release/hvcs/test_github.py → 203 passed. ruff check and mypy clean.

Related

This overlaps with #1193 (native draft-release support) — filed separately as a breakage on immutable-release orgs rather than a convenience feature. Heads-up: the create_release rewrite in #1436 keeps the draft=False-then-upload order, so it would reintroduce this once merged.

GitHub's immutable releases feature freezes a release's assets the moment
the release is published, so the previous flow -- publish the release,
then upload distribution assets in a follow-up request -- fails with
"HTTP 422: Cannot upload assets to an immutable release" on any
organization that has immutable releases enabled.

When assets are provided, create the release as a draft, upload the
assets while it is still mutable, and only then publish it via the new
`publish_release` method. Releases without assets are still published
directly, so that common path is unchanged. If an asset upload fails,
the release is left as a draft rather than published without its assets.

Closes python-semantic-release#1478

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@farhan

farhan commented Aug 28, 2026

Copy link
Copy Markdown
Author

Closing this after a closer look at the code paths.

This change only reorders the create_release inline-assets path (the configured assets list, uploaded during the version step). But the failure in #1478 happens in the separate publish step — upload_dists → upload_release_asset, which attaches the built distributions to the release found by tag, after it has already been created and published.

In the default flow (assets config empty, distributions uploaded via the publish step) create_as_draft = bool(assets) is False, so the release is still created published and the subsequent dist upload still hits 422 Cannot upload assets to an immutable release. So this doesn't actually resolve #1478 for that setup.

A proper native fix needs the release to stay a draft across both commands — version creates it as a draft and leaves it, then the publish step uploads dists and only then publishes — which is a larger, cross-command change. Leaving the root cause tracked in #1478.

@farhan farhan closed this Aug 28, 2026
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.

GitHub publish fails with 422 on orgs with immutable releases enabled

1 participant