Skip to content

Commit 8e00983

Browse files
authored
Merge pull request #106 from dominykas/main
2 parents 9123ee7 + 424e713 commit 8e00983

File tree

1 file changed

+70
-61
lines changed

1 file changed

+70
-61
lines changed

.github/workflows/wiby.yaml

Lines changed: 70 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,67 @@
11
name: wiby
22

33
on:
4-
issue_comment:
5-
types: [ created ]
4+
pull_request_target:
5+
types: [ labeled ]
66

77
env:
88
WIBY_CHECK_NAME: "wiby"
99
WIBY_NODE_VERSION: 14
1010

1111
jobs:
1212

13-
permissions:
13+
status:
1414

1515
runs-on: ubuntu-latest
1616

17-
if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, 'wiby ') && (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'COLLABORATOR') }}
17+
if: ${{ github.event.label.name == 'wiby test' }}
18+
19+
outputs:
20+
in_progress: ${{ steps.checks_by_status.outputs.in_progress }}
21+
queued: ${{ steps.checks_by_status.outputs.queued }}
22+
completed: ${{ steps.checks_by_status.outputs.completed }}
1823

1924
steps:
20-
- run: 'echo "Author association: ${{ github.event.comment.author_association }}"'
25+
- name: Get status
26+
uses: octokit/[email protected]
27+
with:
28+
route: GET /repos/:repository/commits/:ref/check-runs
29+
repository: ${{ github.event.repository.full_name }}
30+
ref: ${{ github.event.pull_request.head.sha }}
31+
mediaType: |
32+
previews:
33+
- antiope
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
id: pr_status
37+
38+
- name: Count wiby status check by their status
39+
run: |
40+
jq -r '.check_runs | map(select(.name=="wiby")) | group_by(.status) | map("::set-output name=" + .[0].status + "::" + (length | tostring)) | join("\n")' << EOF
41+
${{ steps.pr_status.outputs.data }}
42+
EOF
43+
id: checks_by_status
2144

2245
test:
2346

2447
runs-on: ubuntu-latest
2548

26-
needs: permissions
49+
needs: status
2750

28-
if: ${{ startsWith(github.event.comment.body, 'wiby test') }}
51+
if: ${{ !needs.status.outputs.in_progress && !needs.status.outputs.queued }}
2952

3053
steps:
3154

32-
- name: Load PR
33-
uses: octokit/[email protected]
34-
with:
35-
route: ${{ github.event.issue.pull_request.url }}
36-
env:
37-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38-
id: load_pr
39-
40-
- name: Get PR information
41-
run: |
42-
echo "::set-output name=branch::${{ fromJson(steps.load_pr.outputs.data).head.ref }}"
43-
echo "::set-output name=head_sha::${{ fromJson(steps.load_pr.outputs.data).head.sha }}"
44-
echo "::set-output name=repo_name::${{ fromJson(steps.load_pr.outputs.data).base.repo.full_name }}"
45-
echo "::set-output name=repo_url::${{ fromJson(steps.load_pr.outputs.data).base.repo.html_url }}"
46-
id: pr
47-
4855
- name: Set "queued" status
4956
uses: octokit/[email protected]
5057
with:
5158
route: POST /repos/:repository/check-runs
52-
repository: ${{ steps.pr.outputs.repo_name }}
59+
repository: ${{ github.event.repository.full_name }}
5360
mediaType: |
5461
previews:
5562
- antiope
5663
name: ${{ env.WIBY_CHECK_NAME }}
57-
details_url: "${{ steps.pr.outputs.repo_url }}/actions/runs/${{ github.run_id }}"
58-
head_sha: ${{ steps.pr.outputs.head_sha }}
64+
head_sha: ${{ github.event.pull_request.head.sha }}
5965
status: "queued"
6066
env:
6167
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -64,8 +70,8 @@ jobs:
6470
uses: actions/checkout@v2
6571
with:
6672
token: ${{ secrets.GITHUB_TOKEN }}
67-
repository: ${{ steps.pr.outputs.repo_name }}
68-
ref: ${{ steps.pr.outputs.branch }}
73+
repository: ${{ github.event.repository.full_name }}
74+
ref: ${{ github.event.pull_request.head.ref }}
6975

7076
- name: Prepare Node.js
7177
uses: actions/setup-node@v2
@@ -89,13 +95,12 @@ jobs:
8995
if: ${{ failure() }}
9096
with:
9197
route: POST /repos/:repository/check-runs
92-
repository: ${{ steps.pr.outputs.repo_name }}
98+
repository: ${{ github.event.repository.full_name }}
9399
mediaType: |
94100
previews:
95101
- antiope
96102
name: ${{ env.WIBY_CHECK_NAME }}
97-
details_url: "${{ steps.pr.outputs.repo_url }}/actions/runs/${{ github.run_id }}"
98-
head_sha: ${{ steps.pr.outputs.head_sha }}
103+
head_sha: ${{ github.event.pull_request.head.sha }}
99104
conclusion: "failure"
100105
env:
101106
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -104,49 +109,44 @@ jobs:
104109
uses: octokit/[email protected]
105110
with:
106111
route: POST /repos/:repository/check-runs
107-
repository: ${{ steps.pr.outputs.repo_name }}
112+
repository: ${{ github.event.repository.full_name }}
108113
mediaType: |
109114
previews:
110115
- antiope
111116
name: ${{ env.WIBY_CHECK_NAME }}
112-
details_url: "${{ steps.pr.outputs.repo_url }}/actions/runs/${{ github.run_id }}"
113-
head_sha: ${{ steps.pr.outputs.head_sha }}
117+
head_sha: ${{ github.event.pull_request.head.sha }}
114118
status: "in_progress"
115119
env:
116120
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117121

122+
- name: Clean up the trigger label
123+
if: ${{ always() }}
124+
uses: octokit/[email protected]
125+
with:
126+
route: DELETE /repos/:repository/issues/:issue_number/labels/:label_name
127+
repository: ${{ github.event.repository.full_name }}
128+
issue_number: ${{ github.event.pull_request.number }}
129+
label_name: ${{ github.event.label.name }}
130+
env:
131+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132+
133+
118134
result:
119135

120136
runs-on: ubuntu-latest
121137

122-
needs: permissions
138+
needs: status
123139

124-
if: ${{ startsWith(github.event.comment.body, 'wiby result') }}
140+
if: ${{ needs.status.outputs.in_progress }}
125141

126142
steps:
127143

128-
- name: Load PR
129-
uses: octokit/[email protected]
130-
with:
131-
route: ${{ github.event.issue.pull_request.url }}
132-
env:
133-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134-
id: load_pr
135-
136-
- name: Get PR information
137-
run: |
138-
echo "::set-output name=branch::${{ fromJson(steps.load_pr.outputs.data).head.ref }}"
139-
echo "::set-output name=head_sha::${{ fromJson(steps.load_pr.outputs.data).head.sha }}"
140-
echo "::set-output name=repo_name::${{ fromJson(steps.load_pr.outputs.data).base.repo.full_name }}"
141-
echo "::set-output name=repo_url::${{ fromJson(steps.load_pr.outputs.data).base.repo.html_url }}"
142-
id: pr
143-
144144
- name: Checkout PR Branch
145145
uses: actions/checkout@v2
146146
with:
147147
token: ${{ secrets.GITHUB_TOKEN }}
148-
repository: ${{ steps.pr.outputs.repo_name }}
149-
ref: ${{ steps.pr.outputs.branch }}
148+
repository: ${{ github.event.repository.full_name }}
149+
ref: ${{ github.event.pull_request.head.ref }}
150150

151151
- name: Prepare Node.js
152152
uses: actions/setup-node@v2
@@ -162,7 +162,7 @@ jobs:
162162
WIBY_RESULT_CODE=$1
163163
164164
if [ ${WIBY_RESULT_CODE} -eq 64 ]; then
165-
echo "`wiby` exited with code 64 - results are still pending"
165+
echo "wiby exited with code 64 - results are still pending"
166166
exit
167167
else
168168
echo "::set-output name=wiby_conclusion::failure"
@@ -191,13 +191,12 @@ jobs:
191191
if: ${{ failure() }}
192192
with:
193193
route: POST /repos/:repository/check-runs
194-
repository: ${{ steps.pr.outputs.repo_name }}
194+
repository: ${{ github.event.repository.full_name }}
195195
mediaType: |
196196
previews:
197197
- antiope
198198
name: ${{ env.WIBY_CHECK_NAME }}
199-
details_url: "${{ steps.pr.outputs.repo_url }}/actions/runs/${{ github.run_id }}"
200-
head_sha: ${{ steps.pr.outputs.head_sha }}
199+
head_sha: ${{ github.event.pull_request.head.sha }}
201200
conclusion: "failure"
202201
env:
203202
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -207,13 +206,23 @@ jobs:
207206
if: ${{ steps.wiby_result.outputs.wiby_conclusion != '' }}
208207
with:
209208
route: POST /repos/:repository/check-runs
210-
repository: ${{ steps.pr.outputs.repo_name }}
209+
repository: ${{ github.event.repository.full_name }}
211210
mediaType: |
212211
previews:
213212
- antiope
214213
name: ${{ env.WIBY_CHECK_NAME }}
215-
details_url: "${{ steps.pr.outputs.repo_url }}/actions/runs/${{ github.run_id }}"
216-
head_sha: ${{ steps.pr.outputs.head_sha }}
214+
head_sha: ${{ github.event.pull_request.head.sha }}
217215
conclusion: ${{ steps.wiby_result.outputs.wiby_conclusion }}
218216
env:
219217
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
218+
219+
- name: Clean up the trigger label
220+
if: ${{ always() }}
221+
uses: octokit/[email protected]
222+
with:
223+
route: DELETE /repos/:repository/issues/:issue_number/labels/:label_name
224+
repository: ${{ github.event.repository.full_name }}
225+
issue_number: ${{ github.event.pull_request.number }}
226+
label_name: ${{ github.event.label.name }}
227+
env:
228+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)