Skip to content

Commit 5c95dd9

Browse files
committed
Unbreak Dependabot auto-merge
`gh pr review --approve` fails outright where "Allow GitHub Actions to create and approve pull requests" is off, and under `bash -e` that killed the step before `gh pr merge --auto` ever ran. Our rulesets require status checks, not reviews, so the approval bought nothing; GitHub's own documented example does not approve either. Also pins fetch-metadata to the v3.1.0 SHA, replaces the fail-open `update-type != major` guard -- which merged on an empty update-type -- with an explicit allow-list, and tolerates auto-merge refusing to arm on a PR GitHub already considers mergeable.
1 parent eeb8369 commit 5c95dd9

1 file changed

Lines changed: 50 additions & 13 deletions

File tree

.github/workflows/dependabot-auto-merge.yml

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,75 @@ permissions:
99
jobs:
1010
auto-merge:
1111
runs-on: ubuntu-latest
12+
timeout-minutes: 10
1213
if: github.event.pull_request.user.login == 'dependabot[bot]'
1314
steps:
1415
- name: Fetch Dependabot metadata
1516
id: metadata
16-
uses: dependabot/fetch-metadata@v3
17+
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
1718
with:
1819
github-token: ${{ secrets.GITHUB_TOKEN }}
1920

2021
# Auto-merge everything except Python-ecosystem majors:
2122
# - grouped PRs report the highest bump anywhere in the group (including
2223
# transitive lockfile updates), so trust our own minor-and-patch groups
2324
# - GitHub-Actions majors are CI-validated and low blast radius
25+
# An unrecognised or empty update-type is NOT eligible, so metadata
26+
# failures leave the PR open rather than merging it. Each branch is a
27+
# full if/case, never `test && var=true`: under `bash -e` a failing test
28+
# as the last statement of a step fails the whole step.
29+
- name: Decide eligibility
30+
id: gate
31+
env:
32+
ECOSYSTEM: ${{ steps.metadata.outputs.package-ecosystem }}
33+
GROUP: ${{ steps.metadata.outputs.dependency-group }}
34+
UPDATE_TYPE: ${{ steps.metadata.outputs.update-type }}
35+
run: |
36+
eligible=false
37+
if [ "$ECOSYSTEM" = "github_actions" ]; then
38+
eligible=true
39+
fi
40+
case "$GROUP" in
41+
*minor-and-patch*) eligible=true ;;
42+
esac
43+
case "$UPDATE_TYPE" in
44+
version-update:semver-minor|version-update:semver-patch) eligible=true ;;
45+
esac
46+
echo "ecosystem=$ECOSYSTEM group=$GROUP update-type=$UPDATE_TYPE eligible=$eligible"
47+
echo "eligible=$eligible" >> "$GITHUB_OUTPUT"
48+
49+
# No `gh pr review --approve`: it fails outright where the repo has
50+
# "Allow GitHub Actions to create and approve pull requests" off, which
51+
# aborted the step before the merge ever ran. Our rulesets require status
52+
# checks, not reviews, and GitHub's own documented example does not
53+
# approve either.
2454
- name: Enable auto-merge for eligible updates
25-
if: >-
26-
steps.metadata.outputs.package-ecosystem == 'github_actions' ||
27-
contains(steps.metadata.outputs.dependency-group, 'minor-and-patch') ||
28-
steps.metadata.outputs.update-type != 'version-update:semver-major'
55+
if: steps.gate.outputs.eligible == 'true'
2956
env:
3057
PR_URL: ${{ github.event.pull_request.html_url }}
3158
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3259
run: |
33-
gh pr review --approve "$PR_URL"
34-
gh pr merge --auto --squash "$PR_URL"
60+
if err=$(gh pr merge --auto --squash "$PR_URL" 2>&1); then
61+
printf '%s\n' "$err"
62+
exit 0
63+
fi
64+
printf '%s\n' "$err"
65+
# GitHub refuses to arm auto-merge on a PR it currently considers
66+
# mergeable, and this job finishes in seconds -- often before the
67+
# required check runs exist. Do not merge directly here: "clean" at
68+
# t+4s does not mean the checks passed.
69+
case "$err" in
70+
*"clean status"*|*"not mergeable"*|*"Auto merge is not allowed"*)
71+
echo "::warning::auto-merge not armable yet; leaving PR open"
72+
exit 0 ;;
73+
esac
74+
exit 1
3575
36-
- name: Flag major updates for manual review
37-
if: >-
38-
steps.metadata.outputs.package-ecosystem != 'github_actions' &&
39-
!contains(steps.metadata.outputs.dependency-group, 'minor-and-patch') &&
40-
steps.metadata.outputs.update-type == 'version-update:semver-major'
76+
- name: Flag ineligible updates for manual review
77+
if: steps.gate.outputs.eligible != 'true' && github.event.action == 'opened'
4178
env:
4279
PR_URL: ${{ github.event.pull_request.html_url }}
4380
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4481
run: |
4582
gh pr comment "$PR_URL" --body \
46-
"Major version bump — left open for manual review (auto-merge covers patch/minor only)."
83+
"Left open for manual review auto-merge covers GitHub-Actions updates, our minor-and-patch groups, and patch/minor Python bumps."

0 commit comments

Comments
 (0)