From a09b1c0ec6154d9703da3c03c2fc1b07d89a6f2f Mon Sep 17 00:00:00 2001 From: RealiCZ Date: Fri, 20 Nov 2026 17:42:36 +0800 Subject: [PATCH 1/3] feat(release): attach assets before publication --- .github/actions/README.md | 4 +- .github/actions/RELEASE.md | 23 ++- .github/actions/release-assets/README.md | 2 +- .github/actions/release-assets/action.yml | 4 +- .github/actions/release-publish/README.md | 21 ++- .github/actions/release-publish/action.yml | 77 +++++++- .github/actions/release-route/action.yml | 10 +- .github/actions/release-settle/action.yml | 2 +- .github/workflows/actions-test.yml | 193 ++++++++++++++++++++- docs/RELEASING.md | 12 +- workflow-templates/on-release.yml | 25 +-- workflow-templates/release-settle.yml | 5 + 12 files changed, 324 insertions(+), 54 deletions(-) diff --git a/.github/actions/README.md b/.github/actions/README.md index d97c5b2..f1f8623 100644 --- a/.github/actions/README.md +++ b/.github/actions/README.md @@ -20,9 +20,9 @@ a README whose input, output, step and error tables are generated from its | [`merge-queue-skipper`](merge-queue-skipper/README.md) | Standalone | Decide whether a merge-queue run may skip checks that already passed on the pull request. GitHub always re-runs required checks on the temporary merge branch; this outputs `skip-check: true` only when that branch's tree is provably the one the PR's own checks covered: the entry was enqueued at the head of the target branch, the PR branch still contains that commit, and the PR branch and the queue branch have no diff. Any other situation — not a merge-queue ref, a queue entry behind another, a PR updated after enqueueing — yields `false`. The caller gates its expensive jobs on the output. Needs the repository history: the action checks it out itself (`fetch-depth: 0`) unless `checkout: false`, in which case the caller must already have a full checkout with `origin` remote. | | [`notify-lark`](notify-lark/README.md) | Standalone | Post a message to a Lark (Feishu) group through a custom-bot webhook. The default is a plain text message; `msg_type: post` sends rich text with a title, and `payload` sends any JSON you built yourself (interactive cards, mentions), untouched. If the bot has signature verification enabled, pass its signing `secret` and the request is signed with the documented timestamp + HMAC-SHA256 scheme. The webhook URL and secret go through the environment and are masked. A non-2xx response or a Lark error code fails the step unless `fail_on_error` is `false`; the response body is an output either way. Nothing is organisation-specific: the webhook is an input. | | [`pr-lint`](pr-lint/README.md) | Standalone | Lint a pull request. Currently validates that the PR title follows Conventional Commits, posting a sticky comment on failure and removing it once fixed; further PR-level lint steps can be added here over time. Run as a step inside a job the consumer names, so the resulting status-check context is that job name. | -| [`release-assets`](release-assets/README.md) | [Release pipeline](RELEASE.md) | Attach files, plus a generated `SHA256SUMS`, to the GitHub Release for a tag. Re-runs replace assets of the same name (`--clobber`), so the step is idempotent. `dry_run` writes and prints `SHA256SUMS` but attaches nothing. Needs a token with `contents: write` on the repository (the job token is enough). Guide: .github/actions/RELEASE.md in megaeth-labs/.github. | +| [`release-assets`](release-assets/README.md) | [Release pipeline](RELEASE.md) | Attach files, plus a generated `SHA256SUMS`, to the GitHub Release for a tag. Re-runs replace assets of the same name (`--clobber`), so the step is idempotent. `dry_run` writes and prints `SHA256SUMS` but attaches nothing. Needs a token with `contents: write` on the repository (the job token is enough). This post-publish action cannot attach files to an immutable Release. Use `release-publish` with `asset_files` to attach them before publication. Guide: .github/actions/RELEASE.md in megaeth-labs/.github. | | [`release-candidate`](release-candidate/README.md) | [Release pipeline](RELEASE.md) | Start a release (trunk-first). `stage: propose` bumps the version file on the default branch, drafts this release's undated changelog entry from the commits since the previous tag, syncs the previous release's entry from its tag, and opens a `chore/release-candidate-X.Y.Z` PR. `stage: refresh` merges an open candidate PR's own base into its head and re-drafts the changelog without rewriting history; any push requires renewed approval. `stage: cut`, run on the push that merged that PR (the consumer passes the `commit` and `pr_number` outputs of `release-route`), re-reads the PR through the API, refuses anything but a merged, gutenberg-authored candidate into the default branch, and creates `release-vX.Y.Z` at the merge commit (a retry that finds it already there is a no-op; at any other commit it refuses). No tag is created at any stage — tags come from release-publish, once, at settlement. `base_commit` releases a commit that is not the tip of the default branch: `propose` cuts the release branch there itself, carries the default branch's release workflows onto it, and points the candidate PR at it; that PR merges into the release branch, so `cut` never runs for it. Run as a step in a job the consumer owns; the organization-level `MEGA_GUTENBERG_CLIENT_ID` and `MEGA_GUTENBERG_PK` provide the app credentials. The one-reviewer `release` environment gates only tagging, Release creation and artifact upload. The consumer checks the repository out first (`fetch-depth: 0`, `persist-credentials: false`). Guide: .github/actions/RELEASE.md in megaeth-labs/.github. | -| [`release-publish`](release-publish/README.md) | [Release pipeline](RELEASE.md) | Publish a settled release. By default, runs on a push to `release-vX.Y.Z` (the consumer passes the `commit` and `pr_number` that `release-route` resolved for the push). Re-verifies the merged `chore/release-settle-vX.Y.Z` PR through the API — merged, merge commit equals the pushed commit, head/base names, author, and the settled-SHA marker against the merge commit's parent. With `settle_source: dispatch`, verifies the merged candidate PR's merge SHA, head, base and author, and that `release_branch` still points at `commit` for a fresh publish, or contains `commit` when resuming an existing tag; repeats this state check immediately before tagging. Then creates the annotated tag `vX.Y.Z` at that commit and publishes the GitHub Release with the changelog section as notes. A tag already at the commit without a Release (a run that died between the two steps) is resumed: the tag step is skipped and the Release is still created. Re-run the push-triggered workflow for the settle-PR shape, or dispatch for the direct shape. A tag at the commit with its Release already there is a retry of a finished run and exits 0 with a notice; a tag at any other commit refuses, because a release is published once. A version that is not newer than every other `vX.Y.Z` tag (the rule `release-route` applies) is refused before the tag, and the Release is marked latest only when it is newer than the current latest Release. A tag push or Release create that loses a race to a concurrent run of the same publish keeps the winner's, if it is at this commit. This is the only place in the release flow that creates a tag; merging the settle PR is the approval. The default branch's changelog catches up in the next release candidate PR — nothing is back-merged. The consumer checks the repository out first (`fetch-depth: 0`, `persist-credentials: false`). Guide: .github/actions/RELEASE.md in megaeth-labs/.github. | +| [`release-publish`](release-publish/README.md) | [Release pipeline](RELEASE.md) | Publish a settled release. By default, runs on a push to `release-vX.Y.Z` (the consumer passes the `commit` and `pr_number` that `release-route` resolved for the push). Re-verifies the merged `chore/release-settle-vX.Y.Z` PR through the API — merged, merge commit equals the pushed commit, head/base names, author, and the settled-SHA marker against the merge commit's parent. With `settle_source: dispatch`, verifies the merged candidate PR's merge SHA, head, base and author, and that `release_branch` still points at `commit` for a fresh publish, or contains `commit` when resuming an existing tag; repeats this state check immediately before tagging. Then creates the annotated tag `vX.Y.Z` at that commit and publishes the GitHub Release with the changelog section as notes. Pass `asset_files` to attach files and `SHA256SUMS` before the Release becomes immutable. A tag already at the commit without a published Release (a run that died between the two steps) is resumed: the tag step is skipped and the Release is still created. Re-run the push-triggered workflow for the settle-PR shape, or dispatch for the direct shape. A tag at the commit with its Release already there is a retry of a finished run and exits 0 with a notice; a tag at any other commit refuses, because a release is published once. A version that is not newer than every other `vX.Y.Z` tag (the rule `release-route` applies) is refused before the tag, and the Release is marked latest only when it is newer than the current latest Release. A tag push or Release create that loses a race to a concurrent run of the same publish keeps the winner's, if it is at this commit. This is the only place in the release flow that creates a tag; merging the settle PR is the approval. The default branch's changelog catches up in the next release candidate PR — nothing is back-merged. The consumer checks the repository out first (`fetch-depth: 0`, `persist-credentials: false`). Guide: .github/actions/RELEASE.md in megaeth-labs/.github. | | [`release-publish-rust-crates`](release-publish-rust-crates/README.md) | [Release pipeline](RELEASE.md) | Publish an explicit list of workspace crates to crates.io at the release version. Verifies every listed crate's manifest version first, skips crates already published at that version (so a re-run after a partial failure finishes the rest), publishes the remainder in one `cargo publish -p … -p …` invocation — Cargo orders by dependency and waits for the index between crates (requires Cargo ≥ 1.90) — then polls crates.io until every crate reports the version. `dry_run` runs `cargo publish --dry-run`: full packaging and build verification, nothing uploaded. Run inside a job that has checked out the release tag and installed the toolchain the crates need. Never use `--workspace`: a crate without `publish = false` that was never meant to be published would go out with it. Guide: .github/actions/RELEASE.md in megaeth-labs/.github. | | [`release-route`](release-route/README.md) | [Release pipeline](RELEASE.md) | Route a push or manual dispatch to cut, refresh, publish or skip using merged release PR metadata. Read-only; uses the job token, not a release App secret. Requires a checkout with full history and persist-credentials disabled. | | [`release-settle`](release-settle/README.md) | [Release pipeline](RELEASE.md) | Maintain a settle PR for a release candidate: verify `commit` is the tip of the release branch and carries the expected version, generate release notes from the commits since the previous tag, write them into the changelog under the candidate's undated `## vX.Y.Z` heading, and open or refresh a `chore/release-settle-vX.Y.Z` PR onto the release branch without rewriting its history. New commits on the release branch refresh this PR automatically; merging it is the settlement decision and release-publish then tags the merge commit once. Run as a step in a job the consumer owns; consumer checks the repository out first (`fetch-depth: 0`, `persist-credentials: false`). Needs `gh` and `python3` on the runner. Guide: .github/actions/RELEASE.md in megaeth-labs/.github. | diff --git a/.github/actions/RELEASE.md b/.github/actions/RELEASE.md index b9e7700..81101b8 100644 --- a/.github/actions/RELEASE.md +++ b/.github/actions/RELEASE.md @@ -38,8 +38,8 @@ job log. |---|---|---| | **Candidate** | a maintainer dispatches `release-candidate.yml` with a version | a PR on the default branch that bumps the version and drafts the changelog entry; merging it creates `release-vX.Y.Z` at the merge commit | | **Settle** | a push to `release-vX.Y.Z`: the branch being cut, and every later push to it | `route` answers `refresh`, and `release-settle` opens or updates one reviewed `chore/release-settle-vX.Y.Z` PR onto the release branch, carrying the changelog entry for the commits since the previous tag | -| **Publish** | the settle PR merging, or a dispatch of `release-settle.yml` with a version whose branch needs no settle PR | `release-publish` creates the annotated tag `vX.Y.Z` at the settled commit and publishes the GitHub Release with the changelog section as notes | -| **Publish targets** | the GitHub Release being published | whatever the repository ships: crates to crates.io, binaries to the artifact registry, downloads on the Release page, composed in `on-release.yml` from the publish-target actions | +| **Publish** | the settle PR merging, or a dispatch of `release-settle.yml` with a version whose branch needs no settle PR | `release-publish` creates the annotated tag `vX.Y.Z` at the settled commit and publishes the GitHub Release with the changelog section as notes and any `asset_files` as downloads | +| **Publish targets** | the GitHub Release being published | whatever the repository ships, such as crates to crates.io and binaries to the artifact registry, composed in `on-release.yml` from the publish-target actions | The choices that shape it: @@ -189,6 +189,12 @@ notes, marked latest only when it is newer than the current latest Release. A version that is not newer than every other `vX.Y.Z` tag is refused before the tag, so an older line merged late is never tagged or made latest. +For GitHub Release downloads, add a credential-free build job that checks out +`needs.route.outputs.commit` and uploads the binaries as a workflow artifact. +Download the artifact in the publish job and list its paths in +`release-publish`'s `asset_files`. The action attaches the files and a +`SHA256SUMS` manifest before publishing, when the Release can still take assets. + **5. Publish targets.** The Release's `published` event starts `on-release.yml`, which builds and publishes whatever the repository ships. Each target is a job; `dry_run` is off on a real release. See @@ -384,6 +390,9 @@ release workflow (rule L4). ## Publish targets (`on-release.yml`) +Immutable GitHub Releases cannot accept assets after publication. Use +`release-publish`'s `asset_files` for downloads on the Release page. + The Release's `published` event runs the repository's `on-release.yml`. What every one of them carries, and why (the template has all of it): @@ -399,8 +408,7 @@ every one of them carries, and why (the template has all of it): `2>/dev/null || echo …`: that turns a binary that cannot load into a green step and a published download. - One build feeding every target when several targets ship the same file - (a workflow artifact between jobs), so the Release page and the registry - carry the same bytes. + (a workflow artifact between jobs), so the targets carry the same bytes. - `dry_run` threaded from a `workflow_dispatch` input (default true there) into every target, so the whole workflow can be rehearsed on a tag ref: `gh workflow run on-release.yml --ref vX.Y.Z -f dry_run=true`. A run @@ -410,9 +418,8 @@ A `release` event resolves the workflow from the tagged commit's tree, so the file must exist at the tag. A release branch cut from a default branch that has it carries it; a branch cut before it landed needs it cherry-picked (through its own PR, the `release-*` ruleset requires one) before the settle -PR is merged, or the Release publishes with nothing attached and no failed -run. Settle warns when the settled commit lacks a workflow the default -branch has. +PR is merged, or the target jobs will not run. Settle warns when the settled +commit lacks a workflow the default branch has. The targets: @@ -420,7 +427,7 @@ The targets: |---|---|---|---| | `release-publish-rust-crates` | an explicit crate list to crates.io at the release version: one `cargo publish -p … -p …` (Cargo ≥ 1.90 orders and waits); polls the index afterwards. Every crate's manifest must already be at the version. Never `--workspace`: list the crates. | crates already at the version are skipped | `cargo publish --dry-run` for every listed crate, nothing uploaded | | `release-upload-artifact` | one file to Artifact Registry (generic repository) or a GCS bucket; every destination is an input. Authentication is the caller's: run `google-github-actions/auth` before it. | identical file already there → `exists`; different → fails, never overwrites | checksum and destination check only | -| `release-assets` | files plus a generated `SHA256SUMS` on the GitHub Release; needs the job token with `contents: write` | `--clobber` | prints the sums, attaches nothing | +| `release-assets` | files plus a generated `SHA256SUMS` on a mutable Release; needs the job token with `contents: write` | `--clobber` | prints the sums, attaches nothing | | `release-verify-version` | nothing: runs a version probe (`my-binary --version`) and requires ` ` (`expected` overrides, with `{name}` and `{version}`) | n/a | a mismatch warns; a probe that cannot run fails even here | ## Snapshots (`snapshot-publish.yml`) diff --git a/.github/actions/release-assets/README.md b/.github/actions/release-assets/README.md index d21f5f3..7029343 100644 --- a/.github/actions/release-assets/README.md +++ b/.github/actions/release-assets/README.md @@ -3,7 +3,7 @@ `uses: megaeth-labs/.github/.github/actions/release-assets@main` -Attach files, plus a generated `SHA256SUMS`, to the GitHub Release for a tag. Re-runs replace assets of the same name (`--clobber`), so the step is idempotent. `dry_run` writes and prints `SHA256SUMS` but attaches nothing. Needs a token with `contents: write` on the repository (the job token is enough). Guide: .github/actions/RELEASE.md in megaeth-labs/.github. +Attach files, plus a generated `SHA256SUMS`, to the GitHub Release for a tag. Re-runs replace assets of the same name (`--clobber`), so the step is idempotent. `dry_run` writes and prints `SHA256SUMS` but attaches nothing. Needs a token with `contents: write` on the repository (the job token is enough). This post-publish action cannot attach files to an immutable Release. Use `release-publish` with `asset_files` to attach them before publication. Guide: .github/actions/RELEASE.md in megaeth-labs/.github. Family: [Release pipeline](../RELEASE.md). diff --git a/.github/actions/release-assets/action.yml b/.github/actions/release-assets/action.yml index 8ad2c36..1eca552 100644 --- a/.github/actions/release-assets/action.yml +++ b/.github/actions/release-assets/action.yml @@ -4,7 +4,9 @@ description: >- tag. Re-runs replace assets of the same name (`--clobber`), so the step is idempotent. `dry_run` writes and prints `SHA256SUMS` but attaches nothing. Needs a token with `contents: write` on the repository (the job token is - enough). + enough). This post-publish action cannot attach files to an immutable + Release. Use `release-publish` with `asset_files` to attach them before + publication. Guide: .github/actions/RELEASE.md in megaeth-labs/.github. inputs: diff --git a/.github/actions/release-publish/README.md b/.github/actions/release-publish/README.md index 51306f5..b54f309 100644 --- a/.github/actions/release-publish/README.md +++ b/.github/actions/release-publish/README.md @@ -3,7 +3,7 @@ `uses: megaeth-labs/.github/.github/actions/release-publish@main` -Publish a settled release. By default, runs on a push to `release-vX.Y.Z` (the consumer passes the `commit` and `pr_number` that `release-route` resolved for the push). Re-verifies the merged `chore/release-settle-vX.Y.Z` PR through the API — merged, merge commit equals the pushed commit, head/base names, author, and the settled-SHA marker against the merge commit's parent. With `settle_source: dispatch`, verifies the merged candidate PR's merge SHA, head, base and author, and that `release_branch` still points at `commit` for a fresh publish, or contains `commit` when resuming an existing tag; repeats this state check immediately before tagging. Then creates the annotated tag `vX.Y.Z` at that commit and publishes the GitHub Release with the changelog section as notes. A tag already at the commit without a Release (a run that died between the two steps) is resumed: the tag step is skipped and the Release is still created. Re-run the push-triggered workflow for the settle-PR shape, or dispatch for the direct shape. A tag at the commit with its Release already there is a retry of a finished run and exits 0 with a notice; a tag at any other commit refuses, because a release is published once. A version that is not newer than every other `vX.Y.Z` tag (the rule `release-route` applies) is refused before the tag, and the Release is marked latest only when it is newer than the current latest Release. A tag push or Release create that loses a race to a concurrent run of the same publish keeps the winner's, if it is at this commit. This is the only place in the release flow that creates a tag; merging the settle PR is the approval. The default branch's changelog catches up in the next release candidate PR — nothing is back-merged. The consumer checks the repository out first (`fetch-depth: 0`, `persist-credentials: false`). Guide: .github/actions/RELEASE.md in megaeth-labs/.github. +Publish a settled release. By default, runs on a push to `release-vX.Y.Z` (the consumer passes the `commit` and `pr_number` that `release-route` resolved for the push). Re-verifies the merged `chore/release-settle-vX.Y.Z` PR through the API — merged, merge commit equals the pushed commit, head/base names, author, and the settled-SHA marker against the merge commit's parent. With `settle_source: dispatch`, verifies the merged candidate PR's merge SHA, head, base and author, and that `release_branch` still points at `commit` for a fresh publish, or contains `commit` when resuming an existing tag; repeats this state check immediately before tagging. Then creates the annotated tag `vX.Y.Z` at that commit and publishes the GitHub Release with the changelog section as notes. Pass `asset_files` to attach files and `SHA256SUMS` before the Release becomes immutable. A tag already at the commit without a published Release (a run that died between the two steps) is resumed: the tag step is skipped and the Release is still created. Re-run the push-triggered workflow for the settle-PR shape, or dispatch for the direct shape. A tag at the commit with its Release already there is a retry of a finished run and exits 0 with a notice; a tag at any other commit refuses, because a release is published once. A version that is not newer than every other `vX.Y.Z` tag (the rule `release-route` applies) is refused before the tag, and the Release is marked latest only when it is newer than the current latest Release. A tag push or Release create that loses a race to a concurrent run of the same publish keeps the winner's, if it is at this commit. This is the only place in the release flow that creates a tag; merging the settle PR is the approval. The default branch's changelog catches up in the next release candidate PR — nothing is back-merged. The consumer checks the repository out first (`fetch-depth: 0`, `persist-credentials: false`). Guide: .github/actions/RELEASE.md in megaeth-labs/.github. Family: [Release pipeline](../RELEASE.md). @@ -22,6 +22,7 @@ Family: [Release pipeline](../RELEASE.md). | `release_branch` | no | | Release branch that must equal X.Y.Z; for dispatch its tip must equal commit for a fresh publish, or contain commit when resuming an existing tag. | | `commit` | yes | | The commit to publish (full SHA); it must be the settle PR's merge commit for pr, or the candidate PR's merge commit for dispatch. | | `pr_number` | yes | | Number of the merged settle PR for pr, or the merged candidate PR for dispatch. | +| `asset_files` | no | | Newline-separated regular file paths, absolute or relative to the workspace. Use unique basenames and reserve SHA256SUMS for the generated checksum file. Paths cannot contain `#`, which GitHub CLI treats as an asset label separator. | | `pr_author` | no | `mega-gutenberg[bot]` | Login the settle or candidate PR must have been opened by — the app identity `release-settle` runs under. Stops a hand-made `chore/release-settle-*` branch from reaching the tag step. Empty disables the check only for pr. | | `git_user_name` | no | `mega-gutenberg[bot]` | Committer identity for the commits this action makes. | | `git_user_email` | no | `348780249+mega-gutenberg[bot]@users.noreply.github.com` | Committer email for the commits this action makes. | @@ -70,9 +71,13 @@ Family: [Release pipeline](../RELEASE.md). - `tag $tag already exists (at $(git rev-parse` - `$FILE at $MERGE_SHA says $actual, expected $version` - `changelog section for v$version at $MERGE_SHA disagrees with regenerated notes; let the settle refresh land first, then publish.` +- `release asset must be an existing regular file and not a symlink: $file` +- `release asset basename is reserved or duplicated: $name` +- `release asset path cannot contain GitHub CLI` - `could not push $TAG; the remote tag is at $(git rev-parse` - `cannot read the latest Release to decide whether $TAG is the latest; re-run to resume` - `could not create the Release for $TAG` +- `published Release $TAG is missing asset: $name` ## Example @@ -117,11 +122,15 @@ ancestry rule. `commit` in dispatch mode; then publishes the GitHub Release with the changelog section as notes, marked latest only when it is newer than the current latest Release. -- If the tag exists at `commit` but its Release does not, both sources skip - tagging and resume Release creation after their verification passes. Resume - the settle-PR shape by re-running the push-triggered workflow; resume the - direct shape by dispatching again with the same inputs. A tag elsewhere is - always refused; a tag at `commit` with a Release already present is a no-op. +- If the tag exists at `commit` and there is no published Release, both + sources skip tagging and resume Release creation once verification passes. + Re-run the push-triggered workflow for the settle-PR shape or dispatch again + with the same inputs for the direct shape. A tag elsewhere is refused. + A tag at `commit` with a published Release is a no-op. +- With `asset_files`, the guard checks the files and generates `SHA256SUMS` + before tagging. The publish step replaces stranded drafts for the tag and + uploads the files before publication. Keep the publish job in the template's + per-release-branch concurrency group when using this input. - The Release body is the changelog section extracted from the tagged tree, verbatim, with no injected date. With an empty `changelog_file`, notes are generated from non-merge commits since the previous release tag (or all diff --git a/.github/actions/release-publish/action.yml b/.github/actions/release-publish/action.yml index 7c23e97..bafa054 100644 --- a/.github/actions/release-publish/action.yml +++ b/.github/actions/release-publish/action.yml @@ -10,8 +10,9 @@ description: >- for a fresh publish, or contains `commit` when resuming an existing tag; repeats this state check immediately before tagging. Then creates the annotated tag `vX.Y.Z` at that commit and publishes the GitHub Release - with the changelog section as notes. A tag already at the commit without a - Release (a run that died between the two steps) is resumed: the tag step is + with the changelog section as notes. Pass `asset_files` to attach files and + `SHA256SUMS` before the Release becomes immutable. A tag already at the commit + without a published Release (a run that died between the two steps) is resumed: the tag step is skipped and the Release is still created. Re-run the push-triggered workflow for the settle-PR shape, or dispatch for the direct shape. A tag at the commit with its Release already there is a retry of a finished run and exits 0 with a @@ -65,6 +66,13 @@ inputs: pr_number: description: "Number of the merged settle PR for pr, or the merged candidate PR for dispatch." required: true + asset_files: + description: >- + Newline-separated regular file paths, absolute or relative to the workspace. + Use unique basenames and reserve SHA256SUMS for the generated checksum file. + Paths cannot contain `#`, which GitHub CLI treats as an asset label separator. + required: false + default: "" pr_author: description: >- Login the settle or candidate PR must have been opened by — the app identity @@ -120,6 +128,7 @@ runs: FILE: ${{ inputs.version_file }} PATTERN: ${{ inputs.version_pattern }} CHANGELOG: ${{ inputs.changelog_file }} + ASSET_FILES: ${{ inputs.asset_files }} TOOLS: ${{ github.action_path }}/../release-tools/release_tools.py run: | "$AUTH_WRAPPER" bash --noprofile --norc -e -o pipefail <<'GITHUB_AUTH_COMMAND' @@ -242,7 +251,8 @@ runs: echo "::error::tag $tag already exists (at $(git rev-parse "$tag^{commit}")), not at $MERGE_SHA; a release is published once"; exit 1 fi tag_exists=true - if release_url="$(gh release view "$tag" --json url -q .url 2>/dev/null)"; then + if release_url="$(gh release view "$tag" --json url,isDraft -q 'select(.isDraft == false) | .url' 2>/dev/null)" && + [[ -n "$release_url" ]]; then published=true else release_url="" @@ -301,6 +311,30 @@ runs: echo "::error::changelog section for v$version at $MERGE_SHA disagrees with regenerated notes; let the settle refresh land first, then publish."; exit 1 fi fi + if [[ -n "${ASSET_FILES:-}" ]]; then + asset_dir="$(mktemp -d "$RUNNER_TEMP/release-publish-assets.XXXXXXXX")" + touch "$asset_dir/files" "$asset_dir/names" "$asset_dir/SHA256SUMS" + while IFS= read -r file; do + [[ -n "$file" ]] || continue + [[ "$file" == /* ]] || file="$GITHUB_WORKSPACE/$file" + if [[ ! -f "$file" || -L "$file" ]]; then + echo "::error::release asset must be an existing regular file and not a symlink: $file"; exit 1 + fi + name="${file##*/}" + if [[ "$name" == SHA256SUMS ]] || grep -qxF -- "$name" "$asset_dir/names"; then + echo "::error::release asset basename is reserved or duplicated: $name"; exit 1 + fi + if [[ "$file" == *'#'* ]]; then + echo "::error::release asset path cannot contain GitHub CLI's label separator (#): $file"; exit 1 + fi + printf '%s\n' "$name" >> "$asset_dir/names" + printf '%s\n' "$file" >> "$asset_dir/files" + (cd "${file%/*}/" && sha256sum -- "./$name") | sed 's/ \.\// /' >> "$asset_dir/SHA256SUMS" + done <<< "$ASSET_FILES" + if [[ -s "$asset_dir/files" ]]; then + echo "asset_dir=$asset_dir" >> "$GITHUB_OUTPUT" + fi + fi { echo "version=$version" echo "tag=$tag" @@ -374,6 +408,7 @@ runs: TAG: ${{ steps.guard.outputs.tag }} NOTES: ${{ steps.guard.outputs.notes_file }} TOOLS: ${{ github.action_path }}/../release-tools/release_tools.py + ASSET_DIR: ${{ steps.guard.outputs.asset_dir }} run: | set -euo pipefail # Mark the Release latest only if it is newer than the Release GitHub @@ -395,10 +430,42 @@ runs: latest_flag=--latest=false echo "::warning title=Not the latest Release::$TAG is published without becoming latest: $refusal (rule: latest only when newer than the latest Release)" fi - if ! url="$(gh release create "$TAG" --verify-tag "$latest_flag" --title "$TAG" --notes-file "$NOTES")"; then + set -- + fields=url,isDraft + if [[ -n "${ASSET_DIR:-}" ]]; then + fields+=,assets + while IFS= read -r file; do + # An empty label tells gh to use the literal path without globbing. + case "$file" in + *['*?[\']*) set -- "$@" "$file#" ;; + *) set -- "$@" "$file" ;; + esac + done < "$ASSET_DIR/files" + set -- "$@" "$ASSET_DIR/SHA256SUMS" + releases="repos/$GITHUB_REPOSITORY/releases" + drafts="$(gh api --paginate "$releases" --jq ".[] | select(.tag_name == \"$TAG\" and .draft == true) | .id")" + while IFS= read -r id; do + [[ -n "$id" ]] || continue + # The publish job serializes each release branch. Recheck by ID + # immediately before deleting so a published Release is skipped. + draft="$(gh api "$releases/$id" --jq .draft)" + if [[ "$draft" == true ]]; then + gh api --method DELETE "$releases/$id" + fi + done <<< "$drafts" + fi + if ! url="$(gh release create "$TAG" --verify-tag "$latest_flag" --title "$TAG" --notes-file "$NOTES" "$@")"; then # A concurrent publish created it first; that Release is this one. - url="$(gh release view "$TAG" --json url -q .url)" \ + view="$(gh release view "$TAG" --json "$fields")" && + url="$(jq -er 'select(.isDraft == false) | .url // empty' <<< "$view")" \ || { echo "::error::could not create the Release for $TAG"; exit 1; } + if [[ -n "${ASSET_DIR:-}" ]]; then + while IFS= read -r name; do + if ! jq -e --arg name "$name" 'any(.assets[]; .name == $name and .state == "uploaded")' <<< "$view" > /dev/null; then + echo "::error::published Release $TAG is missing asset: $name"; exit 1 + fi + done < <(cat "$ASSET_DIR/names"; printf '%s\n' SHA256SUMS) + fi echo "::notice::the Release for $TAG was created by a concurrent run; keeping it" fi echo "url=$url" >> "$GITHUB_OUTPUT" diff --git a/.github/actions/release-route/action.yml b/.github/actions/release-route/action.yml index e1b28f3..ef8efc3 100644 --- a/.github/actions/release-route/action.yml +++ b/.github/actions/release-route/action.yml @@ -99,6 +99,12 @@ runs: return 1 fi } + has_published_release() { + local published_tag + published_tag="$(gh release view "$1" --json tagName,isDraft \ + --jq 'select(.isDraft == false) | .tagName' 2>/dev/null)" && + [[ "$published_tag" == "$1" ]] + } # Sets $actual to the version at . A version file that is # missing or does not parse is a configuration error, not a candidate # that has not landed yet, so it fails the route instead of skipping. @@ -129,7 +135,7 @@ runs: if [[ -z "$tag_commit" ]]; then tag_commit="$(git ls-remote origin "refs/tags/$tag" | cut -f1)" fi - if gh release view "$tag" --json tagName >/dev/null 2>&1; then release_exists=true; fi + if has_published_release "$tag"; then release_exists=true; fi fi if [[ "$release_exists" == false ]]; then read_version "$GITHUB_SHA" "$GITHUB_REF_NAME" @@ -156,7 +162,7 @@ runs: tagged=false; branch_release_exists=false; actual="" if has_tag "v$version"; then tagged=true - if gh release view "v$version" --json tagName >/dev/null 2>&1; then branch_release_exists=true; fi + if has_published_release "v$version"; then branch_release_exists=true; fi else read_version "$tip" "$branch" fi diff --git a/.github/actions/release-settle/action.yml b/.github/actions/release-settle/action.yml index dc87ceb..0fd7da5 100644 --- a/.github/actions/release-settle/action.yml +++ b/.github/actions/release-settle/action.yml @@ -207,7 +207,7 @@ runs: fi release_exists=false releases="$(gh api --paginate "repos/$GITHUB_REPOSITORY/releases" --jq \ - ".[] | select(.tag_name == \"v$VERSION\") | .id")" + ".[] | select(.tag_name == \"v$VERSION\" and .draft == false) | .id")" [[ -z "$releases" ]] || release_exists=true section_matches=true if [[ -n "$CHANGELOG" ]]; then diff --git a/.github/workflows/actions-test.yml b/.github/workflows/actions-test.yml index 411796a..d05f20b 100644 --- a/.github/workflows/actions-test.yml +++ b/.github/workflows/actions-test.yml @@ -506,7 +506,8 @@ jobs: assert action["inputs"]["git_user_email"]["default"] == "348780249+mega-gutenberg[bot]@users.noreply.github.com" assert not {"settle_mode", "settlers", "github_token"} & action["inputs"].keys() assert set(action["outputs"]) == {"version", "pr_url", "notes_file"} - want = {"Guard": "guard.sh", "Generate release notes": "notes.sh", "Ensure the settle PR": "ensure.sh"} + want = {"Guard": "guard.sh", "Generate release notes": "notes.sh", "Ensure the settle PR": "ensure.sh", + "Compute settlement state": "state.sh"} found = {s["name"]: s["run"] for s in action["runs"]["steps"] if s.get("name") in want} assert found.keys() == want.keys(), f"missing shipped steps: {want.keys() - found.keys()}" for name, script in found.items(): @@ -629,11 +630,21 @@ jobs: path.write_text(json.dumps(state)) if args[:2] == ["pr", "list"]: + if option("--state") == "merged": + candidate = {"mergeCommit": {"oid": os.environ["CANDIDATE_SHA"]}, + "body": "", + "author": {"login": "app/mega-gutenberg"}, "mergedAt": "2026-01-01"} + print(json.dumps([candidate])) + sys.exit(0) assert option("--state") == "open" fields = option("--json").split(",") pulls = [pr for pr in state["pulls"] if pr["state"] == "open" and pr["headRefName"] == option("--head") and pr["baseRefName"] == option("--base")] - print(json.dumps([{key: pr[key] for key in fields} for pr in pulls])) + payload = json.dumps([{key: pr[key] for key in fields} for pr in pulls]) + if "--jq" in args: + subprocess.run(["jq", "-r", option("--jq")], input=payload, text=True, check=True) + else: + print(payload) elif args[:2] == ["pr", "create"]: assert not any(pr["state"] == "open" and pr["headRefName"] == option("--head") and pr["baseRefName"] == option("--base") for pr in state["pulls"]) @@ -663,6 +674,8 @@ jobs: pr["state"] = "closed" pr["comment"] = option("--comment") save("close") + elif args[:3] == ["api", "--paginate", "repos/megaeth-labs/fake/releases"]: + subprocess.run(["jq", "-r", option("--jq"), os.environ["RELEASE_PAGES"]], check=True) elif args[:3] == ["api", "-X", "DELETE"]: prefix = "repos/megaeth-labs/fake/git/refs/heads/" assert len(args) == 4 and args[3].startswith(prefix), args @@ -912,6 +925,32 @@ jobs: fi echo "PASS conflicting CHANGELOG fails, aborts the merge and leaves remote refs and PR untouched" + - name: Settlement state treats a tagged draft as resumable + run: | + set -euo pipefail + source "$SH/helpers.sh" + export REPO="$FIXTURE/draft" PR_STATE="$FIXTURE/draft-prs.json" + make_repo + export COMMIT CANDIDATE_SHA PREVIOUS=v1.0.0 + COMMIT="$(remote_head "$BRANCH")" + CANDIDATE_SHA="$COMMIT" + export RELEASE_PAGES="$FIXTURE/release-pages.jsonl" + printf '%s\n' '[{"tag_name":"v1.0.0","id":1,"draft":false}]' \ + '[{"tag_name":"v1.1.0","id":2,"draft":true}]' > "$RELEASE_PAGES" + ( + cd "$REPO" + git tag -a v1.1.0 "$COMMIT" -m 'interrupted publish' + export GITHUB_STEP_SUMMARY="$FIXTURE/draft-summary" + : > "$OUT" + bash "$SH/state.sh" + grep -qxF 'state=resume' "$OUT" + + printf '%s\n' '[{"tag_name":"v1.1.0","id":2,"draft":false}]' > "$RELEASE_PAGES" + : > "$OUT" + bash "$SH/state.sh" + grep -qxF 'state=published' "$OUT" + ) + - name: Remove settle rehearsal resources if: always() run: | @@ -1910,6 +1949,7 @@ jobs: GITHUB_REPOSITORY=megaeth-labs/fake \ TAG="$(out_get tag)" \ NOTES="$(out_get notes_file)" \ + ASSET_DIR="$(out_get asset_dir)" \ GITHUB_OUTPUT="$OUT.release" \ bash "$SH/release.sh" ) } @@ -2003,6 +2043,7 @@ jobs: mkdir -p "$RUNNER_TEMP/bin" "$FIX" : > "$ARGS" : > "$RELEASES" + printf '[]\n' > "$FIX/drafts.json" cat > "$RUNNER_TEMP/bin/gh" <<'SH' #!/usr/bin/env bash # Only what the shell under test calls. The pull request comes from a @@ -2023,13 +2064,35 @@ jobs: echo "gh: Not Found (HTTP 404)" >&2 exit 1 fi + if [[ "$1 $2" == 'api --paginate' && "$3" == repos/*/releases ]]; then + jq -r "$5" "$FIX/drafts.json" + exit 0 + fi + if [[ "$1" == api && "$2" == repos/*/releases/[0-9]* ]]; then + jq -r --argjson id "${2##*/}" '.[] | select(.id == $id) | .draft' "$FIX/drafts.json" + exit 0 + fi + if [[ "$1 $2 $3" == 'api --method DELETE' && "$4" == repos/*/releases/[0-9]* ]]; then + jq -e --argjson id "${4##*/}" 'any(.[]; .id == $id and .draft == true)' "$FIX/drafts.json" >/dev/null + jq --argjson id "${4##*/}" 'map(select(.id != $id))' "$FIX/drafts.json" > "$FIX/remaining-drafts.json" + mv "$FIX/remaining-drafts.json" "$FIX/drafts.json" + echo "delete ${4##*/}" >> "$FIX/release-events" + exit 0 + fi if [[ "${1:-}" == release && "${2:-}" == view ]]; then + draft=true + assets='[]' if grep -qxF "${3:-}" "$RELEASES"; then - echo "https://github.com/megaeth-labs/fake/releases/tag/$3" - exit 0 + draft=false + if [[ -f "$FIX/assets-$3.json" ]]; then assets="$(cat "$FIX/assets-$3.json")"; fi + elif ! jq -e --arg tag "$3" 'any(.[]; .tag_name == $tag and .draft == true)' "$FIX/drafts.json" >/dev/null; then + echo "release not found" >&2 + exit 1 fi - echo "release not found" >&2 - exit 1 + json="$(jq -cn --arg url "https://github.com/megaeth-labs/fake/releases/tag/$3" \ + --argjson draft "$draft" --argjson assets "$assets" '{url: $url, isDraft: $draft, assets: $assets}')" + if [[ "${6:-}" == -q ]]; then jq -r "$7" <<< "$json"; else echo "$json"; fi + exit 0 fi if [[ "${1:-}" == release && "${2:-}" == create ]]; then if [[ -e "$FIX/fail-create" ]]; then @@ -2046,6 +2109,8 @@ jobs: if [[ "${args[i]}" == --notes-file ]]; then notes="${args[i + 1]}"; fi done [[ -s "$notes" ]] || { echo "gh: --notes-file '$notes' is missing or empty" >&2; exit 1; } + printf '%s\0' "$@" > "$FIX/create-argv" + echo "create $3" >> "$FIX/release-events" echo "$*" >> "$ARGS" echo "$3" >> "$RELEASES" # GitHub's "latest" moves only for a Release created with --latest. @@ -2272,6 +2337,94 @@ jobs: [[ "$(cat "$FIX/latest-release")" == v3.1.0 ]] || { echo "latest moved back to $(cat "$FIX/latest-release")"; exit 1; } echo "v1.9.5 refused after v2.1.0; v3.0.0 not tagged after v3.1.0, and its late Release is not latest" + - name: No asset input preserves the exact Release create arguments + run: | + set -euo pipefail + printf '%s\0' release create v3.0.0 --verify-tag --latest=false --title v3.0.0 \ + --notes-file "$RUNNER_TEMP/release-notes-v3.0.0.md" > "$FIX/legacy-argv" + cmp "$FIX/create-argv" "$FIX/legacy-argv" + + - name: Asset validation refuses invalid paths before tagging + run: | + set -euo pipefail + source "$SH/helpers.sh" + settle 3.2.0 140 + mkdir -p "$REPO/dist" "$FIX/other" + printf 'binary\n' > "$REPO/dist/my tool" + printf 'different file\n' > "$FIX/other/my tool" + printf 'second binary\n' > "$FIX/other/tool-debug" + ln -s "$REPO/dist/my tool" "$FIX/other/linked" + touch "$FIX/other/SHA256SUMS" + count="$(grep -c . "$ARGS")" + ASSET_FILES=dist/missing GITHUB_WORKSPACE="$REPO" refuse 140 'existing regular file' + ASSET_FILES="$(printf '%s\n' 'dist/my tool' "$FIX/other/my tool")" GITHUB_WORKSPACE="$REPO" \ + refuse 140 'reserved or duplicated: my tool' + ASSET_FILES="$FIX/other/linked" refuse 140 'existing regular file' + ASSET_FILES="$FIX/other/SHA256SUMS" refuse 140 'reserved or duplicated: SHA256SUMS' + [[ -z "$(remote_tag_object v3.2.0)" ]] + [[ "$(grep -c . "$ARGS")" == "$count" ]] + + - name: Asset paths and basename checksums reach Release create + run: | + set -euo pipefail + source "$SH/helpers.sh" + ASSET_FILES="$(printf '%s\n' 'dist/my tool' '' "$FIX/other/tool-debug")" GITHUB_WORKSPACE="$REPO" publish 140 + sums="$(out_get asset_dir)/SHA256SUMS" + [[ "$(remote_commit v3.2.0)" == "$(cat "$FIX/merge-140")" ]] + printf '%s\0' release create v3.2.0 --verify-tag --latest --title v3.2.0 \ + --notes-file "$(out_get notes_file)" "$REPO/dist/my tool" "$FIX/other/tool-debug" "$sums" \ + > "$FIX/asset-argv" + cmp "$FIX/create-argv" "$FIX/asset-argv" + { (cd "$REPO/dist" && sha256sum 'my tool'); (cd "$FIX/other" && sha256sum tool-debug); } > "$FIX/expected-sums" + cmp "$sums" "$FIX/expected-sums" + + - name: A stranded draft resumes and is deleted before asset publication + run: | + set -euo pipefail + source "$SH/helpers.sh" + settle 3.3.0 141 + seed_tag v3.3.0 "$(cat "$FIX/merge-141")" + printf '%s\n' '[{"tag_name":"v3.3.0","id":11,"draft":true},{"tag_name":"v3.1.0","id":13,"draft":true}]' > "$FIX/drafts.json" + tag_object="$(remote_tag_object v3.3.0)" + guard 141 + expect_output 'tag_exists=true' + expect_output 'published=false' + expect_output 'release_url=' + + : > "$FIX/release-events" + touch "$FIX/fail-create" + if release_step > "$FIX/draft.log" 2>&1; then + echo "create failed but a draft was accepted"; exit 1 + fi + grep -qF 'could not create the Release for v3.3.0' "$FIX/draft.log" + [[ ! -s "$FIX/release-events" && ! -s "$OUT.release" ]] + rm "$FIX/fail-create" + + ASSET_FILES="$FIX/other/tool-debug" publish 141 + [[ ! -e "$FIX/tag-ran" && "$(remote_tag_object v3.3.0)" == "$tag_object" ]] + printf '%s\n' 'delete 11' 'create v3.3.0' > "$FIX/expected-events" + cmp "$FIX/release-events" "$FIX/expected-events" + + - name: A concurrent published Release must have every uploaded asset + run: | + set -euo pipefail + source "$SH/helpers.sh" + settle 3.4.0 142 + ASSET_FILES="$FIX/other/tool-debug" guard 142 + tag_step + echo v3.4.0 >> "$RELEASES" + printf '%s\n' '[{"tag_name":"v3.4.0","id":12,"draft":false}]' > "$FIX/drafts.json" + printf '%s\n' '[{"name":"tool-debug","state":"uploaded"},{"name":"SHA256SUMS","state":"starter"}]' > "$FIX/assets-v3.4.0.json" + if release_step > "$FIX/fallback.log" 2>&1; then + echo "a published Release without SHA256SUMS was accepted"; exit 1 + fi + grep -qF 'published Release v3.4.0 is missing asset: SHA256SUMS' "$FIX/fallback.log" + [[ ! -s "$OUT.release" ]] + + printf '%s\n' '[{"name":"tool-debug","state":"uploaded"},{"name":"SHA256SUMS","state":"uploaded"}]' > "$FIX/assets-v3.4.0.json" + release_step + grep -qxF 'url=https://github.com/megaeth-labs/fake/releases/tag/v3.4.0' "$OUT.release" + release-route: runs-on: ubuntu-24.04 permissions: @@ -2393,7 +2546,10 @@ jobs: cat "$FIX/fallback.json" ;; "release view "*) [[ -e "$FIX/release-exists" ]] || exit 1 - echo '{"tagName":"v1.2.0"}' ;; + is_draft=false + [[ ! -e "$FIX/release-draft" ]] || is_draft=true + jq -nr --arg tag "$3" --argjson draft "$is_draft" \ + '{tagName: $tag, isDraft: $draft} | '"$7" ;; *) echo "unexpected gh call: $*" >&2; exit 99 ;; esac SH @@ -2620,6 +2776,29 @@ jobs: done echo "a missing or unparsable version file fails push and dispatch routes, naming file and pattern" + - name: Push and dispatch do not count a draft as published + run: | + set -euo pipefail + source "$SH/helpers.sh" + touch "$FIX/release-exists" "$FIX/release-draft" + + # Dispatch still includes a tagged branch whose Release is a draft. + route settle main "$(cat "$FIX/candidate")" workflow_dispatch + expect_output action refresh + [[ "$(out_get targets | jq -c 'map(.release_branch) | sort')" == '["release-v1.1.0","release-v1.2.0"]' ]] + + # A push at the settle merge resumes the draft's tagged version. + merge="$(cat "$FIX/merge")" + git -C "$REPO" tag -a v1.2.0 "$merge" -m 'interrupted publish' + "$AUTH_WRAPPER" git -C "$REPO" push --quiet origin refs/tags/v1.2.0 + cp "$FIX/settle.json" "$FIX/pulls.json" + route settle release-v1.2.0 "$merge" + expect_output action publish + expect_output commit "$merge" + "$AUTH_WRAPPER" git -C "$REPO" push --quiet origin :refs/tags/v1.2.0 + git -C "$REPO" tag -d v1.2.0 + rm "$FIX/release-exists" "$FIX/release-draft" + - name: Partial publication resumes and reports the actual tag commit run: | set -euo pipefail diff --git a/docs/RELEASING.md b/docs/RELEASING.md index c39314c..b3e99b2 100644 --- a/docs/RELEASING.md +++ b/docs/RELEASING.md @@ -92,12 +92,16 @@ one-sentence reason in the job log. no date is injected. A settle PR that went stale before it merged publishes nothing; `route` answers `refresh` and a fresh PR follows. -4. **Assets: the tag push (the Release) fires On Release.** Publishing the - Release runs the repository's `on-release.yml`, which builds, verifies the + For GitHub Release downloads, pass the built files to + [`release-publish`](../.github/actions/release-publish/README.md) as + `asset_files`. It attaches them with `SHA256SUMS` before the Release becomes + immutable. + +4. **Publish targets.** Publishing the Release runs the repository's + `on-release.yml`, which builds, verifies the version ([`release-verify-version`](../.github/actions/release-verify-version/README.md)), uploads ([`release-upload-artifact`](../.github/actions/release-upload-artifact/README.md)), - attaches [release assets](../.github/actions/release-assets/README.md), and - publishes crates. + and publishes crates. ## Environments and their variables diff --git a/workflow-templates/on-release.yml b/workflow-templates/on-release.yml index 3bc2c30..1bef7f6 100644 --- a/workflow-templates/on-release.yml +++ b/workflow-templates/on-release.yml @@ -4,7 +4,7 @@ name: On Release # GitHub Release (the release-publish action, run by release-settle's publish # job with the release app mega-gutenberg, creates it right after the tag), # and on demand for a rehearsal on a tag ref, which runs every job with -# nothing uploaded, published or attached: +# nothing uploaded or published: # gh workflow run on-release.yml --ref vX.Y.Z -f dry_run=true # The tag being released is always the run's own ref; there is no tag input. # The `release` environment authorises that ref, so it must also be what @@ -14,10 +14,9 @@ name: On Release # workflow from the tag's tree, not from the default branch. A release branch # cut from a default branch that has it carries it; a branch cut before it # landed needs it cherry-picked (through its own PR — the `release-*` ruleset -# requires one) before the settle PR is merged, or the Release publishes -# with nothing attached and no failed run. release-settle warns when the -# settled commit lacks a workflow the default branch has. A rehearsal -# likewise needs a tag whose tree has this file. +# requires one) before the settle PR is merged, or these jobs will not run. +# release-settle warns when the settled commit lacks a workflow the default +# branch has. A rehearsal likewise needs a tag whose tree has this file. # # Put CARGO_REGISTRY_TOKEN / GCP_AUTH_KEY in the `release` environment as # environment secrets. Require reviewers and allow the default branch, @@ -44,13 +43,13 @@ on: workflow_dispatch: inputs: dry_run: - description: "Verify and build everything; publish, upload and attach nothing" + description: "Verify and build everything; publish and upload nothing" required: false type: boolean default: true # One run per tag: a release run and a dispatch on the same tag both end in -# uploads (`--clobber` on Release assets), so overlapping runs would race. +# uploads, so overlapping runs would race. # Never cancel an upload mid-flight; queue instead. concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -97,12 +96,11 @@ jobs: token: ${{ env.DRY_RUN != 'true' && secrets.CARGO_REGISTRY_TOKEN || '' }} dry_run: ${{ env.DRY_RUN }} - # ---- binary: build → verify → MegaETH registry → Release asset ------------- + # ---- binary: build → verify → MegaETH registry --------------------------- + # For GitHub Release downloads, pass asset_files to release-publish in release-settle.yml. binary: runs-on: ubuntu-latest environment: release - permissions: - contents: write # release-assets steps: - name: Require a tag ref run: | @@ -143,10 +141,3 @@ jobs: package: my-binary version: ${{ env.TAG }} dry_run: ${{ env.DRY_RUN }} - - - uses: megaeth-labs/.github/.github/actions/release-assets@main - with: - tag: ${{ env.TAG }} - files: | - target/release/my-binary - dry_run: ${{ env.DRY_RUN }} diff --git a/workflow-templates/release-settle.yml b/workflow-templates/release-settle.yml index eb0860b..de323ec 100644 --- a/workflow-templates/release-settle.yml +++ b/workflow-templates/release-settle.yml @@ -111,6 +111,11 @@ jobs: version_pattern: plain changelog_file: CHANGELOG.md + # To attach Release assets, add a build job that needs route and runs when + # route returns publish. Check out `needs.route.outputs.commit` with + # persist-credentials: false and build without release credentials. + # Upload the files as a workflow artifact. Add the build to publish.needs, + # download the artifact after checkout, and list its paths in asset_files. publish: needs: route # Route permits a merged settle PR on push or a clean branch on dispatch; From cbef2fd4786a72ed72b1e7992038f9de22df7ec1 Mon Sep 17 00:00:00 2001 From: RealiCZ Date: Fri, 20 Nov 2026 18:32:35 +0800 Subject: [PATCH 2/3] fix(release): refuse asset_files that names no paths Reject blank asset lists before creating a tag. Test both empty and whitespace-only lines. --- .github/actions/release-publish/README.md | 1 + .github/actions/release-publish/action.yml | 7 ++++--- .github/workflows/actions-test.yml | 9 +++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/actions/release-publish/README.md b/.github/actions/release-publish/README.md index b54f309..efd558d 100644 --- a/.github/actions/release-publish/README.md +++ b/.github/actions/release-publish/README.md @@ -74,6 +74,7 @@ Family: [Release pipeline](../RELEASE.md). - `release asset must be an existing regular file and not a symlink: $file` - `release asset basename is reserved or duplicated: $name` - `release asset path cannot contain GitHub CLI` +- `asset_files is set but names no usable paths` - `could not push $TAG; the remote tag is at $(git rev-parse` - `cannot read the latest Release to decide whether $TAG is the latest; re-run to resume` - `could not create the Release for $TAG` diff --git a/.github/actions/release-publish/action.yml b/.github/actions/release-publish/action.yml index bafa054..5d9b9cd 100644 --- a/.github/actions/release-publish/action.yml +++ b/.github/actions/release-publish/action.yml @@ -315,7 +315,7 @@ runs: asset_dir="$(mktemp -d "$RUNNER_TEMP/release-publish-assets.XXXXXXXX")" touch "$asset_dir/files" "$asset_dir/names" "$asset_dir/SHA256SUMS" while IFS= read -r file; do - [[ -n "$file" ]] || continue + [[ "$file" =~ ^[[:space:]]*$ ]] && continue [[ "$file" == /* ]] || file="$GITHUB_WORKSPACE/$file" if [[ ! -f "$file" || -L "$file" ]]; then echo "::error::release asset must be an existing regular file and not a symlink: $file"; exit 1 @@ -331,9 +331,10 @@ runs: printf '%s\n' "$file" >> "$asset_dir/files" (cd "${file%/*}/" && sha256sum -- "./$name") | sed 's/ \.\// /' >> "$asset_dir/SHA256SUMS" done <<< "$ASSET_FILES" - if [[ -s "$asset_dir/files" ]]; then - echo "asset_dir=$asset_dir" >> "$GITHUB_OUTPUT" + if [[ ! -s "$asset_dir/files" ]]; then + echo "::error::asset_files is set but names no usable paths"; exit 1 fi + echo "asset_dir=$asset_dir" >> "$GITHUB_OUTPUT" fi { echo "version=$version" diff --git a/.github/workflows/actions-test.yml b/.github/workflows/actions-test.yml index d05f20b..e248d92 100644 --- a/.github/workflows/actions-test.yml +++ b/.github/workflows/actions-test.yml @@ -2364,6 +2364,15 @@ jobs: [[ -z "$(remote_tag_object v3.2.0)" ]] [[ "$(grep -c . "$ARGS")" == "$count" ]] + - name: Asset validation refuses blank lists before tagging + run: | + set -euo pipefail + source "$SH/helpers.sh" + for files in $'\n\n' $'\n \n'; do + ASSET_FILES="$files" refuse 140 '::error::asset_files is set but names no usable paths' + [[ -z "$(remote_tag_object v3.2.0)" ]] + done + - name: Asset paths and basename checksums reach Release create run: | set -euo pipefail From f08e951fe5688feeb05fa332456a094adf1ec07b Mon Sep 17 00:00:00 2001 From: William Aaron Cheung Date: Mon, 23 Nov 2026 09:49:54 +0800 Subject: [PATCH 3/3] fix(release): never delete a draft Release this publish did not create 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 --- .github/actions/release-publish/README.md | 15 +++- .github/actions/release-publish/action.yml | 36 ++++++++- .github/workflows/actions-test.yml | 93 +++++++++++++++++++++- 3 files changed, 135 insertions(+), 9 deletions(-) diff --git a/.github/actions/release-publish/README.md b/.github/actions/release-publish/README.md index efd558d..1c151a6 100644 --- a/.github/actions/release-publish/README.md +++ b/.github/actions/release-publish/README.md @@ -23,6 +23,7 @@ Family: [Release pipeline](../RELEASE.md). | `commit` | yes | | The commit to publish (full SHA); it must be the settle PR's merge commit for pr, or the candidate PR's merge commit for dispatch. | | `pr_number` | yes | | Number of the merged settle PR for pr, or the merged candidate PR for dispatch. | | `asset_files` | no | | Newline-separated regular file paths, absolute or relative to the workspace. Use unique basenames and reserve SHA256SUMS for the generated checksum file. Paths cannot contain `#`, which GitHub CLI treats as an asset label separator. | +| `release_author` | no | `mega-gutenberg[bot]` | Login a draft Release at the tag must have been created by for the publish step to delete it as debris from its own interrupted run — the app identity this action runs under. Any other draft at the tag is refused, never deleted, so a hand-written draft is never destroyed. Only consulted with `asset_files`. Empty refuses every pre-existing draft. | | `pr_author` | no | `mega-gutenberg[bot]` | Login the settle or candidate PR must have been opened by — the app identity `release-settle` runs under. Stops a hand-made `chore/release-settle-*` branch from reaching the tag step. Empty disables the check only for pr. | | `git_user_name` | no | `mega-gutenberg[bot]` | Committer identity for the commits this action makes. | | `git_user_email` | no | `348780249+mega-gutenberg[bot]@users.noreply.github.com` | Committer email for the commits this action makes. | @@ -77,6 +78,8 @@ Family: [Release pipeline](../RELEASE.md). - `asset_files is set but names no usable paths` - `could not push $TAG; the remote tag is at $(git rev-parse` - `cannot read the latest Release to decide whether $TAG is the latest; re-run to resume` +- `draft Release $id for $TAG was created by ${author:-}, not $RELEASE_AUTHOR; publishing would delete it. Publish or delete that draft by hand, then re-run.` +- `cannot read draft Release $id for $TAG to decide whether to replace it; re-run to resume` - `could not create the Release for $TAG` - `published Release $TAG is missing asset: $name` @@ -129,9 +132,15 @@ ancestry rule. with the same inputs for the direct shape. A tag elsewhere is refused. A tag at `commit` with a published Release is a no-op. - With `asset_files`, the guard checks the files and generates `SHA256SUMS` - before tagging. The publish step replaces stranded drafts for the tag and - uploads the files before publication. Keep the publish job in the template's - per-release-branch concurrency group when using this input. + before tagging, and only for a publish that will create the Release: a retry + of a finished run is still a no-op whatever `asset_files` names. The publish + step uploads the files before publication. Keep the publish job in the + template's per-release-branch concurrency group when using this input. +- A draft Release at the tag is only replaced when it is this action's own: it + must have been created by `release_author`, the identity publishing here, and + the deletion is announced as a warning. Any other draft at the tag — someone's + unpublished notes — is refused with an error and left untouched, because + deleting a Release cannot be undone. - The Release body is the changelog section extracted from the tagged tree, verbatim, with no injected date. With an empty `changelog_file`, notes are generated from non-merge commits since the previous release tag (or all diff --git a/.github/actions/release-publish/action.yml b/.github/actions/release-publish/action.yml index 5d9b9cd..f4736b5 100644 --- a/.github/actions/release-publish/action.yml +++ b/.github/actions/release-publish/action.yml @@ -73,6 +73,15 @@ inputs: Paths cannot contain `#`, which GitHub CLI treats as an asset label separator. required: false default: "" + release_author: + description: >- + Login a draft Release at the tag must have been created by for the publish + step to delete it as debris from its own interrupted run — the app identity + this action runs under. Any other draft at the tag is refused, never + deleted, so a hand-written draft is never destroyed. Only consulted with + `asset_files`. Empty refuses every pre-existing draft. + required: false + default: "mega-gutenberg[bot]" pr_author: description: >- Login the settle or candidate PR must have been opened by — the app identity @@ -311,7 +320,9 @@ runs: echo "::error::changelog section for v$version at $MERGE_SHA disagrees with regenerated notes; let the settle refresh land first, then publish."; exit 1 fi fi - if [[ -n "${ASSET_FILES:-}" ]]; then + # Only for a publish that will create the Release. A retry of a finished + # run exits 0 below, and must not need the files to still be on disk. + if [[ "$published" != true && -n "${ASSET_FILES:-}" ]]; then asset_dir="$(mktemp -d "$RUNNER_TEMP/release-publish-assets.XXXXXXXX")" touch "$asset_dir/files" "$asset_dir/names" "$asset_dir/SHA256SUMS" while IFS= read -r file; do @@ -410,8 +421,12 @@ runs: NOTES: ${{ steps.guard.outputs.notes_file }} TOOLS: ${{ github.action_path }}/../release-tools/release_tools.py ASSET_DIR: ${{ steps.guard.outputs.asset_dir }} + RELEASE_AUTHOR: ${{ inputs.release_author }} run: | set -euo pipefail + # Unset means no attributable author, which refuses every pre-existing + # draft below: a harness that extracts this step never deletes one. + RELEASE_AUTHOR="${RELEASE_AUTHOR:-}" # Mark the Release latest only if it is newer than the Release GitHub # calls latest now (a concurrent publish of a newer line may have won). if current="$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq .tag_name 2>"$RUNNER_TEMP/latest-release.err")"; then @@ -444,14 +459,27 @@ runs: done < "$ASSET_DIR/files" set -- "$@" "$ASSET_DIR/SHA256SUMS" releases="repos/$GITHUB_REPOSITORY/releases" - drafts="$(gh api --paginate "$releases" --jq ".[] | select(.tag_name == \"$TAG\" and .draft == true) | .id")" - while IFS= read -r id; do + drafts="$(gh api --paginate "$releases" \ + --jq ".[] | select(.tag_name == \"$TAG\" and .draft == true) | [.id, .author.login] | @tsv")" + while IFS=$'\t' read -r id author; do [[ -n "$id" ]] || continue + # Only this action's own interrupted run leaves a draft to replace, + # and gh creates it as the identity publishing here. Any other draft + # at the tag is someone's unpublished notes: refuse, never delete. + if [[ -z "$RELEASE_AUTHOR" || "$author" != "$RELEASE_AUTHOR" ]]; then + echo "::error::draft Release $id for $TAG was created by ${author:-}, not $RELEASE_AUTHOR; publishing would delete it. Publish or delete that draft by hand, then re-run."; exit 1 + fi # The publish job serializes each release branch. Recheck by ID # immediately before deleting so a published Release is skipped. - draft="$(gh api "$releases/$id" --jq .draft)" + # A 404 is the outcome this loop wants, not a failure: continue. + if ! draft="$(gh api "$releases/$id" --jq .draft 2>"$RUNNER_TEMP/draft-$id.err")"; then + grep -qF "HTTP 404" "$RUNNER_TEMP/draft-$id.err" && continue + cat "$RUNNER_TEMP/draft-$id.err" >&2 + echo "::error::cannot read draft Release $id for $TAG to decide whether to replace it; re-run to resume"; exit 1 + fi if [[ "$draft" == true ]]; then gh api --method DELETE "$releases/$id" + echo "::warning title=Deleted stranded draft::draft Release $id at $TAG was left by an interrupted publish and was deleted before creating the Release" fi done <<< "$drafts" fi diff --git a/.github/workflows/actions-test.yml b/.github/workflows/actions-test.yml index e248d92..7a22c7d 100644 --- a/.github/workflows/actions-test.yml +++ b/.github/workflows/actions-test.yml @@ -1950,6 +1950,7 @@ jobs: TAG="$(out_get tag)" \ NOTES="$(out_get notes_file)" \ ASSET_DIR="$(out_get asset_dir)" \ + RELEASE_AUTHOR="${RELEASE_AUTHOR-mega-gutenberg[bot]}" \ GITHUB_OUTPUT="$OUT.release" \ bash "$SH/release.sh" ) } @@ -2069,6 +2070,15 @@ jobs: exit 0 fi if [[ "$1" == api && "$2" == repos/*/releases/[0-9]* ]]; then + # The real API 404s for a draft deleted since the listing was read. + if [[ -e "$FIX/vanished-${2##*/}" ]]; then + echo "gh: Not Found (HTTP 404)" >&2 + exit 1 + fi + if [[ -e "$FIX/unreadable-${2##*/}" ]]; then + echo "gh: Server Error (HTTP 500)" >&2 + exit 1 + fi jq -r --argjson id "${2##*/}" '.[] | select(.id == $id) | .draft' "$FIX/drafts.json" exit 0 fi @@ -2183,6 +2193,20 @@ jobs: [[ "$(grep -c 'release create v1.2.0 ' "$ARGS")" == 1 ]] || { echo "a second Release was created"; exit 1; } echo "tag and Release both at the commit: exit 0, notice, nothing changed" + - name: A finished publish stays a no-op whatever asset_files says + run: | + set -euo pipefail + source "$SH/helpers.sh" + # The Release is already there, so no asset is ever uploaded from this + # run: the files need not still be on disk for the retry to be green. + ASSET_FILES="$(printf '%s\n' dist/gone /nowhere/SHA256SUMS)" GITHUB_WORKSPACE="$REPO" \ + publish 101 > "$RUNNER_TEMP/retry-assets.log" 2>&1 \ + || { echo "a retry of a finished publish failed on asset_files"; cat "$RUNNER_TEMP/retry-assets.log"; exit 1; } + expect_output "published=true" + grep -qF "Already published" "$RUNNER_TEMP/retry-assets.log" + [[ -z "$(out_get asset_dir)" ]] || { echo "asset work ran for a finished publish"; exit 1; } + [[ ! -e "$FIX/tag-ran" && ! -e "$FIX/release-ran" ]] || { echo "a step ran on the retry"; exit 1; } + - name: A run that died after the tag is resumed, not refused run: | set -euo pipefail @@ -2393,7 +2417,8 @@ jobs: source "$SH/helpers.sh" settle 3.3.0 141 seed_tag v3.3.0 "$(cat "$FIX/merge-141")" - printf '%s\n' '[{"tag_name":"v3.3.0","id":11,"draft":true},{"tag_name":"v3.1.0","id":13,"draft":true}]' > "$FIX/drafts.json" + printf '%s\n' '[{"tag_name":"v3.3.0","id":11,"draft":true,"author":{"login":"mega-gutenberg[bot]"}}, + {"tag_name":"v3.1.0","id":13,"draft":true,"author":{"login":"mega-gutenberg[bot]"}}]' > "$FIX/drafts.json" tag_object="$(remote_tag_object v3.3.0)" guard 141 expect_output 'tag_exists=true' @@ -2409,10 +2434,12 @@ jobs: [[ ! -s "$FIX/release-events" && ! -s "$OUT.release" ]] rm "$FIX/fail-create" - ASSET_FILES="$FIX/other/tool-debug" publish 141 + ASSET_FILES="$FIX/other/tool-debug" publish 141 > "$FIX/publish-141.log" 2>&1 [[ ! -e "$FIX/tag-ran" && "$(remote_tag_object v3.3.0)" == "$tag_object" ]] printf '%s\n' 'delete 11' 'create v3.3.0' > "$FIX/expected-events" cmp "$FIX/release-events" "$FIX/expected-events" + # The deletion is announced, so it is never silent in the run log. + grep -qF '::warning title=Deleted stranded draft::draft Release 11 at v3.3.0' "$FIX/publish-141.log" - name: A concurrent published Release must have every uploaded asset run: | @@ -2434,6 +2461,68 @@ jobs: release_step grep -qxF 'url=https://github.com/megaeth-labs/fake/releases/tag/v3.4.0' "$OUT.release" + - name: A draft the publish did not create is refused, never deleted + run: | + set -euo pipefail + source "$SH/helpers.sh" + settle 3.5.0 143 + printf '%s\n' '[{"tag_name":"v3.5.0","id":21,"draft":true,"author":{"login":"a-maintainer"}}]' > "$FIX/drafts.json" + ASSET_FILES="$FIX/other/tool-debug" guard 143 + tag_step + : > "$FIX/release-events" + if release_step > "$FIX/foreign.log" 2>&1; then + echo "a foreign draft was accepted"; exit 1 + fi + grep -qF 'draft Release 21 for v3.5.0 was created by a-maintainer' "$FIX/foreign.log" + # Refused before any destructive call, and the draft is still there. + [[ ! -s "$FIX/release-events" && ! -s "$OUT.release" ]] + [[ "$(jq -r 'length' "$FIX/drafts.json")" == 1 ]] + + # An unattributable draft (no author) is refused the same way. + printf '%s\n' '[{"tag_name":"v3.5.0","id":21,"draft":true}]' > "$FIX/drafts.json" + if release_step > "$FIX/anon.log" 2>&1; then + echo "an unattributable draft was accepted"; exit 1 + fi + grep -qF 'created by ' "$FIX/anon.log" + [[ ! -s "$FIX/release-events" ]] + + # Its own draft publishes, and the run is clean once the draft is ours. + printf '%s\n' '[{"tag_name":"v3.5.0","id":21,"draft":true,"author":{"login":"mega-gutenberg[bot]"}}]' > "$FIX/drafts.json" + release_step + printf '%s\n' 'delete 21' 'create v3.5.0' > "$FIX/expected-events" + cmp "$FIX/release-events" "$FIX/expected-events" + + - name: A draft that vanishes between the listing and the read is not fatal + run: | + set -euo pipefail + source "$SH/helpers.sh" + settle 3.6.0 144 + printf '%s\n' '[{"tag_name":"v3.6.0","id":31,"draft":true,"author":{"login":"mega-gutenberg[bot]"}}, + {"tag_name":"v3.6.0","id":32,"draft":true,"author":{"login":"mega-gutenberg[bot]"}}]' > "$FIX/drafts.json" + # 31 is deleted by something else after the listing; 404 means the + # loop already has what it wanted, so the publish must carry on. + touch "$FIX/vanished-31" + : > "$FIX/release-events" + ASSET_FILES="$FIX/other/tool-debug" publish 144 + printf '%s\n' 'delete 32' 'create v3.6.0' > "$FIX/expected-events" + cmp "$FIX/release-events" "$FIX/expected-events" + grep -qxF "url=https://github.com/megaeth-labs/fake/releases/tag/v3.6.0" "$OUT.release" + rm "$FIX/vanished-31" + + # Any other read failure still refuses, with a named error. + settle 3.7.0 145 + printf '%s\n' '[{"tag_name":"v3.7.0","id":33,"draft":true,"author":{"login":"mega-gutenberg[bot]"}}]' > "$FIX/drafts.json" + touch "$FIX/unreadable-33" + ASSET_FILES="$FIX/other/tool-debug" guard 145 + tag_step + : > "$FIX/release-events" + if release_step > "$FIX/unreadable.log" 2>&1; then + echo "an unreadable draft was accepted"; exit 1 + fi + grep -qF 'cannot read draft Release 33 for v3.7.0' "$FIX/unreadable.log" + [[ ! -s "$FIX/release-events" ]] + rm "$FIX/unreadable-33" + release-route: runs-on: ubuntu-24.04 permissions: