Skip to content

fix: harden release-guard workflow and prevent race condition#4776

Closed
bryanbeverly wants to merge 7 commits intotrufflesecurity:mainfrom
bryanbeverly:fix/release-guard-gh-repo
Closed

fix: harden release-guard workflow and prevent race condition#4776
bryanbeverly wants to merge 7 commits intotrufflesecurity:mainfrom
bryanbeverly:fix/release-guard-gh-repo

Conversation

@bryanbeverly
Copy link
Copy Markdown
Contributor

@bryanbeverly bryanbeverly commented Feb 27, 2026

Summary

  • The release-guard.yml workflow's unset-latest job fails because the gh CLI cannot infer the repository — there is no actions/checkout step and no GH_REPO env var, so gh falls back to looking for a local .git directory which doesn't exist.
  • This adds GH_REPO: ${{ github.repository }} to the step's environment so gh knows which repo to target without needing a checkout.
  • In release.yml, the "Mark release as latest" step now passes github.ref_name through an env var instead of interpolating it directly into the shell command.
  • The guard now checks the Release workflow run status before acting: if the pipeline already succeeded for this tag, the guard skips — preventing a race where a delayed guard run could revert a legitimate release. If the pipeline failed or never ran (manual release), the guard proceeds normally.
  • Adds actions: read permission so the guard can query workflow run status.
  • Event context (release.tag_name) is also passed through an env var for consistency.

Failed run: https://github.com/trufflesecurity/trufflehog/actions/runs/22491672284

Test plan

  • Verify both workflow files are valid YAML
  • Create a test release to confirm the workflows pass with the fixes

Note

Medium Risk
Changes release automation logic and GitHub Actions permissions; mistakes could incorrectly mark/unmark a release as latest or block releases.

Overview
Prevents the release-guard workflow from incorrectly undoing a legitimate latest release by first checking whether the release.yml workflow run for the tag already succeeded, and skipping the guard in that case.

Hardens gh CLI usage by explicitly setting GH_REPO/RELEASE_TAG env vars (no checkout required) and adding actions: read permission so the guard can query workflow runs; release.yml also switches to passing the tag via TAG env var when marking the release as latest.

Written by Cursor Bugbot for commit c685900. This will update automatically on new commits. Configure here.

The `gh` CLI commands fail with "fatal: not a git repository" because
the workflow never checks out the repo and gh cannot infer the
repository context. Setting GH_REPO avoids the need for a checkout step.

Fixes the failure in: https://github.com/trufflesecurity/trufflehog/actions/runs/22491672284

Made-with: Cursor
@bryanbeverly bryanbeverly requested a review from a team February 27, 2026 16:01
Use an intermediate environment variable for github.ref_name instead
of interpolating it directly into the shell command.

Made-with: Cursor
Check the Release workflow run status before deciding to unset latest.
If the pipeline completed successfully for this tag, the latest flag was
set intentionally and the guard should not undo it. This prevents a race
where a delayed guard run could revert a legitimate release.

Also passes event context through env vars and adds actions:read
permission for gh run list.

Made-with: Cursor
@bryanbeverly bryanbeverly changed the title fix: add GH_REPO env to release-guard workflow fix: harden release-guard workflow and prevent race condition Feb 27, 2026
Comment thread .github/workflows/release-guard.yml Outdated
bryanbeverly and others added 4 commits March 6, 2026 16:37
@bryanbeverly
Copy link
Copy Markdown
Contributor Author

Closed, replaced by #4838

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