Skip to content

Commit 5912d17

Browse files
hannahhowardclaude
andcommitted
ci: auto-approve and auto-merge Dependabot patch/minor updates
Approves and squash-merges Dependabot PRs for semver-patch and semver-minor updates once every other check is green. Major updates are untouched and wait for a human. Follow-up to the CI-standardization rollout (fil-one/RFC#11). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 769282a commit 5912d17

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: dependabot-auto-merge
2+
on: pull_request
3+
4+
permissions:
5+
contents: write
6+
pull-requests: write
7+
8+
jobs:
9+
auto-merge:
10+
if: github.event.pull_request.user.login == 'dependabot[bot]'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Fetch Dependabot metadata
14+
id: meta
15+
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
16+
- name: Approve (patch/minor only)
17+
if: contains(fromJSON('["version-update:semver-patch","version-update:semver-minor"]'), steps.meta.outputs.update-type)
18+
continue-on-error: true
19+
env:
20+
PR_URL: ${{ github.event.pull_request.html_url }}
21+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
run: gh pr review --approve "$PR_URL"
23+
- name: Merge when the other checks are green (patch/minor only)
24+
if: contains(fromJSON('["version-update:semver-patch","version-update:semver-minor"]'), steps.meta.outputs.update-type)
25+
env:
26+
PR_URL: ${{ github.event.pull_request.html_url }}
27+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
run: |
29+
for i in $(seq 1 60); do
30+
sleep 30
31+
state=$(gh pr view "$PR_URL" --json statusCheckRollup --jq '
32+
[.statusCheckRollup[]
33+
| select((.name // .context) != "auto-merge")
34+
| ((.conclusion // .state // "PENDING") | ascii_upcase)]
35+
| if length == 0 then "PENDING"
36+
elif any(. == "FAILURE" or . == "ERROR" or . == "CANCELLED" or . == "TIMED_OUT" or . == "ACTION_REQUIRED" or . == "STARTUP_FAILURE") then "RED"
37+
elif all(. == "SUCCESS" or . == "SKIPPED" or . == "NEUTRAL") then "GREEN"
38+
else "PENDING" end')
39+
echo "checks: $state (poll $i)"
40+
if [ "$state" = "GREEN" ]; then
41+
gh pr merge --squash "$PR_URL"
42+
exit 0
43+
fi
44+
if [ "$state" = "RED" ]; then
45+
echo "Checks failed - leaving this PR for a human."
46+
exit 1
47+
fi
48+
done
49+
echo "Timed out waiting for checks - leaving this PR for a human."
50+
exit 1

0 commit comments

Comments
 (0)