Skip to content

feat(release): attach assets before publication - #59

Merged
Troublor merged 3 commits into
megaeth-labs:mainfrom
RealiCZ:cz/feat/release-asset-files
Nov 23, 2026
Merged

Troublor merged 3 commits into
megaeth-labs:mainfrom
RealiCZ:cz/feat/release-asset-files

Conversation

@RealiCZ

@RealiCZ RealiCZ commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Releases in several org repositories are now immutable once published: mega-evm, stateless-validator, mega-kona, mega-reth and mega-optimism. release-assets runs from on-release.yml on release: published, which is after the Release has become immutable, so it can no longer attach anything. Two releases hit this and shipped without their binaries:

  • mega-evm v1.7.3;
  • stateless-validator v2.1.0.

Both failed with HTTP 422: Cannot upload assets to an immutable release.

This PR lets a caller attach files at publication time instead. A caller that does not use the new input behaves exactly as before.

release-publish

  • New optional input asset_files: newline-separated paths, empty by default.
  • Checked in the guard, before anything is tagged — and only for a publish that will create the Release, so a retry of a finished run stays the documented no-op whatever asset_files names. Each path must be an existing regular file, not a symlink. Basenames must be unique, SHA256SUMS is reserved, and # is refused because gh reads it as a label separator. Blank and whitespace-only lines are skipped. An asset_files that names no usable path fails, so it can never fall back to an assetless publish. The guard also writes a SHA256SUMS over the files.
  • Publishing. The publish step passes the files and SHA256SUMS to the existing gh release create. gh creates a draft, uploads the files and then publishes, so the assets are in place before the Release becomes immutable.
  • A draft left by an interrupted earlier run is deleted first, but only when this publish can prove the draft is its own: the new release_author input (default mega-gutenberg[bot], the identity the pipeline publishes as) must match the draft's author. Any other draft at the tag, or one with no author, is refused with an error and left untouched — deleting a Release cannot be undone, so someone's unpublished notes are never destroyed. Each deletion is announced with a warning. Each draft is re-read by ID right before deletion, so a published Release is never deleted; a 404 on that read is the outcome the loop wants and is skipped, while any other read failure refuses with a named error.
  • When gh release create fails, the fallback accepts only a published Release. With asset_files, that Release must also carry every expected asset and SHA256SUMS, all uploaded.
  • Without asset_files, the gh release create arguments are unchanged.

Drafts no longer count as an existing Release. This applies to:

  • the guard's "already published" check in release-publish;
  • has_published_release in release-route;
  • the release listing in release-settle.

Docs and templates

  • release-assets now says it cannot attach to an immutable Release, and points to asset_files.
  • workflow-templates/on-release.yml drops the post-publish attach example.
  • workflow-templates/release-settle.yml shows how to opt in.
  • RELEASE.md and docs/RELEASING.md describe attaching assets at publication.
  • The generated READMEs are regenerated.

Opting in. A caller adds a credential-free build job to its release-settle.yml and hands the files to publish:

build:
  needs: route
  if: needs.route.outputs.action == 'publish'
  runs-on: ubuntu-latest
  permissions:
    contents: read
  steps:
    - uses: actions/checkout@v4
      with:
        ref: ${{ needs.route.outputs.commit }}
        persist-credentials: false
    - run: ./scripts/build-release.sh
    - uses: actions/upload-artifact@v4
      with:
        name: release-files
        path: dist/my-binary
        if-no-files-found: error

publish:
  needs: [route, build]
  steps:
    # ...existing checkout and app token...
    - uses: actions/download-artifact@v4
      with:
        name: release-files
        path: release-files
    - uses: megaeth-labs/.github/.github/actions/release-publish@main
      with:
        # ...existing inputs...
        asset_files: |
          release-files/my-binary

No caller changes are needed. mega-evm will opt in in a follow-up PR; stateless-validator can do the same.

Testing

actions-test.yml

  • New cases:

    • without asset_files, the create arguments are exactly as before;
    • with asset_files, the files and a correct SHA256SUMS are passed;
    • a missing file or a duplicate basename fails before the tag step;
    • an asset_files with only blank or whitespace-only lines fails before the tag step;
    • a stranded draft is deleted, then the Release is created;
    • a draft is not "already published" for the guard;
    • drafts are not Releases for route and settle.
  • Local run. These jobs run only on GitHub, so their run: steps were executed locally with a harness, a fake gh and local Git remotes:

    • all 35 existing steps pass;
    • the 8 new steps pass;
    • the release-tools (84) and .github/scripts (86) unit tests pass;
    • action_docs.py --check and app_token_lint.py pass;
    • actionlint reports nothing beyond the one existing SC2001 style note in actions-test.yml.

    This PR's CI runs the suite on GitHub.

Live rehearsal on GitHub

Setup. The rehearsal used a public sandbox repository with immutable releases enabled: RealiCZ/release-asset-rehearsal. Its releases and observer runs are the evidence below. For example, the v0.2.0 published run shows the Release already immutable with all three assets uploaded.

  • The shell steps were extracted verbatim from this PR's commits and run with a user token. S1-S5 used the first commit; S6-S7 used the head after the review fix.
  • An observer workflow on release: [created, published] recorded, at event time, the Release's draft and immutable flags and its assets.

Results:

Scenario Result
S1: legacy publish, no asset_files. A fresh tag, plus a resume where the tag existed without a Release Pass. Published and immutable, 0 assets. One created and one published event, as today. (The first attempt hit a network TLS timeout; the step exited with an error and created nothing, and the re-run resumed cleanly.)
S2: publish with two files Pass. When the published workflow ran, the Release was already immutable, with both files and SHA256SUMS uploaded. The downloads matched the checksums.
S3: upload after publication Pass. HTTP 422: Cannot upload assets to an immutable release, the failure this PR avoids.
S4: a stranded draft holding a partial asset Pass. No workflow fired for the draft. Publishing deleted it and created one complete, immutable Release.
S5: a tag with only a draft Pass. The route, the settle listing and the guard all treat it as unpublished.
S6: S2 again, after the review fix Pass. v0.5.0: the published run saw the immutable Release with all three assets uploaded, and the downloads matched the checksums.
S7: asset_files with only blank lines, tag pushed first Pass. The guard exited 1 with asset_files is set but names no usable paths. No Release and no workflow run exist for v0.6.0.

Review fixes (commit f08e951)

A review of the first two commits raised three things, all fixed in f08e951:

  1. Blocking — the draft cleanup deleted any draft at the tag. It filtered on nothing but tag name and draft == true, with no log annotation, so a maintainer's unpublished notes at that tag were destroyed irreversibly and silently; the loop also runs on a fresh publish, so a draft written ahead of the release was in range. Now gated on release_author and announced, as described above.
  2. A 404 on the per-ID recheck aborted the publish. gh api exits 1 on 404 and the assignment is the failing command in a while body, so set -e killed the step after the tag had been pushed, with no ::error:: annotation — even though a 404 means the draft is already gone, which is what the loop wants. It now continues on 404 and surfaces gh's output with a named error otherwise, matching the releases/latest read and release-route's has_tag.
  3. The guard did asset work on an already-finished publish. The asset_files block sat above the already-published early exit, so a retry demanded the files still be on disk and failed where the README promises exit 0 with a notice. It is now conditioned on $published like the order check and the dispatch changelog check.

New cases in actions-test.yml: a foreign draft and an unattributable draft are both refused with nothing deleted and the draft intact; its own draft is deleted, announced and published; a draft that 404s between the listing and the read does not stop the publish, while a 500 refuses with a named error; a finished publish stays a no-op with asset_files naming paths that do not exist. The fake gh gained author fields and a configurable per-ID 404/500.

One review item is left open rather than fixed: GitHub's REST docs say it "renames asset filenames that have special characters, non-alphanumeric characters, and leading or trailing periods", without saying what the substitution is. SHA256SUMS, the asset-name list and the uniqueness check all key on the local basename, and the test fixture is dist/my tool. If a space is renamed, the manifest no longer matches the published asset names and cannot be corrected, because it now lands behind the immutability boundary. Settling this needs one upload to a throwaway release to read back .assets[].name; if it renames, the fix is to refuse non-[A-Za-z0-9._-] basenames in the guard and rename the fixture.

Notes and known limits

  • Events. The asset path fires only release: published, with no created, because the Release starts as a draft. No workflow in the org listens for release: created (code search).
  • Listing lag. The releases listing can lag a just-created draft. An immediate retry after an interrupted asset publish may therefore leave one extra draft. That draft is harmless: publication completes, and route and settle ignore drafts. This case was not rehearsed.
  • Existing drafts. Of the eight repositories that call release-publish, only mega-optimism has a draft: a v2.0.0 draft from 2025-11-10, whose tag also exists.
    • After this change, route no longer counts that draft as a published v2.0.0.
    • In practice nothing changes: the version-order check refuses any version that is not newer than v2.0.14, and only a push to release-v2.0.0 or a dispatch for 2.0.0 would reach that check.
  • Overlap with docs: align release guides with shipped settlement flow #58. This PR overlaps docs: align release guides with shipped settlement flow #58 in RELEASE.md, docs/RELEASING.md and release-publish/README.md. The edits here are small and additive; whichever PR lands second rebases.

Reject blank asset lists before creating a tag. Test both empty and whitespace-only lines.
The stranded-draft cleanup added for `asset_files` listed every draft at the
release tag and deleted it, with no check of where it came from and no log
annotation. A maintainer's unpublished notes at that tag were destroyed
irreversibly and silently, and the loop runs on a fresh publish too, so a
draft written ahead of the release was in range. Deleting a Release cannot be
undone, so the cleanup now has to prove the draft is its own.

- New optional `release_author` input, defaulting to the app identity the
  pipeline publishes as. A draft at the tag is replaced only when `gh` created
  it as that identity; any other draft, or one with no author, is refused with
  an error and left untouched. Empty refuses every pre-existing draft.
- Each deletion is announced with a warning, so it is never silent.
- A 404 on the per-ID recheck is the outcome the loop wants, not a failure:
  continue instead of letting `set -e` abort the step after the tag is pushed.
  Any other read failure surfaces `gh`'s output and a named error, matching how
  the `releases/latest` read and `release-route`'s `has_tag` already behave.
- The guard's asset checks and `SHA256SUMS` only run for a publish that will
  create the Release, so a retry of a finished run stays the documented no-op
  whatever `asset_files` names, instead of demanding the files still be on disk.

Tests: a foreign draft and an unattributable draft are both refused with
nothing deleted and the draft intact; its own draft is deleted, announced and
published; a draft that 404s between the listing and the read does not stop the
publish, while a 500 refuses with a named error; a finished publish stays a
no-op with `asset_files` naming paths that do not exist.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Troublor
Troublor merged commit 87b6847 into megaeth-labs:main Nov 23, 2026
14 checks passed
@RealiCZ
RealiCZ deleted the cz/feat/release-asset-files branch November 23, 2026 03:07
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.

3 participants