Skip to content

Commit 3fb456f

Browse files
committed
ci: standardize dependabot automerge
1 parent 8a2d378 commit 3fb456f

1 file changed

Lines changed: 37 additions & 12 deletions

File tree

.github/workflows/automerge.yml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,47 @@
11
name: Dependabot auto-merge
22

3-
"on":
4-
pull_request:
5-
types:
6-
- opened
7-
- synchronize
8-
- reopened
3+
# Hardened against the CVE-2025-61671 pattern (and similar):
4+
# * Trust the PR author via `github.event.pull_request.user.login` only as a
5+
# coarse gate. The actual security boundary is the official
6+
# dependabot/fetch-metadata action, which signs over the PR contents and
7+
# exposes update-type / dependency metadata in a tamper-resistant way.
8+
# * Only `version-update:semver-patch` and `version-update:semver-security`
9+
# are eligible for `--merge`. Minor and major bumps get `--approve` only;
10+
# a human must hit the merge button.
11+
# * `gh pr merge --auto --squash` lets GitHub gate the actual merge on the
12+
# repository's required status checks (configured via branch protection),
13+
# so we do NOT need to wait for CI inside this workflow.
14+
15+
'on':
16+
pull_request_target:
17+
types: [opened, synchronize, reopened]
18+
19+
permissions:
20+
contents: write
21+
pull-requests: write
922

1023
jobs:
1124
automerge:
1225
runs-on: ubuntu-latest
13-
if: github.actor == 'dependabot[bot]'
14-
permissions:
15-
contents: write
16-
pull-requests: write
26+
if: github.event.pull_request.user.login == 'dependabot[bot]'
1727
steps:
18-
- name: Enable auto-merge for Dependabot PRs
19-
run: gh pr merge --auto --squash "$PR_URL"
28+
- name: Fetch Dependabot metadata
29+
id: meta
30+
uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a # v2.5.0
31+
with:
32+
github-token: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Approve PR (all update types)
2035
env:
2136
PR_URL: ${{ github.event.pull_request.html_url }}
2237
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
run: gh pr review --approve "$PR_URL"
39+
40+
- name: Enable auto-merge (patch + security only)
41+
if: |
42+
steps.meta.outputs.update-type == 'version-update:semver-patch' ||
43+
steps.meta.outputs.update-type == 'version-update:semver-security'
44+
env:
45+
PR_URL: ${{ github.event.pull_request.html_url }}
46+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
run: gh pr merge --auto --squash "$PR_URL"

0 commit comments

Comments
 (0)