Repository navigation
48 lines (43 loc) · 2.05 KB
/
Copy pathAutoMerge.yml
File metadata and controls
48 lines (43 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
name: auto-merge
# pull_request_target is required because DEPENDABOT_AUTO_MERGE_TOKEN is an
# Actions secret, and Dependabot's pull_request runs only receive Dependabot
# secrets. No step checks out or executes code from the pull request.
on:
pull_request_target: # zizmor: ignore[dangerous-triggers]
permissions: {}
# github.ref is the base branch for pull_request_target, so the group is keyed
# by pull request; a newer event for the same pull request supersedes an older one.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
auto-merge:
# The pull request author cannot be spoofed by re-running or commenting,
# unlike github.actor.
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: read
pull-requests: read
steps:
- name: Read Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
# The previous action posted "@dependabot merge" comments, which GitHub
# removed on 2026-01-27, so it succeeded without merging (issue #150).
- name: Enable auto-merge for patch and minor updates
if: ${{ steps.metadata.outputs.update-type != 'version-update:semver-major' }}
env:
GH_TOKEN: ${{ secrets.DEPENDABOT_AUTO_MERGE_TOKEN }}
PR_URL: ${{ github.event.pull_request.html_url }}
run: |
if [ -z "$GH_TOKEN" ]; then
echo "::error title=Auto-merge token missing::Configure the DEPENDABOT_AUTO_MERGE_TOKEN Actions secret with a token that can merge pull requests."
exit 1
fi
if [ "$(gh api "repos/$GITHUB_REPOSITORY" --jq .allow_auto_merge)" != true ]; then
echo "::error title=Auto-merge is disabled::Enable 'Allow auto-merge' in Settings > General > Pull Requests, otherwise Dependabot pull requests are never merged."
exit 1
fi
gh pr merge --auto --merge "$PR_URL"