-
Notifications
You must be signed in to change notification settings - Fork 1
99 lines (86 loc) · 3.78 KB
/
dependabot-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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright (C) 2020 Dremio
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# GitHub workflow to automatically approve and merge dependabot-PRs that
# have passed CI.
name: Dependabot Auto Merge
on:
workflow_run:
types:
- "completed"
workflows:
- "CI"
jobs:
merge:
name: "Dependabot Auto Merge"
runs-on: ubuntu-latest
# Note: the check `github.actor == 'dependabot[bot]'` ensures that auto-approve-and-merge
# only happens when dependabot triggers the workflow runs - but not when another user pushes.
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' &&
github.actor == 'dependabot[bot]' && (
contains(github.event.workflow_run.head_commit.message, 'ump ')
) &&
github.repository == 'projectnessie/nessie-antlr-runtime'
steps:
- name: Information
uses: "actions/github-script@v6"
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const pullRequest = context.payload.workflow_run.pull_requests[0]
const repository = context.repo
const pullRequestDetails = await github.rest.pulls.get({
owner: repository.owner,
repo: repository.repo,
pull_number: pullRequest.number,
})
console.log("PR Number: " + pullRequest.number)
console.log("PR head SHA: " + pullRequest.head.sha)
console.log("PR head ref: " + pullRequest.head.ref)
console.log("PR URL: " + pullRequestDetails.html_url)
console.log(pullRequestDetails)
- name: Check commit status
run: |
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
gh api repos/projectnessie/nessie-antlr-runtime/commits/${{ github.event.workflow_run.head_commit.id }}/check-runs --jq 'if ([.check_runs[] | select(.name | endswith(" release") or startswith("codecov/") or startswith("Report ") | not ) | select(.conclusion != "skipped") | .conclusion // "pending" ] | unique == ["success"]) then "OK" else error("Commit checks are not OK") end'
- name: "Approve pull request"
uses: "actions/github-script@v6"
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const pullRequest = context.payload.workflow_run.pull_requests[0]
const repository = context.repo
await github.rest.pulls.createReview({
event: "APPROVE",
owner: repository.owner,
repo: repository.repo,
pull_number: pullRequest.number,
commit_id: pullRequest.head.sha,
})
- name: "Merge pull request"
uses: "actions/github-script@v6"
with:
# Use the NESSIE_BUILDER secret to tigger CI on main branch
github-token: "${{ secrets.NESSIE_BUILDER }}"
script: |
const pullRequest = context.payload.workflow_run.pull_requests[0]
const repository = context.repo
await github.rest.pulls.merge({
merge_method: "squash",
owner: repository.owner,
pull_number: pullRequest.number,
repo: repository.repo,
commit_id: pullRequest.head.sha,
})