-
Notifications
You must be signed in to change notification settings - Fork 19
51 lines (47 loc) · 1.79 KB
/
auto_merge_dependabot_pr.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
name: Auto-Merge Dependabot PRs on CI Success
on:
repository_dispatch:
types: [ checks-complete ]
jobs:
auto-merge:
runs-on: ubuntu-latest
steps:
- run: echo "PR_NUMBER=${{ toJson(github.event.client_payload.prNumber) }}" >> $GITHUB_ENV
- name: Wait for 10 seconds
run: sleep 10
- name: Check CI status and Merge PR
uses: actions/github-script@v7
with:
script: |
const prNumber = process.env.PR_NUMBER;
if (!prNumber) {
console.log("No PR number found.");
return;
}
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
if(pullRequest.merged) {
console.log(`PR #${prNumber} is already merged.`);
return;
}
const { data: listCheckRuns } = await github.rest.checks.listForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: pullRequest.head.sha,
});
console.log("checks: ", listCheckRuns);
const allChecksPassed = listCheckRuns.check_runs.every(check => check.conclusion === 'success' || check.name === 'Inclusive Language' || check.conclusion === 'skipped');
if (allChecksPassed) {
await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
console.log(`Merged PR #${prNumber}`);
} else {
console.log(`Not all checks passed for PR #${prNumber}`);
}
github-token: ${{ secrets.GITHUB_TOKEN }}