Repository navigation
Dependabot Auto-Merge #363
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
| name: Dependabot Auto-Merge | |
| on: | |
| workflow_run: | |
| workflows: ["CI"] | |
| types: [completed] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| automerge: | |
| name: Auto-merge Dependabot PRs after CI passes | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - name: Find associated PR | |
| id: find-pr | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| HEAD_SHA: ${{ github.event.workflow_run.head_sha }} | |
| run: | | |
| PR=$(gh api "repos/$REPO/commits/$HEAD_SHA/pulls" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| --jq '.[0] | {number: .number, actor: .user.login}') | |
| NUMBER=$(echo "$PR" | jq -r '.number // empty') | |
| ACTOR=$(echo "$PR" | jq -r '.actor // empty') | |
| echo "pr_number=$NUMBER" >> "$GITHUB_OUTPUT" | |
| echo "actor=$ACTOR" >> "$GITHUB_OUTPUT" | |
| - name: Approve and merge if Dependabot PR | |
| if: steps.find-pr.outputs.actor == 'dependabot[bot]' && steps.find-pr.outputs.pr_number != '' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| PR_NUMBER: ${{ steps.find-pr.outputs.pr_number }} | |
| run: | | |
| gh pr review "$PR_NUMBER" --approve --repo "$REPO" | |
| gh pr merge "$PR_NUMBER" --squash --repo "$REPO" |