ci: auto-merge Dependabot PRs after required checks pass#78
Merged
Conversation
Comment on lines
+17
to
+27
|
|
||
| jobs: | ||
| auto-merge: | ||
| if: ${{ github.actor == 'dependabot[bot]' }} | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Enable auto-merge (squash) | ||
| run: gh pr merge --auto --squash "$PR_URL" | ||
| env: | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
There was a problem hiding this comment.
Bug: The pull_request_target trigger, when used with Dependabot, likely provides a read-only token, which will cause the gh pr merge command to fail due to insufficient permissions.
Severity: HIGH
Suggested Fix
Change the workflow trigger from pull_request_target to pull_request. The permissions block is already correctly configured to grant the necessary write access for this trigger type. This aligns with GitHub's recommended practice for Dependabot workflows that need to perform write operations and matches the pattern used by other workflows in this repository.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: .github/workflows/dependabot-auto-merge.yml#L12-L27
Potential issue: The workflow is configured to run on `pull_request_target` events.
According to GitHub's security model, workflows triggered by Dependabot on this event
often receive a read-only `GITHUB_TOKEN` to prevent potential security exploits from
compromised dependencies. Although the workflow explicitly requests `contents: write`
and `pull-requests: write` permissions, these may be overridden by the read-only token
restriction. As a result, the `gh pr merge --auto --squash "$PR_URL"` command is likely
to fail with a permission denied error, preventing Dependabot pull requests from being
auto-merged.
Did we get this right? 👍 / 👎 to inform future reviews.
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.
Adds a minimal, safe
dependabot-auto-merge.ymlthat enables GitHub native auto-merge (gh pr merge --auto --squash) fordependabot[bot]PRs.Safety:
dependabot[bot]actor.Keeps the repo green automatically going forward.