-
-
Notifications
You must be signed in to change notification settings - Fork 604
65 lines (56 loc) · 2.18 KB
/
dependabot-automerge.yml
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Automatically merge Dependabot PRs when version comparison is within the range
# that is configured in .github/auto-merge.yml
name: Auto-Merge Dependabot PRs
on:
# WARNING: This needs to be run in the PR base, DO NOT build untrusted code in this action
# details under https://github.blog/changelog/2021-02-19-github-actions-workflows-triggered-by-dependabot-prs-will-run-with-read-only-permissions/
pull_request_target:
# permissions:
# pull-requests: write
# contents: write
jobs:
auto-merge:
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Dependabot metadata
id: dependabot-metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: ${{ secrets.BOT_TOKEN }}
alert-lookup: true
- name: Check if PR should be auto-merged
uses: actions/github-script@v7
id: should-automerge
env:
updatedDependenciesJson: ${{ steps.dependabot-metadata.outputs.updated-dependencies-json }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }} # This doesn't need special permissions
result-encoding: string
script: |
const bot = require(`${process.env.GITHUB_WORKSPACE}/.github/bot-scripts/index.cjs`);
return bot.shouldAutomerge({github, context});
- name: Approve PR
if: ${{ steps.should-automerge.outputs.result == 'true' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.BOT_TOKEN }}
script: |
const options = {
owner: context.repo.owner,
repo: context.repo.repo,
};
await github.rest.pulls.createReview({
...options,
pull_number: context.issue.number,
event: "APPROVE"
});
- name: Auto-merge PR
if: ${{ steps.should-automerge.outputs.result == 'true' }}
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
gh pr merge --auto --squash "$PR_URL"