fix(auto-revert): handle workflow-file commits instead of failing on them - #84
Merged
Merged
Conversation
…them auto-revert pushes with GITHUB_TOKEN, which GitHub categorically forbids from creating or updating anything under .github/workflows/. `workflows` is not among the grantable `permissions:` scopes, so this was never a misconfiguration anyone could correct -- the capability does not exist for that token. The failure mode was poor. The push was rejected only after the revert commit had been made, so the job died with refusing to allow a GitHub App to create or update workflow .github/workflows/ci.yml without `workflows` permission which reads like a setup error, and buried the CI failure it was reacting to under a second red check. Now the job detects the case before committing and opens an issue instead, so the regression is still surfaced loudly and the check stays green. Callers need `issues: write`; the example stub is updated. Two latent bugs surfaced while fixing it. The path check must diff against the first parent: `git diff-tree -r <sha>` lists nothing for a merge commit, and the bad SHA is usually a merge, so the naive check would never have fired on the case that matters. And it follows that auto-revert has never once succeeded against a workflow-file regression in any consumer. For full automation, `revert-app-client-id` plus a `REVERT_APP_PRIVATE_KEY` secret mints a scoped installation token with permission-workflows: write and pushes with that. Both optional; unset keeps today behaviour plus the issue fallback. The docs call for a dedicated App rather than reusing deps-reader, which is deliberately contents:read only -- a credential that can rewrite workflow files can rewrite CI itself. Verified: actionlint clean; the run: block extracted and shellcheck -S warning clean; the heredoc rendered and its output inspected; diff-vs-first-parent checked against a real merge commit, where diff-tree -r returns 0 paths and diff <sha>^1 <sha> correctly returns .github/workflows/ci.yml. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EoicTZniGXry3W7YFZBsSM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
auto-revert pushes with GITHUB_TOKEN, which GitHub categorically forbids from
creating or updating anything under .github/workflows/.
workflowsis not amongthe grantable
permissions:scopes, so this was never a misconfiguration anyonecould correct -- the capability does not exist for that token.
The failure mode was poor. The push was rejected only after the revert commit
had been made, so the job died with
refusing to allow a GitHub App to create or update workflow
.github/workflows/ci.yml without
workflowspermissionwhich reads like a setup error, and buried the CI failure it was reacting to
under a second red check.
Now the job detects the case before committing and opens an issue instead, so
the regression is still surfaced loudly and the check stays green. Callers need
issues: write; the example stub is updated.Two latent bugs surfaced while fixing it. The path check must diff against the
first parent:
git diff-tree -r <sha>lists nothing for a merge commit, and thebad SHA is usually a merge, so the naive check would never have fired on the
case that matters. And it follows that auto-revert has never once succeeded
against a workflow-file regression in any consumer.
For full automation,
revert-app-client-idplus aREVERT_APP_PRIVATE_KEYsecret mints a scoped installation token with permission-workflows: write and
pushes with that. Both optional; unset keeps today behaviour plus the issue
fallback. The docs call for a dedicated App rather than reusing deps-reader,
which is deliberately contents:read only -- a credential that can rewrite
workflow files can rewrite CI itself.
Verified: actionlint clean; the run: block extracted and shellcheck -S warning
clean; the heredoc rendered and its output inspected; diff-vs-first-parent
checked against a real merge commit, where diff-tree -r returns 0 paths and
diff ^1 correctly returns .github/workflows/ci.yml.
Test plan
actionlintclean.run:block extracted andshellcheck -S warningclean.extractor-llm:git diff-tree --no-commit-id --name-only -r <sha>returns 0 paths,git diff <sha>^1 <sha>correctly returns.github/workflows/ci.yml.🤖 Generated with Claude Code
https://claude.ai/code/session_01EoicTZniGXry3W7YFZBsSM