-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
102 lines (92 loc) · 3.52 KB
/
action.yaml
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
100
101
102
name: "cleanlab/merge-bot"
description: "Deployment merge handler."
author: "Ryan Singman @ Cleanlab"
inputs:
reviews_required:
description: "if reviews are required to merge"
required: false
default: true
dependent_checks:
description: "comma separated list of checks to depend on"
required: false
default: ""
check_status_required:
description: "status value(s) for check to be considered passed (as comma separated list)"
required: false
default: "success"
blocking_label:
description: "label to block merge on (leave empty to disable behavior)"
required: false
default: ""
delete_branch:
description: "if should delete source branch of PR after successful merge"
required: false
default: false
merge_type:
description: "type of merge to use (merge or fast-forward)"
required: true
github_token:
description: "token used to access source repository"
required: true
runs:
using: composite
steps:
- uses: actions/checkout@v3
- id: blocking_label_check
run: |
python $GITHUB_ACTION_PATH/merge_bot/check_blocking_label.py \
--blocking-label ${{ inputs.blocking_label }} \
--labels ${{ join(github.event.pull_request.labels.*.name, ' ') }} && \
echo "success=1" >> $GITHUB_OUTPUT || \
echo "success=0" >> $GITHUB_OUTPUT
shell: bash
# install Python dependencies for action
- run: |
pip install -r $GITHUB_ACTION_PATH/requirements.txt
shell: bash
# if reviews_required, check all reviews are passing
- id: review_check
if: ${{ inputs.reviews_required }}
run: |
GITHUB_TOKEN=${{ inputs.github_token }} \
python $GITHUB_ACTION_PATH/merge_bot/check_review_approval.py \
--repository ${{ github.repository }} \
--pull-request-number ${{ github.event.pull_request.number }} && \
echo "success=1" >> $GITHUB_OUTPUT || \
echo "success=0" >> $GITHUB_OUTPUT
shell: bash
# if dependent checks, check all checks have required check status
- id: dependents_check
if: ${{ inputs.dependent_checks }}
run: |
GITHUB_TOKEN=${{ inputs.github_token }} \
python $GITHUB_ACTION_PATH/merge_bot/check_dependent_checks.py \
--checks "${{ inputs.dependent_checks }}" \
--repository ${{ github.repository }} \
--head-sha ${{ github.event.pull_request.head.sha }} \
--passing-check-statuses ${{ inputs.check_status_required }} && \
echo "success=1" >> $GITHUB_OUTPUT || \
echo "success=0" >> $GITHUB_OUTPUT
shell: bash
# merge PR using merge type
- id: merge
if: ${{ steps.blocking_label_check.outputs.success == 1 && steps.review_check.outputs.success == 1 && steps.dependents_check.outputs.success == 1 }}
uses: everlytic/[email protected]
with:
github_token: ${{ inputs.github_token }}
source_ref: ${{ github.event.pull_request.head.ref }}
target_branch: ${{ github.event.pull_request.base.ref }}
continue-on-error: true
# if delete source branch, delete branch
- if: ${{ success() && inputs.delete_branch && steps.merge.outcome == 'success' }}
run: |
echo "${{ steps.merge }}"
echo "Deleting source branch: ${{ github.event.pull_request.head.ref }}"
git push --delete origin ${{ github.event.pull_request.head.ref }}
shell: bash
# if failed to merge, print message
- if: failure()
run:
echo "Failed to merge -- exiting."
exit 0
shell: bash