Skip to content

Instantly share code, notes, and snippets.

@Attacktive
Created December 2, 2025 01:14
Show Gist options
  • Select an option

  • Save Attacktive/120fe90d5740ee1e4a5ea9f9617a8be9 to your computer and use it in GitHub Desktop.

Select an option

Save Attacktive/120fe90d5740ee1e4a5ea9f9617a8be9 to your computer and use it in GitHub Desktop.
Auto-merging GitHub Workflow for Dependabot
name: 'Dependabot Auto-Merge'
on:
pull_request:
types: ['opened', 'reopened', 'synchronize', 'ready_for_review']
permissions:
contents: 'write'
pull-requests: 'write'
jobs:
auto-merge:
runs-on: 'ubuntu-latest'
if: github.actor == 'dependabot[bot]'
steps:
- name: 'Fetch Dependabot metadata'
id: 'metadata'
uses: 'dependabot/fetch-metadata@08eff52bf64351f401fb50d4972fa95b9f2c2d1b'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: 'Approve PR'
run: |
gh pr review "$PR_URL" --approve
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{ github.event.pull_request.html_url }}
- name: 'Enable Auto-Merge (Rebase)'
run: 'gh pr merge "$PR_URL" --auto --rebase'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{ github.event.pull_request.html_url }}
- name: 'Delete branch when merged'
if: 'github.event.pull_request.merged == true'
run: 'gh api -X DELETE "$URL_TO_BRANCH"'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
URL_TO_BRANCH: "repos/${{ github.repository }}/git/refs/heads/${{ github.event.pull_request.head.ref }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment