Skip to content

Commit b2a75d8

Browse files
committed
ci: add dependabot auto-merge workflow
Auto-approves and auto-merges semver-safe (patch/minor) dependabot PRs when CI passes. Major version bumps require manual review.
1 parent d24ce09 commit b2a75d8

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Dependabot Auto-Merge
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, labeled]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
auto-merge:
13+
# Only run on dependabot PRs
14+
if: github.actor == 'dependabot[bot]'
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Fetch dependabot metadata
18+
id: metadata
19+
uses: dependabot/fetch-metadata@v2
20+
with:
21+
github-token: "${{ secrets.GITHUB_TOKEN }}"
22+
23+
- name: Wait for CI checks
24+
id: wait
25+
uses: lewagon/wait-on-check-action@v1.3.4
26+
with:
27+
ref: ${{ github.event.pull_request.head.sha }}
28+
check-name: 'test'
29+
repo-token: ${{ secrets.GITHUB_TOKEN }}
30+
wait-interval: 10
31+
32+
- name: Approve and merge
33+
if: steps.wait.outputs.exit-code == '0'
34+
run: |
35+
# Only auto-merge patch and minor updates (semver-safe)
36+
UPDATE_TYPE="${{ steps.metadata.outputs.update-type }}"
37+
echo "Update type: $UPDATE_TYPE"
38+
39+
case "$UPDATE_TYPE" in
40+
version-update:semver-patch|version-update:semver-minor)
41+
echo "Safe update — approving and merging"
42+
gh pr review --approve "$PR_URL" --body "Auto-approved: $UPDATE_TYPE"
43+
gh pr merge --squash --auto "$PR_URL"
44+
;;
45+
version-update:semver-major)
46+
echo "Major version bump — requires manual review"
47+
;;
48+
*)
49+
echo "Non-semver update (likely actions/gomod) — auto-merging if CI passes"
50+
gh pr review --approve "$PR_URL" --body "Auto-approved: CI-only dependency update"
51+
gh pr merge --squash --auto "$PR_URL"
52+
;;
53+
esac
54+
env:
55+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
PR_URL: ${{ github.event.pull_request.html_url }}

0 commit comments

Comments
 (0)