Skip to content

Commit 835d673

Browse files
committed
Add merge-dependabot workflow
1 parent b07109f commit 835d673

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: merge-dependabot
2+
3+
# Merges minor and patch Dependabot pull requests once the Build workflow has passed on them.
4+
# Triggering on workflow_run rather than pull_request means an untested bump is never merged, and
5+
# no branch protection is needed (a required check would also block the docs workflow's pushes).
6+
# No personal access token: GITHUB_TOKEN gets write access through the permissions block below.
7+
# Major version bumps are left for a person.
8+
on:
9+
workflow_run:
10+
workflows: [Build]
11+
types: [completed]
12+
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
17+
jobs:
18+
merge:
19+
runs-on: ubuntu-latest
20+
if: >
21+
github.event.workflow_run.conclusion == 'success' &&
22+
github.event.workflow_run.event == 'pull_request' &&
23+
github.event.workflow_run.actor.login == 'dependabot[bot]'
24+
steps:
25+
# Dependabot records the update type in its commit message metadata, for example
26+
# "update-type: version-update:semver-minor". A grouped bump lists one per dependency.
27+
# --match-head-commit refuses the merge if the branch moved after this build ran.
28+
- name: Merge when the bump is minor or patch
29+
env:
30+
GH_TOKEN: ${{ github.token }}
31+
GH_REPO: ${{ github.repository }}
32+
BRANCH: ${{ github.event.workflow_run.head_branch }}
33+
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
34+
MESSAGE: ${{ github.event.workflow_run.head_commit.message }}
35+
run: |
36+
if grep -q 'update-type: version-update:semver-major' <<< "$MESSAGE"; then
37+
echo "Major version bump, leaving for review"
38+
exit 0
39+
fi
40+
pr=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number')
41+
if [ -z "$pr" ]; then
42+
echo "::warning::No open pull request for $BRANCH"
43+
exit 0
44+
fi
45+
gh pr merge "$pr" --squash --match-head-commit "$HEAD_SHA"

0 commit comments

Comments
 (0)