-
Notifications
You must be signed in to change notification settings - Fork 154
68 lines (60 loc) · 2.29 KB
/
auto-merge.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
66
67
68
name: Dependabot PR auto-merge
on:
workflow_run:
workflows: [on-pull-request]
types: ["completed"]
jobs:
auto-merge:
name: Auto-merge
runs-on: ubuntu-latest
# Run this only when the previous workflow was successfull & the initial actor was dependabot
if: ${{ github.event.workflow_run.conclusion == 'success' && github.actor == 'dependabot[bot]' }}
steps:
- uses: actions/checkout@v3
- name: Download PR artifact
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
// Get all artifacts
const artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
// Identify the artifact of the PR
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
// Download the actual artifact
const download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
// Write it to disk
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
- name: Unzip artifact
run: unzip pr.zip
- name: Merge PR
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const pullNumber = Number(fs.readFileSync('./NR'));
// Create a review
github.pulls.createReview({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
pull_number: pullNumber,
event: 'APPROVE'
})
// Merge PR
github.pulls.merge({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
pull_number: pullNumber,
merge_method: 'squash'
})
github-token: ${{ secrets.GITHUB_TOKEN }}