Skip to content

Check GitHub push permissions before every release - #86

Merged
dblock merged 1 commit into
dblock/check-trusted-publishingfrom
dblock/check-github-permissions
Nov 20, 2026
Merged

dblock merged 1 commit into
dblock/check-trusted-publishingfrom
dblock/check-github-permissions

Conversation

@dblock

@dblock dblock commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Stacked on #85.

Summary

Extends the per-release preflight from #85 with GitHub checks, so a token that cannot push the release fails before anything is published. Today the release publishes the gem before pushing Git, so a rejected push left a published gem without its tag or release commit.

  • Write access: git push --dry-run --porcelain origin HEAD:refs/heads/<default>. GitHub requires push access to start a push, so this fails without contents: write; a dry run sends no objects and changes no refs.
  • Repository rules: reads rules/branches/<default> and tag rulesets matching refs/tags/vVERSION (including organization rulesets). Branch rules requiring pull requests, status checks, signed commits, deployments, a merge queue, or restricting updates, and tag rules restricting creation or requiring signatures, fail the preflight with the ruleset name, unless the ruleset reports current_user_can_bypass as always or exempt.
  • Classic branch protection: not readable without admin access, so a protected default branch produces a warning instead of a failure.
  • The tag name comes from INPUT_VERSION or the captured GEMSPEC_VERSION; without either, tag rules are skipped. The checks run only on GitHub Actions.
  • The preflight step gets GH_TOKEN in both interfaces. The dry-run job now also captures the release context (default branch, clean and current checkout, version) and keeps checkout credentials so git push --dry-run can authenticate. Its environment matches the release job's.
  • The integration fixture's gh api stub now answers only release endpoints, so the new rules requests see a realistic 404.

Limits, documented: tag-rule matching uses File.fnmatch against GitHub's include/exclude patterns, and rules that only constrain metadata (commit message or author patterns) are not evaluated.

Validation

  • PARALLEL_TEST_PROCESSORS=4 bundle exec rake (460 examples, 0 failures; RuboCop no offenses) and actionlint. The composite and workflow integration suites run the new check against their local remote.
  • New specs cover push-access failure, branch rules blocked or bypassed or irrelevant, tag rulesets matched, excluded, bypassed, or in evaluate mode, unknown tags, the protection warning, and preflight tag selection. Both new files are fully covered.
  • Not validated: a real Actions run against GitHub's rules API with the job token.

Authored by an AI (Claude) acting on behalf of @dblock.

🤖 Generated with Claude Code

https://claude.ai/code/session_011Gr21hZDQo5axDMuFgzL6s

Add Workflow::GitHubPermissions to the preflight on GitHub Actions. It
runs git push --dry-run to the default branch, which fails without
contents: write while sending no objects, then reads the repository
rules for the default branch and the vVERSION tag. Rules that would
reject the release push fail unless the ruleset reports the token can
bypass it; classic branch protection, which needs admin access to read,
produces a warning.

The preflight step receives GH_TOKEN in both interfaces. The dry-run
job now captures the release context and keeps checkout credentials so
it can check the same branch, tag, and push access as a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Gr21hZDQo5axDMuFgzL6s
@dblock
dblock added this pull request to stack #87 November 20, 2026 23:02
@dblock
dblock merged commit 14f5e32 into master Nov 20, 2026
11 checks passed
@dblock
dblock deleted the dblock/check-github-permissions branch November 20, 2026 23:12
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.

1 participant