Skip to content

Commit 70e6c31

Browse files
use better auto-merge mechanism
1 parent e2674d2 commit 70e6c31

File tree

1 file changed

+41
-26
lines changed

1 file changed

+41
-26
lines changed

.github/workflows/update.yaml

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
11
# this workflow merges requests from Dependabot if tests are passing
2-
name: Merge me!
2+
# ref https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions
3+
# and https://github.com/dependabot/fetch-metadata
4+
name: Auto-merge
35

4-
on:
5-
workflow_run:
6-
types:
7-
- completed
8-
workflows:
9-
- 'Test'
6+
# `pull_request_target` means this uses code in the base branch, not the PR.
7+
on: pull_request_target
8+
9+
# Dependabot PRs' tokens have read permissions by default and thus we must enable write permissions.
10+
permissions:
11+
contents: write
12+
pull-requests: write
1013

1114
jobs:
12-
merge-me:
13-
name: Merge me!
15+
dependencies:
16+
runs-on: ubuntu-latest
17+
if: github.actor == 'dependabot[bot]'
18+
19+
steps:
20+
- name: Fetch PR metadata
21+
id: metadata
22+
uses: dependabot/[email protected]
23+
with:
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
1425

15-
runs-on: ubuntu-latest
26+
- name: Wait for PR CI
27+
# Don't merge updates to GitHub Actions versions automatically.
28+
# (Some repos may wish to limit by version range (major/minor/patch), or scope (dep vs dev-dep), too.)
29+
if: contains(steps.metadata.outputs.package-ecosystem, 'npm')
30+
uses: lewagon/[email protected]
31+
with:
32+
ref: ${{ github.event.pull_request.head.sha }}
33+
repo-token: ${{ secrets.GITHUB_TOKEN }}
34+
wait-interval: 30 # seconds
35+
running-workflow-name: dependencies # wait for all checks except this one
36+
allowed-conclusions: success # all other checks must pass, being skipped or cancelled is not sufficient
1637

17-
steps:
18-
- name: Merge me!
19-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
20-
uses: ridedott/merge-me-action@v2
21-
with:
22-
# Depending on branch prodtection rules, a manually populated
23-
# `GITHUB_TOKEN_WORKAROUND` secret with permissions to push to
24-
# a protected branch must be used.
25-
#
26-
# When using a custom token, it is recommended to leave the following
27-
# comment for other developers to be aware of the reasoning behind it:
28-
#
29-
# This must be used as GitHub Actions token does not support pushing
30-
# to protected branches.
31-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32-
PRESET: DEPENDABOT_MINOR
38+
- name: Auto-merge dependabot PRs
39+
# Don't merge updates to GitHub Actions versions automatically.
40+
# (Some repos may wish to limit by version range (major/minor/patch), or scope (dep vs dev-dep), too.)
41+
if: contains(steps.metadata.outputs.package-ecosystem, 'npm')
42+
env:
43+
PR_URL: ${{ github.event.pull_request.html_url }}
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
# The "auto" flag will only merge once all of the target branch's required checks
46+
# are met. Configure those in the "branch protection" settings for each repo.
47+
run: gh pr merge --auto --squash "$PR_URL"

0 commit comments

Comments
 (0)