Skip to content

release.yml: gate goreleaser on tests passing - #2

Merged
unidoc-ahall merged 5 commits into
masterfrom
fix-release-test-gate
Sep 2, 2026
Merged

unidoc-ahall merged 5 commits into
masterfrom
fix-release-test-gate

Conversation

@unidoc-ahall

@unidoc-ahall unidoc-ahall commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Started as: gate release.yml's goreleaser job on tests passing —
a tag push had no relation to test.yml, so binaries could publish
from a commit whose tests never ran. Grew during review into the
full release-tooling pass unidoc-alip's review surfaced:

  • release.yml/test.yml: test job that goreleaser needs,
    deduplicated via workflow_call (not copy-pasted), gofmt step's
    pipefail gap fixed, permissions ceiling correctly set to read
    at workflow level (not just omitted — omitted falls back to this
    repo's permissive default token, which was a worse regression than
    the thing being fixed).
  • Justfile: release-pr refuses cleanly when there's nothing to
    bump (same bug independently found in age-plugin-sshagent's
    identical recipe), and no longer wedges itself if gh pr create
    fails after the branch is already pushed.

Test plan

  • go build/vet/test/gofmt clean (verified locally, CI confirms)
  • Merge, then just release 0.1.0 directly — version.txt already carries 0.1.0, so release-pr has nothing to bump for this first release; the next real bump (0.1.1+) is the first live exercise of release-pr's guards

A tag push has no relation to the test workflow (only triggers on
push:branches/pull_request) — release.yml went straight from tag push
to goreleaser, so a tag could publish binaries whose tests never ran
or failed. `just release` checks version.txt/clean-tree/tag-existence
but not CI status. Added a `test` job (build/vet/test/gofmt, matching
test.yml) that `goreleaser` now needs.

Same gap unidoc-alip's age-plugin-sshagent review caught (F2) —
fixing here too ahead of today's release.

@unidoc-alip unidoc-alip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: COMMENT — 0 must-fix, 1 should-fix, 1 nit

This PR closes a real hole: release.yml triggers on push: tags: ["v*"] and went straight
to goreleaser release --clean, while test.yml triggers only on push: branches: [master]
and pull_request. A tag push therefore ran no build, no go vet, no go test and no
gofmt check — binaries could be published from a commit whose tests had never run. The fix
(a test job in release.yml plus needs: test on goreleaser) is the right shape, holds
regardless of how the tag was created, and is correctly minimal at 19 added lines with nothing
removed.

The gap and the fix were both verified by machine, not just read — see the appendix. Nothing
here blocks merge; both findings are follow-ups you could reasonably take in a separate commit.
Findings are keyed F1, F2, … (not #1, which GitHub would autolink to an unrelated issue).


F1 [should-fix] .github/workflows/release.yml line 18 — the test job is a verbatim copy of test.yml, and nothing keeps them in sync

The new jobs.test in release.yml is step-for-step identical to jobs.test in test.yml.
The PoC asserts that parity today and it holds (inline-match), which is exactly the point:
the two are equal now, and there is no mechanism that keeps them equal. The next change to the
CI recipe — a new linter, a -race flag, an apt-get install for an integration dependency,
a Go version pin — will land in test.yml because that is the workflow people see on PRs, and
release.yml will silently start gating releases on a weaker check than the one that gates
merges. That is a quiet failure: the release still goes green.

GitHub's reusable-workflow support removes the duplication without changing behaviour. In
test.yml, add one trigger:

on:
  push:
    branches: [master]
  pull_request:
  workflow_call:

and in release.yml, replace the whole inline job with:

  test:
    uses: ./.github/workflows/test.yml

I built this variant and ran it through the same assertions plus actionlint under a real
.github/workflows/ layout, so the uses: path actually resolves; both are clean and
goreleaser still resolves needs: test. Two things to know before taking it: a called
workflow's checks surface as test / test rather than test, so any branch-protection rule
naming the required check needs updating; and a uses: job cannot carry runs-on or steps,
which is why the block collapses to a single line.

Worth folding in while you are in there: the gofmt step masks gofmt's own exit code.

$ bash -c 'gofmt -l /nonexistent | tee /tmp/fmt.out && test ! -s /tmp/fmt.out'; echo $?
stat /nonexistent: no such file or directory
0

The pipeline's status is tee's, and GitHub Actions runs run: steps under bash -e {0}
without pipefail, so a gofmt that errors out rather than printing filenames passes the
step. It is low-impact — gofmt rarely fails outright — but the copy in release.yml now
inherits it, and consolidating via workflow_call means fixing it once instead of twice.
If you would rather leave the workflows duplicated, the one-line fix is shell: bash on that
step — GitHub then runs it as bash --noprofile --norc -eo pipefail {0}, and with pipefail
set the same command returns 2 on a gofmt error instead of 0. Note that test -z "$(gofmt -l .)" is not a fix: gofmt's error goes to stderr, stdout is empty, and test -z "" succeeds
just the same.

F2 [nit] .github/workflows/release.yml line 8 — the new test job inherits contents: write

permissions: contents: write is declared at workflow level, so it applied to one job before
this PR and applies to two after it. The test job now runs go build, go vet and
go test ./... — arbitrary project and dependency code — with a GITHUB_TOKEN that can push
to the repo and create releases. Only goreleaser needs that.

permissions:
  contents: read          # workflow-level default

jobs:
  test:
    runs-on: ubuntu-latest
    # inherits contents: read

  goreleaser:
    needs: test
    runs-on: ubuntu-latest
    permissions:
      contents: write     # only the publishing job

Genuinely a nit given the threat model — your own code, tags pushed by maintainers — but it is
a two-line change that makes the blast radius of a compromised transitive dependency smaller,
and this PR is the moment the second job appears.


PR description verification

  • "A tag push has no relation to the test workflow (only triggers on push:branches/pull_request)" — confirmed. Parsed test.yml's triggers: on.push has a branches key and no tags key, and tags are not branches, so a v* tag push starts nothing in test.yml. Asserted in the PoC as test.yml-tag-trigger=False across all three variants.
  • "release.yml went straight from tag push to goreleaser" — confirmed. On master, release.yml has exactly one job and it carries no needs (release-test-job=False | goreleaser-needs=None).
  • "Added a test job (build/vet/test/gofmt, matching test.yml) that goreleaser now needs" — confirmed. At head, release-test-job=True | goreleaser-needs=test, and the job's step list compares equal to test.yml's step list — the four commands and the checkout/setup-go preamble match exactly, not approximately.
  • "just release checks version.txt/clean-tree/tag-existence but not CI status" — confirmed. Justfile lines 103–110: version regex, git status --porcelain, version.txt equality, and git rev-parse "v{{VERSION}}". No gh run list or any other CI query. (I also checked the git rev-parse … && { exit 1; } line for a set -e interaction that would let a duplicate tag slip through — it behaves correctly; no issue there.)
  • "Same gap unidoc-alip's age-plugin-sshagent review caught (F2), also present here" — confirmed, and the fix mirrors it faithfully. That review's F2 on unidoc/age-plugin-sshagent#1 describes the identical trigger mismatch and recommends "a gate in the workflow itself, so it holds regardless of how the tag was created," with an inline test job and needs: test — structurally what landed here, adapted to this repo's four commands rather than that repo's age apt dependency and bare go test. Its alternative suggestion (query gh run list from the release recipe) was correctly not taken; the workflow-level gate is the stronger of the two. Note that PR is still open, so this repo gets the fix first.
  • "go build/vet/test/gofmt clean (verified locally, CI will confirm)" — partially confirmed, and worth being precise about. The single passing check on this PR is test.yml's job, fired by pull_request. It confirms the repo passes those four commands. It does not exercise anything this PR adds: the new release.yml test job and the needs: test edge only fire on a v* tag push, so as of this review they have never executed. The first run of the code under review will be the next real release. That is the residual risk, and it is why I linted all three variants with actionlint (clean) rather than relying on the green check.
  • "Merge, then tag/release as normal — goreleaser will now wait on test" — confirmed by static analysis, not by execution. needs: test is correctly wired and actionlint accepts the file; no tag was pushed during this review.

Appendix — how this was checked

poc_2_release_gate.py parses the real workflow files — copied verbatim out of git at
master (base), pr-2-review (head), and a workflow_call refactor (fixed) — and asserts a
single joined outcome string per variant:

[PASS] base:  test.yml-tag-trigger=False | release-on-tags=['v*'] | release-test-job=False | goreleaser-needs=None | no-test-job
[PASS] head:  test.yml-tag-trigger=False | release-on-tags=['v*'] | release-test-job=True  | goreleaser-needs=test | inline-match
[PASS] fixed: test.yml-tag-trigger=False | release-on-tags=['v*'] | release-test-job=True  | goreleaser-needs=test | reused:./.github/workflows/test.yml

Base reproduces the gap; head closes it; the F1 refactor closes it too and keeps step parity
by construction. Head, the F1 refactor and the F2 permissions variant were each additionally
linted with actionlint under a real .github/workflows/ layout — all clean.

The script, so you can re-run it yourself:

import os, sys, yaml

def outcome(d):
    t = yaml.safe_load(open(os.path.join(d, "test.yml")))
    r = yaml.safe_load(open(os.path.join(d, "release.yml")))
    # PyYAML parses a bare `on:` key as boolean True (YAML 1.1). Handle both.
    ton, ron = t.get("on", t.get(True)), r.get("on", r.get(True))
    push = ton.get("push")
    test_tag_trigger = "tags" in push if isinstance(push, dict) else False
    jobs = r["jobs"]
    has_test = "test" in jobs
    if has_test and "steps" in jobs["test"]:
        parity = "inline-match" if jobs["test"]["steps"] == t["jobs"]["test"]["steps"] else "inline-DRIFT"
    elif has_test:
        parity = "reused:" + str(jobs["test"].get("uses"))
    else:
        parity = "no-test-job"
    return " | ".join([
        f"test.yml-tag-trigger={test_tag_trigger}",
        f"release-on-tags={(ron.get('push') or {}).get('tags')}",
        f"release-test-job={has_test}",
        f"goreleaser-needs={jobs.get('goreleaser', {}).get('needs')}",
        parity,
    ])

# each dir holds a release.yml + test.yml copied verbatim out of git
for v in ("base", "head", "fixed"):
    print(f"{v}: {outcome(os.path.join(sys.argv[1], v))}")

Save that as poc_2_release_gate.py, then build the three variants from git and run it. This
block is copy-pasteable from the repo root and was run as-is to produce the output above:

git fetch origin pull/2/head:pr-2-review
mkdir -p poc/base poc/head poc/fixed
for f in release test; do
    git show master:.github/workflows/$f.yml      > poc/base/$f.yml
    git show pr-2-review:.github/workflows/$f.yml > poc/head/$f.yml
done

# `fixed` = head with the F1 refactor applied
sed 's|^  pull_request:$|  pull_request:\
  workflow_call:|' poc/head/test.yml > poc/fixed/test.yml
awk '/^  test:$/{print "  test:"; print "    uses: ./.github/workflows/test.yml"; skip=1; next}
     skip && /^  goreleaser:$/{skip=0}
     !skip{print}' poc/head/release.yml > poc/fixed/release.yml

pip install pyyaml
python3 poc_2_release_gate.py poc

To reproduce the actionlint half, give each variant a real workflow layout — otherwise
actionlint cannot resolve the uses: ./.github/workflows/test.yml path and its clean exit
means nothing:

for v in head fixed; do
    mkdir -p poc/$v/.github/workflows && cp poc/$v/*.yml poc/$v/.github/workflows/
    (cd poc/$v && go run github.com/rhysd/actionlint/cmd/actionlint@latest)
done

The gofmt exit-code point in F1 stands alone:

bash -c 'gofmt -l /nonexistent | tee /tmp/fmt.out && test ! -s /tmp/fmt.out'; echo $?   # 0
bash -c 'set -o pipefail
         gofmt -l /nonexistent | tee /tmp/fmt.out && test ! -s /tmp/fmt.out'; echo $?   # 2
bash -c 'test -z "$(gofmt -l /nonexistent)"'; echo $?                                   # 0

Caveats, so nobody over-reads this: the harness models the workflow graph, not GitHub's
scheduler. It establishes that goreleaser declares a dependency on a test job and that
test.yml cannot be triggered by a tag — it does not prove that a failing test job actually
blocks goreleaser at runtime, which is documented GitHub behaviour rather than something
verified here. It also does not model branch protection, GITHUB_TOKEN scoping, or goreleaser
itself. F2 is source-read only. Nothing was tagged, pushed, or published during this review,
and the working tree was not switched to the PR branch — the head was read via
git fetch origin pull/2/head:pr-2-review and git show.

F1 [should-fix] — the test job in release.yml was a verbatim copy of
test.yml's, with nothing keeping them in sync; the next change to the
CI recipe would land in test.yml (what people see on PRs) and
release.yml would silently start gating releases on a weaker check.
Added `workflow_call:` to test.yml's triggers and replaced the inline
job in release.yml with `uses: ./.github/workflows/test.yml`, so
there is exactly one copy. Also folded in the related point: the
gofmt step's `| tee ... && test ! -s ...` pipeline reported the exit
code of `tee`, not `gofmt`, and GitHub Actions runs unspecified-shell
`run:` steps as `bash -e {0}` without `-o pipefail` — a gofmt crash
(not just files needing formatting) would have passed silently.
Confirmed the gap and the fix locally:

    $ bash -c 'gofmt -l /nonexistent | tee /tmp/fmt.out && test ! -s /tmp/fmt.out'; echo $?
    0
    $ bash -o pipefail -c 'gofmt -l /nonexistent | tee /tmp/fmt.out && test ! -s /tmp/fmt.out'; echo $?
    2

Fixed by naming the step and adding `shell: bash`, which GitHub runs
as `bash --noprofile --norc -eo pipefail {0}` — confirmed this is the
actual documented difference (unspecified vs. explicit `shell: bash`),
not an assumption.

F2 [nit] — `contents: write` was declared at workflow level, so it
applied to the new `test` job too (arbitrary project/dependency code
running with a token that can push and create releases), when only
`goreleaser` needs it. Moved to the `goreleaser` job only; `test` now
inherits the default `contents: read`.

Verified `actionlint` clean against both files in place (not a copy),
confirming `uses: ./.github/workflows/test.yml` actually resolves.

go build/vet/test/gofmt clean.
@unidoc-ahall

Copy link
Copy Markdown
Contributor Author

Addressed both.

F1 [should-fix] — confirmed the drift risk and took the workflow_call refactor as suggested: test.yml gained the trigger, release.yml's inline job became uses: ./.github/workflows/test.yml. Also folded in the gofmt pipefail point — reproduced it locally (tee's exit code masks gofmt's, and GitHub's unspecified-shell run: really does omit -o pipefail, confirmed against current docs, not assumed), fixed with shell: bash on that step per your simpler suggestion. actionlint clean against the files in place, confirming the uses: path resolves for real. Branch-protection isn't affected — test.yml keeps its own direct push/pull_request triggers, so PR checks still surface as plain test; the test / test naming only applies to the tag-triggered call from release.yml, which branch protection never looked at.

F2 [nit] — confirmed, moved contents: write down to the goreleaser job only.

go build/vet/test/gofmt clean.

@unidoc-alip

Copy link
Copy Markdown
Collaborator

Verdict: COMMENT — 0 must-fix, 1 should-fix (F2, reopened), 0 nits

Re-review of 75301f4 ("Address review (F1 should-fix, F2 nit)") against the previous review
of b281142. F1 is fully fixed and the reasoning in the reply is correct on every point.
F2 is not fixed — it regressed
, and in the opposite direction from the one intended.
Keeping the original F1/F2 keys so they map to the earlier comment.


F1 [resolved] — workflow_call refactor and the gofmt pipefail fix both land correctly

test.yml gained workflow_call:, release.yml's inline job collapsed to
uses: ./.github/workflows/test.yml, and the duplication is gone. Re-ran the same
three-variant assertion harness with 75301f4 as the fixed variant:

[PASS] base:  … | release-test-job=False | goreleaser-needs=None | no-test-job
[PASS] head:  … | release-test-job=True  | goreleaser-needs=test | inline-match
[PASS] fixed: … | release-test-job=True  | goreleaser-needs=test | reused:./.github/workflows/test.yml

actionlint is clean on the real files under a git init-ed .github/workflows/ layout, so
the uses: path genuinely resolves — the earlier run I reported as clean had in fact been
skipping project detection, which the reply's own "in place" check caught independently.

The gofmt fix is now observed, not just documented. From the 75301f4 run log
(run 33621297772):

##[group]Run gofmt -l . | tee /tmp/fmt.out && test ! -s /tmp/fmt.out
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}

-o pipefail is present, so gofmt's own exit code is no longer masked by tee's.

The branch-protection reasoning in the reply is also correct, and I checked it rather than
taking it on faith: the active ruleset master-protection (id 22029519) requires exactly one
status check context, test, and the check on 75301f4 is named test. Because test.yml
kept its direct push/pull_request triggers, PR checks still surface under that plain name;
the test / test prefixing applies only to the tag-triggered call from release.yml, which
the ruleset never inspected. No action needed.

F2 [should-fix] .github/workflows/release.yml line 7 — deleting the permissions block widened the test job's token from 1 write scope to 17

The reply describes this as "moved contents: write down to the goreleaser job only." The
goreleaser half is right. The other half is that the workflow-level block was deleted
rather than set to contents: read, and in GitHub Actions those are not the same thing:
omitting permissions: entirely does not mean read-only, it means fall back to the
repository's default GITHUB_TOKEN permissions
. This repository's default is the permissive
one. From the same run log:

##[group]GITHUB_TOKEN Permissions
Actions: write        ArtifactMetadata: write   Attestations: write
Checks: write         CodeQuality: write        Contents: write
CopilotRequests: write Deployments: write       Discussions: write
Drives: write         Issues: write             Packages: write
Pages: write          PullRequests: write       RepositoryProjects: write
SecurityEvents: write Statuses: write

Seventeen write scopes. Compare that with the state at b281142: declaring any scope in a
permissions: block sets every unspecified scope to none, so the inline test job there had
contents: write and nothing else. The change made in the name of least privilege therefore
took the test job — which runs go build, go vet and go test ./..., i.e. arbitrary project
and dependency code — from one write scope to seventeen, including Packages: write and
Actions: write.

Evidence labelling, so this isn't over-read: the log above is from test.yml triggered by
pull_request on this PR. That path never had a permissions: block and is pre-existing, not
something this PR caused. The release.yml uses: job on a tag push has still never executed
— no tag was pushed during this review. The claim that it lands on the same 17-scope default is
an inference, but a direct one: the caller job declares no permissions:, release.yml now
declares none at workflow level, so the same fallback applies.

The load-bearing fix is to restore the workflow-level block in release.yml as read rather
than removing it. Per GitHub's reusable-workflow docs, permissions "can only be maintained or
reduced — not elevated — throughout the chain", so the caller sets the ceiling for the called
workflow:

on:
  push:
    tags:
      - "v*"

permissions:
  contents: read      # ceiling for the whole workflow, incl. the called test.yml

jobs:
  test:
    uses: ./.github/workflows/test.yml

  goreleaser:
    needs: test
    permissions:
      contents: write # job-level grant, still within the repo default

Worth adding the same two lines to test.yml as well, at workflow level. That reduces within
the chain and, more usefully, covers the direct push/pull_request triggers — which is where
the 17-scope token was actually observed, and which release.yml alone cannot reach. It also
fixes it once in the file both paths share, matching F1's reasoning. goreleaser's job-level
contents: write is sufficient for this .goreleaser.yaml: no Docker, Homebrew or package
publishing, and changelog: use: github only reads.

Both files with those blocks added pass actionlint cleanly under a real workflow layout.

There is a repo-settings alternative — flipping the default GITHUB_TOKEN permission to
read-only in Actions settings — which would fix this class of problem across every workflow at
once. It is the better long-term move, but it belongs in its own change, not this PR, and it
would silently break any workflow relying on the wide default.


Reply verification

  • "took the workflow_call refactor as suggested" — confirmed. Diff b281142..75301f4 shows exactly the suggested shape in both files.
  • "reproduced it locally … GitHub's unspecified-shell run: really does omit -o pipefail, confirmed against current docs, not assumed" — confirmed, and now confirmed on the run itself, which is stronger than either of us had: the step header prints -e -o pipefail after the fix.
  • "actionlint clean against the files in place, confirming the uses: path resolves for real" — confirmed, and this corrected my own earlier check, which had been passing vacuously.
  • "Branch-protection isn't affected … PR checks still surface as plain test" — confirmed against ruleset 22029519 (required context test) and the check name on 75301f4 (test).
  • "moved contents: write down to the goreleaser job only" — partially confirmed. The goreleaser job-level grant is correct. The workflow-level block was removed rather than downgraded, which is what F2 above is about.
  • "go build/vet/test/gofmt clean" — confirmed. The test check on 75301f4 passed in 28s.

Appendix — commands used for this pass

git fetch -f origin pull/2/head:pr-2-review
git diff b281142 pr-2-review

# token scopes and shell, observed on the run for 75301f4
gh run view 33621297772 --repo unidoc/incus-sync --log | grep -A20 'GITHUB_TOKEN Permission'
gh run view 33621297772 --repo unidoc/incus-sync --log | grep -A3 'Run gofmt'

# the branch-protection claim
gh api repos/unidoc/incus-sync/rulesets/22029519 \
    --jq '.rules[] | select(.type=="required_status_checks") | .parameters.required_status_checks'
gh api repos/unidoc/incus-sync/commits/75301f4/check-runs --jq '.check_runs[] | .name'

# actionlint needs a git repo and a real layout, or it skips silently
mkdir -p v/.github/workflows
for f in release test; do git show pr-2-review:.github/workflows/$f.yml > v/.github/workflows/$f.yml; done
(cd v && git init -q . && go run github.com/rhysd/actionlint/cmd/actionlint@latest)

The three-variant YAML harness is unchanged from the previous review comment; only the fixed
directory was repopulated from 75301f4.

Caveats: as before, this models the workflow graph and the observed PR-triggered run, not the
tag path, which has still never executed. Nothing was tagged, pushed or published, and the
working tree was not switched to the PR branch.

Same bug fixed in age-plugin-sshagent's release-pr: writing
version.txt unconditionally and committing means a bump to a version
version.txt already carries (true for this repo's own pending 0.1.0
release) is a no-op — git commit exits 1, set -euo pipefail aborts
after the release branch is already checked out, and the recipe
leaves you stranded on a stray local branch with no PR opened.

Fixed with a guard right after git fetch: refuse with a clear message
("nothing to bump; run: just release VERSION") before touching
anything, plus a trap that returns to master and deletes the stray
branch on any later failure, so the recipe is re-runnable.

Verified with the same PoC methodology used for age-plugin-sshagent's
fix: a scratch clone against a local bare origin, gh stubbed. Refusal
case (release-pr 0.1.0, matching master's current version.txt) exits
1 and stays on master with no stray branch; normal-bump case
(release-pr 0.2.0) commits, pushes, and opens the PR as expected.

Practical effect for today's first release: `just release-pr 0.1.0`
would have hit this immediately, since version.txt already carries
0.1.0. The first release skips release-pr entirely — merge this PR,
then run `just release 0.1.0` directly. release-pr is exercised for
real starting with the next bump (0.1.1+).
@unidoc-ahall

Copy link
Copy Markdown
Contributor Author

Also pushed a second, unrelated fix while getting ready to cut today's release: Justfile's release-pr had the identical F1 bug your age-plugin-sshagent review caught (no guard for "nothing to bump"), which would have bitten the very next version bump here too. Same fix, verified with the same PoC methodology. Flagging for visibility rather than asking for re-review — it's a direct copy of an already-reviewed-and-approved fix.

The previous fix for F2 (contents:write scoped too broadly) deleted
release.yml's workflow-level permissions block instead of downgrading
it to read. Per GitHub's reusable-workflow docs, permissions can only
be reduced through a workflow_call chain, never elevated — the caller
sets the ceiling. Omitting the block entirely does not mean read-only,
it falls back to the repository's default GITHUB_TOKEN permissions,
which this repo has set permissively (confirmed from the actual
workflow run: 17 write scopes, not 1).

Restored `permissions: contents: read` at workflow level in
release.yml (ceiling for both jobs, including the called test.yml),
and added the same to test.yml per the review's suggestion — that
also covers test.yml's own direct push/pull_request triggers, which
release.yml's ceiling alone can't reach and which is where the
17-scope token was actually observed. goreleaser's existing job-level
`contents: write` grant is unaffected — a job-level grant can only
narrow further within the workflow ceiling, and read->write within the
same scope the ceiling already allows is not an elevation.

Verified: actionlint clean on both files in place, go build/vet/test/
gofmt clean.
@unidoc-ahall

Copy link
Copy Markdown
Contributor Author

F2 [should-fix, reopened] — confirmed exactly as described, and confirmed against your run-log evidence (17 write scopes is a real problem, and a worse one than the original nit). My mistake was deleting the workflow-level block rather than downgrading it — I hadn't internalized that omitted ≠ read-only for GITHUB_TOKEN. Fixed as you specified: permissions: contents: read restored at workflow level in release.yml (ceiling for both jobs), and added the same to test.yml since that's where the wide token was actually observed on the direct push/pull_request path, not just the workflow_call path. goreleaser's job-level contents: write grant is unaffected.

actionlint clean on both files in place, go build/vet/test/gofmt clean.

Thanks for catching this with the actual run log rather than just the diff — I would not have caught the "deleted vs. downgraded" distinction from reading the YAML alone.

unidoc-alip
unidoc-alip previously approved these changes Sep 2, 2026

@unidoc-alip unidoc-alip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE — 0 must-fix, 1 should-fix (F3, new, non-blocking), 1 nit (F4, new)

Re-review of 49e4b00. F2 is fixed exactly as specified and I have nothing further on it —
that thread is closed.
The subject of this PR — the release test gate and the permissions
ceiling — is correct and verified, so this is an approval.

Two new findings, both against a36f8af, an unrelated Justfile change that arrived in the
same push and wasn't mentioned in the reply. F3 is a real reproduction, not a reading: the trap
added to make release-pr re-runnable makes it permanently un-re-runnable at the one failure
point that matters most. I'm not blocking on it, because it cannot bite the release this PR is
clearing the way for: version.txt on master is already 0.1.0 and no tags exist, so
a36f8af's own new guard refuses release-pr 0.1.0 by design and today's path is
just release 0.1.0 directly. F3 first becomes reachable at 0.1.1. Please fix it before
then, in this PR or a follow-up. Continuing the F1/F2 keys from the earlier comments.


F2 [resolved] — permissions ceiling restored correctly in both files

permissions: contents: read at workflow level in release.yml (ceiling for both jobs,
including the called workflow), the same in test.yml (covering the direct
push/pull_request triggers where the wide token was actually observed), goreleaser's
job-level contents: write untouched. That is the shape I proposed and the reasoning in the
comments on both blocks is accurate. actionlint clean on both files under a real
.github/workflows/ layout at 49e4b00.

F3 [should-fix] Justfile line 89 — the new trap wedges release-pr permanently if gh pr create fails

a36f8af's stated goal is "so the recipe is re-runnable." For the failure the trap was added
to handle it achieves the opposite, and this is a regression against the behaviour before the
commit.

The trap is armed before git checkout -b and disarmed only after gh pr create succeeds. So
it is still armed across git push -u origin, which means the window it covers includes the
point where the remote branch already exists. If gh pr create fails there — expired auth, an
API blip, a PR already open — the trap deletes the local branch and leaves the remote
one. Every subsequent run then dies on a non-fast-forward push, because the fresh local commit
has a different SHA from the pushed one, and the trap deletes the local branch again. The
recipe cannot recover on its own.

Reproduced against 49e4b00's Justfile in a scratch clone with a local bare origin and gh
stubbed to fail (harness in the appendix):

=== CASE B: bump 0.2.0, gh pr create FAILS ===
gh: stub failing for pr create --title Release v0.2.0 ...
Deleted branch release/v0.2.0 (was 585e159).
local  =[master ]
remote =[master release/v0.2.0 ]

=== CASE B2: re-run the same command ===
error: failed to push some refs to '.../origin.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g. 'git pull ...')
Deleted branch release/v0.2.0 (was a657e82).
local  =[master ]
remote =[master release/v0.2.0 ]

Note the second run is identical to the first — this repeats forever. The error surfaced is
git's, not the recipe's, and its git pull hint is actively misleading: following it would
merge the release branch's history into whatever you are on. Recovery requires knowing to run
git push -d origin release/v0.2.0 by hand, which nothing tells you.

Before a36f8af, the same gh failure left you standing on the pushed local branch, where
gh pr create by hand finished the job. Loud failure, no data loss, one-command recovery —
which is why this is should-fix rather than must-fix — but the fix inverted it.

Two changes fix it. Disarm the trap at the point of no return rather than at the end, and give
the failure a recovery hint:

    git push -u origin "release/v{{VERSION}}"
    trap - EXIT   # past the point of no return: the remote branch exists, keep the local one
    gh pr create --title "Release v{{VERSION}}" \
        --body "..." \
        || { echo "✗ branch pushed but PR creation failed — finish with: gh pr create --head release/v{{VERSION}}"; exit 1; }

and guard the remote branch alongside the new version.txt guard, so a re-run explains itself
instead of handing you a git hint:

    git ls-remote --exit-code --heads origin "release/v{{VERSION}}" >/dev/null 2>&1 && \
        { echo "✗ release/v{{VERSION}} already on origin — open the PR with: gh pr create --head release/v{{VERSION}} (or delete it: git push -d origin release/v{{VERSION}})"; exit 1; }

Deliberately not deleting the remote branch in the trap: a PR may already be attached to it,
and a cleanup path that deletes pushed work is worse than the wedge.

I ran that variant through all four cases:

FIXED / CASE B : ✗ branch pushed but PR creation failed — finish with: gh pr create --head release/v0.2.0
                 ended-on=release/v0.2.0, local=[master release/v0.2.0], remote=[master release/v0.2.0]
FIXED / CASE B2: ✗ release/v0.2.0 already on origin — open the PR with: gh pr create --head ... (or delete it: git push -d origin ...)
FIXED / CASE A : ✗ version.txt on master is already 0.1.0 — nothing to bump; run: just release 0.1.0
FIXED / CASE D : ✓ release PR opened — ended-on=release/v0.2.0 commits=1 version=0.2.0 remote has the branch

The new version.txt guard and the happy path are both unaffected.

F4 [nit] a36f8af is unannounced scope in a workflow-permissions PR

The PR is titled "release.yml: gate goreleaser on tests passing" and its description covers
only that. a36f8af changes release-pr, which is release-critical tooling, and it is not in
the description or in the reply. It is a real bug with a good fix — the guard works exactly as
the commit message claims, verified below — so this is about visibility, not merit: either
extend the PR description to cover it, or split it into its own PR. Worth doing today given
0.1.0 is imminent. (No documentation impact: grep -rn 'release-pr' README.md docs/ returns
nothing, so the commit message's "the first release skips release-pr entirely" contradicts
no written instructions.)


Reply and commit-message verification

  • "permissions: contents: read restored at workflow level in release.yml (ceiling for both jobs)" — confirmed in the diff, with an accurate explanatory comment.
  • "added the same to test.yml since that's where the wide token was actually observed" — confirmed, and this is the right call for the reason given.
  • "goreleaser's job-level contents: write grant is unaffected" — confirmed.
  • "actionlint clean on both files in place" — confirmed independently at 49e4b00 under a git init-ed layout.
  • a36f8af: "refuse with a clear message before touching anything" — confirmed. just release-pr 0.1.0 against a master already at 0.1.0 exits 1, prints the intended message, and leaves you on master with no stray branch and a clean tree.
  • a36f8af: "plus a trap that returns to master and deletes the stray branch on any later failure, so the recipe is re-runnable" — partially confirmed, and this is F3. The return-to-master and branch-deletion both work. "Re-runnable" holds only for failures before git push; after the push it is the opposite.
  • a36f8af: "normal-bump case (release-pr 0.2.0) commits, pushes, and opens the PR as expected" — confirmed. One commit Release v0.2.0, version.txt = 0.2.0, remote branch created, gh pr create invoked, trap correctly disarmed so the branch survives and you are left on it.
  • PR description as of 49e4b00 — incomplete. Still describes only the release.yml test gate; covers neither the permissions work nor a36f8af.

Appendix — the release-pr harness

Scratch clone against a local bare origin with gh stubbed. Touches no network and no real
remote. Run from anywhere:

W=$(mktemp -d); mkdir -p $W/stub
git init -q --bare $W/origin.git
git init -q $W/seed && cd $W/seed
git config user.email t@t && git config user.name t
git -C /path/to/incus-sync show pr-2-review:Justfile > Justfile
echo "0.1.0" > version.txt
git add -A && git commit -qm init && git branch -M master
git remote add origin $W/origin.git && git push -q -u origin master
cd $W && git clone -q origin.git work && cd work
git config user.email t@t && git config user.name t

# gh stub — flip between failing and succeeding to select the case
printf '#!/bin/sh\necho "gh: stub failing" >&2\nexit 1\n' > $W/stub/gh && chmod +x $W/stub/gh

# CASE A  guard:      no-op bump is refused
PATH=$W/stub:$PATH just release-pr 0.1.0
# CASE B  the bug:    gh fails after push -> local deleted, remote survives
PATH=$W/stub:$PATH just release-pr 0.2.0
git branch; git --git-dir=$W/origin.git branch
# CASE B2 the wedge:  re-run dies on non-fast-forward, forever
PATH=$W/stub:$PATH just release-pr 0.2.0
# CASE D  happy path: swap the stub to exit 0 first
printf '#!/bin/sh\necho "gh: (stub) PR created"\n' > $W/stub/gh && chmod +x $W/stub/gh

One harness artifact worth flagging, since it cost me a run: when testing the fixed variant,
editing Justfile in the clone makes the tree dirty and the recipe's own clean-tree check
fires first, so every case fails with "working tree not clean" rather than exercising the
change. Commit the edit in the scratch clone before running.

Caveats: the harness models the local git and gh invocation sequence only. It does not model
GitHub-side PR creation, protected-branch push rejection, or auth. It establishes what the
recipe does locally up to and past the point of failure, which is where F3 lives. The
workflow-file half of this review is unchanged from the previous pass: the tag path has still
never executed, and nothing was tagged, pushed or published. The working tree of the real repo
was not switched to the PR branch.

a36f8af's trap was armed before git checkout -b and disarmed only
after gh pr create succeeded — still armed across git push, so a
failure in gh pr create (expired auth, an API blip, a PR already
open) deleted the local release branch while the remote one, already
pushed, survived. Every re-run then either died on a non-fast-forward
push (different commit SHA, same branch name) or silently produced
"Everything up-to-date" while deleting the local branch again — no
path forward without knowing to run `git push -d origin
release/vX.Y.Z` by hand first. The trap's stated goal was making the
recipe re-runnable; for this exact failure it was the opposite,
permanently so.

Reproduced against the actual bug first (scratch clone, local bare
origin, gh stubbed to fail after a real push succeeds): local branch
deleted, remote branch orphaned, identical on every retry.

Fixed as suggested: disarm the trap right after the push succeeds
(the actual point of no return — the remote branch exists from here
on, so deleting the local one is harmless but recreating it isn't),
and give a failed gh pr create a direct recovery hint instead of
relying on the trap. Also added a remote-branch-exists guard next to
the version.txt guard, so a re-run after a failure explains itself
("already on origin — finish with...") instead of surfacing a
confusing git-level rejection.

Re-ran all four cases from the review's own harness against the
actual fixed Justfile: no-op-bump refusal, gh-fails-after-push
(branch survives, clear message), re-run-after-that (clean guard
message, no git error), and the normal happy path — all four match
the review's expected output exactly.

Same bug existed in age-plugin-sshagent's Justfile (same trap,
copied from here originally) — fixed there too in a separate PR,
since #1 there is already merged.

go build/vet/test/gofmt clean.
@unidoc-ahall

Copy link
Copy Markdown
Contributor Author

F3 [should-fix] — confirmed exactly as described, and reproduced it first against the actual bug (scratch clone, local bare origin, gh stubbed to fail after a real push): local branch deleted, remote branch orphaned, every retry either non-fast-forwards or silently no-ops while deleting the branch again. Fixed exactly as suggested — trap disarms right after the push succeeds instead of after gh pr create, a failed gh pr create now gives a direct recovery command instead of relying on the trap, and added the remote-branch-exists guard so a re-run explains itself. Ran your own four-case harness against the fixed Justfile: no-op-bump refusal, gh-fails-after-push, re-run-after-that, and the happy path all match your expected output.

Also fixed the identical bug in age-plugin-sshagent's Justfile (same trap, originally copied from there to here) — separate PR, since #1 there is already merged.

F4 [nit] — fair, updated the PR description to actually cover the Justfile work instead of just the original release.yml scope.

go build/vet/test/gofmt clean.

@unidoc-alip unidoc-alip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE — 0 must-fix, 0 should-fix, 0 nits. F1–F4 all resolved.

Re-review of ce50055 against the F3/F4 review of 49e4b00. Both are fixed, and the reply's
claims check out on every point I could verify in this repo.

F3 [resolved] — release-pr no longer wedges after a failed gh pr create

ce50055 implements all three suggested changes, verbatim and with nothing omitted:

  • trap - EXIT moved to immediately after git push -u origin, i.e. the actual point of no
    return, instead of after gh pr create.
  • gh pr create gained the || { echo "✗ branch pushed but PR creation failed — finish with: gh pr create --head release/v{{VERSION}}"; exit 1; } recovery hint.
  • The git ls-remote --exit-code --heads guard sits alongside the version.txt guard, before
    anything is touched.

The trap still deliberately does not delete the remote branch, which is the right call for the
reason given in the earlier review — a PR may already be attached to it.

I re-ran the four-case harness from scratch against the real ce50055 Justfile (own bare
origin, own gh stub, Justfile committed in the scratch clone so the recipe's clean-tree
check doesn't pre-empt the cases). All four match the expected output, including the
ending-branch detail:

CASE B  ✗ branch pushed but PR creation failed — finish with: gh pr create --head release/v0.2.0
        ended-on=release/v0.2.0  local=[master release/v0.2.0]  remote=[master release/v0.2.0]
CASE B2 ✗ release/v0.2.0 already on origin — open the PR with: gh pr create --head … (or delete it: git push -d origin …)
        no non-fast-forward, no git-level error
CASE A  ✗ version.txt on master is already 0.1.0 — nothing to bump; run: just release 0.1.0
CASE D  ✓ release PR opened — gh invoked, one commit, remote branch created, left on the branch

Case B2 is the load-bearing one: it previously repeated the wedge indefinitely and surfaced
git's misleading git pull hint; it now exits on the recipe's own message before touching git.

F4 [resolved] — PR description now covers the Justfile work

The description names both Justfile changes and the permissions ceiling, and the
title-vs-scope gap is closed by the "grew during review into the full release-tooling pass"
framing. The test plan also carries the operationally useful note that 0.1.0 ships via
just release 0.1.0 directly, so release-pr's guards are first exercised for real at
0.1.1.

F1 / F2 — still correct at head

workflow_call dedup and the gofmt pipefail fix are unchanged, and 49e4b00's permissions
ceiling is intact: permissions: contents: read at workflow level in both release.yml and
test.yml, goreleaser's job-level contents: write untouched.

Reply verification

  • "Fixed exactly as suggested — trap disarms right after the push … recovery command … remote-branch-exists guard" — confirmed, all three, verbatim.
  • "Ran your own four-case harness … all match your expected output" — confirmed independently, output above.
  • "reproduced it first against the actual bug" — consistent; the commit message matches the failure mode demonstrated in the previous review. I re-ran only the fixed variant this pass, not the broken one.
  • "go build/vet/test/gofmt clean" — confirmed; the test check on ce50055 is green.
  • "Also fixed the identical bug in age-plugin-sshagent's Justfile — separate PR" — unverified, out of this repo; not looked at.

Caveats unchanged from the previous passes: the harness models the local git and gh
invocation sequence only, not GitHub-side PR creation, auth or protected-branch rejection. The
tag path in release.yml has still never executed — nothing was tagged, pushed or published,
and the working tree of the real repo was not switched to the PR branch.

Ship it. For the first release, merge and then run just release 0.1.0 directly, as the test
plan says.

@unidoc-ahall
unidoc-ahall merged commit 7e53a02 into master Sep 2, 2026
1 check passed
@unidoc-ahall
unidoc-ahall deleted the fix-release-test-gate branch September 2, 2026 12:57
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.

2 participants