-
Notifications
You must be signed in to change notification settings - Fork 16
185 lines (168 loc) · 6.69 KB
/
automerge_plugin-only_prs.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: Automatically merge plugin-only PRs
# Triggered on all PRs either by
# - completion of CI checks, OR
# - tagging with label
# 1) If PR is labeled "automerge" or "automerge-web"
# (all website submissions are tagged "automerge-web"),
# checks if Travis tests pass. If yes, THEN
# 2) Checks if PR modifies any code outside plugin dirs.
# If no changes are made beyond new or revised plugins
# (subdirs of /benchmarks, /data, /models, or /metrics)
# the PR is automatically approved and merged.
on:
pull_request:
types: [labeled]
status:
permissions: write-all
jobs:
setup:
name: setup
runs-on: ubuntu-latest
outputs:
BSC_DATABASESECRET: ${{ steps.setenvvars.outputs.BSC_DATABASESECRET }}
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Check if main & set dev/prod vars
id: setenvvars
run: |
if [ ${{ github.ref }} != 'refs/heads/main' ]; then
echo "is NOT main branch"
echo "::set-output name=BSC_DATABASESECRET:: ${{ secrets.BSC_DATABASESECRET_DEV }}"
else
echo "is main branch"
echo "::set-output name=BSC_DATABASESECRET:: ${{ secrets.BSC_DATABASESECRET_PROD }}"
fi
isautomerge:
name: Set as 'automerge' if PR is labeled with 'automerge' or 'automerge-web'
runs-on: ubuntu-latest
if: |
contains( github.event.pull_request.labels.*.name, 'automerge') ||
contains( github.event.pull_request.labels.*.name, 'automerge-web')
outputs:
AUTOMERGE: ${{ steps.setautomerge.outputs.AUTOMERGE }}
steps:
- name: Set 'automerge' to 'True' # job only runs if True
id: setautomerge
run: |
echo "::set-output name=AUTOMERGE::True"
travis_success:
name: Check if Travis build is successful
runs-on: ubuntu-latest
needs: [isautomerge]
if: ${{ needs.isautomerge.outputs.AUTOMERGE == 'True' }}
outputs:
TRAVIS_OK: ${{ steps.istravisok.outputs.TRAVIS_OK }}
steps:
- name: Get Travis build status
id: gettravisstatus
run: |
echo ${{ github.event.pull_request.head.sha }}
echo "TRAVIS_CONCLUSION=$(curl -X GET https://api.github.com/repos/brain-score/language/commits/${{ github.event.pull_request.head.sha }}/check-runs | python -c "from __future__ import print_function; import sys,json; print(next(run['conclusion'] for run in json.load(sys.stdin)['check_runs'] if run['name'] == 'Travis CI - Pull Request'))")" >> $GITHUB_ENV
- name: Check if Travis was successful
id: istravisok
run: |
if [ "$TRAVIS_CONCLUSION" == "success" ]
then
travisok=True
elif [ "$TRAVIS_CONCLUSION" == "None" ]
then
travisok=Wait
else
travisok=False
fi
echo "::set-output name=TRAVIS_OK::$travisok"
email_on_failure:
name: If tests fail on an automerge-web PR, send email to submitter
runs-on: ubuntu-latest
needs: [setup, travis_success]
env:
BSC_DATABASESECRET: ${{ needs.setup.outputs.BSC_DATABASESECRET }}
if: |
needs.travis_success.outputs.TRAVIS_OK == 'False' &&
join(github.event.pull_request.labels.*.name, ',') == 'automerge-web'
steps:
- name: Parse Brain-Score user ID from PR title
run: |
echo "BS_UID="$(<<<${{ github.event.pull_request.title }} | sed -E 's/.*\(user:([^)]+)\).*/\1/'"" >> $GITHUB_ENV
- name: Build project
run: |
python -m pip install "."
- name: Get email from Brain-Score UID
run: |
echo "TO_EMAIL=$(python .github/workflows/call_endpoints.py get_user_email '${{ env.BS_UID }}')" >> $GITHUB_ENV
- name: Send email to Brain-Score user
uses: dawidd6/action-send-mail@v3
with:
# Required mail server address:
server_address: smtp.gmail.com
# Server port, default 25:
server_port: 465
# Optional whether this connection use TLS (default is true if server_port is 465)
secure: true
# Optional (recommended) mail server username:
username: ${{ secrets.MAIL_USERNAME }}
# Optional (recommended) mail server password:
password: ${{ secrets.MAIL_PASSWORD }}
# Required mail subject:
subject: Brain-Score submission failed
# Required recipients' addresses:
to: ${{ env.BS_UID }}
# Required sender full name:
from: Brain-Score
# Optional plain body:
body: Your Brain-Score submission did not pass checks. Please review the test results and update the PR at https://github.com/brain-score/language/pull/${{ github.event.number }} or send in an updated submission via the website.
checkchanges:
name: Check if PR only changes plugin files
runs-on: ubuntu-latest
needs: travis_success
if: ${{ needs.travis_success.outputs.TRAVIS_OK == 'True' }}
outputs:
PLUGIN_INFO: ${{ steps.getpluginfo.outputs.PLUGIN_INFO }}
IS_PLUGIN_ONLY: ${{ steps.ispluginonly.outputs.IS_PLUGIN_ONLY }}
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Get changed files
uses: dorny/[email protected]
id: filter
with:
list-files: shell
filters: |
changed:
- '**'
- name: Save changed files to env var
run: echo "CHANGED_FILES=${{ steps.filter.outputs.changed_files }}" >> $GITHUB_ENV
- name: Parse changed files with python script
run: |
echo "PLUGIN_INFO=$(python .github/workflows/parse_changed_files.py '${{ env.CHANGED_FILES }}')" >> $GITHUB_ENV
- name: Save plugin info to outputs
id: getpluginfo
run: |
echo "PLUGIN_INFO=$PLUGIN_INFO" >> $GITHUB_OUTPUT
- name: check if plugin-only
id: ispluginonly
run: |
echo "IS_PLUGIN_ONLY=$(jq -r '.is_plugin_only' <<< "$PLUGIN_INFO")" >> $GITHUB_OUTPUT
automerge:
name: If plugin-only, approve and merge
runs-on: ubuntu-latest
needs: checkchanges
if: ${{ needs.checkchanges.outputs.IS_PLUGIN_ONLY == 'True' }}
steps:
- name: Auto Approve
uses: hmarr/[email protected]
- name: Auto Merge (GitHub submissions)
uses: plm9606/[email protected]
with:
github-token: ${{ secrets.WORKFLOW_TOKEN }}
label-name: "automerge"
merge-method: "squash"
auto-delete: "true"
- name: Auto Merge (brain-score.org submissions)
uses: plm9606/[email protected]
with:
github-token: ${{ secrets.WORKFLOW_TOKEN }}
label-name: "automerge-web"
merge-method: "squash"
auto-delete: "true"