-
Notifications
You must be signed in to change notification settings - Fork 16
133 lines (117 loc) · 4.55 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
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=$(python -c "import requests; r = requests.get(\"https://api.github.com/repos/brain-score/language/commits/${{ github.event.pull_request.head.sha }}/check-runs\"); print(next(run['conclusion'] for run in r.json()['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"
plugin_only:
name: Ensure PR ONLY changes plugin files
runs-on: ubuntu-latest
needs: travis_success
if: ${{ needs.travis_success.outputs.TRAVIS_OK == 'True' }}
outputs:
PLUGIN_ONLY: ${{ steps.ispluginonly.outputs.PLUGIN_ONLY }}
steps:
- name: Parse plugin_only confirmation from Travis status update
id: getpluginonlyvalue
run: echo "PLUGIN_ONLY=$(python -c "import requests; r = requests.get(\"https://api.github.com/repos/brain-score/language/statuses/$github.event.pull_request.head.sha\"); print(next(status['description'].split('- ')[1] for status in r.json() if status['description'].startswith('Run automerge workflow')))")" >> $GITHUB_ENV
- name: Check if PR is plugin only
id: ispluginonly
run: |
if [ "$PLUGIN_ONLY" == "True" ]
then
pluginonly=True
else
pluginonly=False
fi
echo "::set-output name=PLUGIN_ONLY::$pluginonly"
automerge:
name: If plugin-only, approve and merge
runs-on: ubuntu-latest
needs: plugin_only
if: ${{ needs.plugin_only.outputs.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"