-
Notifications
You must be signed in to change notification settings - Fork 228
52 lines (43 loc) · 1.61 KB
/
wgutils-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
name: Agenda auto-merge
on:
pull_request_target:
types: [synchronize, opened, reopened]
permissions:
contents: write
pull-requests: read
checks: read
jobs:
validate-and-merge:
if: ${{ github.event.pull_request.base.ref == 'main' }}
runs-on: ubuntu-latest
steps:
# SECURITY: it's critical we do not check out the source pull request!
- name: Checkout the main branch
uses: actions/checkout@v3
with:
ref: main
# We need wgutils to be installed
- run: yarn install
- name: Wait for checks to pass
env:
GH_TOKEN: ${{ github.token }}
run: |
# Give 15 seconds for any checks to register
sleep 15
# Wait for checks to pass
gh pr checks ${{ github.event.pull_request.number }} --fail-fast --watch --required 2>&1 || true
# Now get the result in JSON
CHECKS_OUTPUT="$(gh pr checks ${{ github.event.pull_request.number }} --required --json bucket --jq 'map(.bucket == "pass") | all' 2>&1 || true)"
if [[ "$CHECKS_OUTPUT" == "true" ]]; then
echo "$CHECKS_OUTPUT"
else
echo "PR state failed? $CHECKS_OUTPUT"
exit 1
fi
- name: Automerge if wgutils approves
env:
GH_TOKEN: ${{ github.token }}
run: |
if yarn wgutils can-automerge "${{ github.event.pull_request.number }}" "${{ github.event.pull_request.head.sha }}"; then
gh pr merge "${{ github.event.pull_request.number }}" --squash --auto --match-head-commit "${{ github.event.pull_request.head.sha }}"
fi