-
Notifications
You must be signed in to change notification settings - Fork 22
389 lines (377 loc) · 16.8 KB
/
project_management.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# yamllint disable rule:line-length
---
name: "Project Board Automation"
"on":
pull_request:
branches: [develop, master]
types: [synchronize, opened, reopened, labeled, unlabeled, ready_for_review, review_requested, converted_to_draft, closed]
pull_request_review:
types: [submitted]
env:
ORGANIZATION: vegaprotocol
PROJECT_NUMBER: 106
PR_URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ secrets.PROJECT_MANAGE_ACTION }}
EXCLUDE_LABEL: 'no-issue'
IN_PROGRESS_COLUMN_NAME: '"In Progress"'
REVIEW_REQUIRED_COLUMN_NAME: '"Waiting Review"'
IN_REVIEW_COLUMN_NAME: '"In Review"'
APPROVED_COLUMN_NAME: '"Approved"'
MERGED_COLUMN_NAME: '"Merged"'
DONE_COLUMN_NAME: '"Done"'
ITERATION_FIELD_NAME: 'Sprint'
USER: ${{ github.actor }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
project-board-automation:
name: "Linked Issues & Project Board Automation"
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: "Get linked issue id and state"
id: linked-issue
env:
GH_TOKEN: ${{ secrets.PROJECT_MANAGE_ACTION }}
run: |
gh api graphql -f query='
query($pr_url: URI!) {
resource(url: $pr_url) {
... on PullRequest {
closingIssuesReferences(last: 1) {
nodes {
id
state
}
}
}
}
}' -f pr_url=$PR_URL > data.json
echo 'LINKED_ISSUE_STATE='$(jq '.data.resource.closingIssuesReferences.nodes[] | .state' data.json) >> $GITHUB_ENV
echo 'LINKED_ISSUE_ID='$(jq '.data.resource.closingIssuesReferences.nodes[] | .id' data.json) >> $GITHUB_ENV
- name: "Check if PR raised by bot"
id: bot-pr
if: |
((startsWith(github.head_ref, 'renovate/') == true || startsWith(github.head_ref, 'dependabot/') == true)
|| (github.actor == 'dependabot[bot]' || github.actor == 'renovate[bot]'))
run: |
echo 'BOT_PR=true' >> $GITHUB_ENV
- name: "Check for linked issue"
id: linked
if: |
env.LINKED_ISSUE_ID != '' &&
contains(github.event.pull_request.labels.*.name, env.EXCLUDE_LABEL) != true
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log("Linked Issue Found!");
- name: "Check for linked issue exclusion label"
id: exclude-linked
if: |
steps.bot-pr.outcome == 'success' || env.LINKED_ISSUE_ID == '' &&
contains(github.event.pull_request.labels.*.name, env.EXCLUDE_LABEL) == true
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log("Exclusion label added, or a bot-PR no linked issue required!");
- name: "Fail if no linked issue or exclusion label"
id: exclude-linked-error
if: steps.linked.outcome == 'skipped' && steps.exclude-linked.outcome == 'skipped'
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log("No linked issue or exclusion label!");
core.setFailed("Link an issue and rerun, or, add the exclusion label!");
- name: "Fail if linked issue AND exclusion label"
id: linked-and-nochangelog
if: steps.linked.outcome == 'success' && steps.exclude-linked.outcome == 'success'
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log("Remove exclusion label, linked issue found!");
core.setFailed("Remove exclusion label, linked issue found!");
- name: "Get project related data"
id: project-data
run: |
gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
fields(first:20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
... on ProjectV2IterationField {
name
id
configuration {
iterations {
id
title
}
}
}
}
}
}
}
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' data.json) >> $GITHUB_ENV
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' data.json) >> $GITHUB_ENV
echo 'IN_PROGRESS_COLUMN='$(jq --arg in_progress ${{ env.IN_PROGRESS_COLUMN_NAME }} '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name==$in_progress) | .id' data.json) >> $GITHUB_ENV
echo 'REVIEW_REQUIRED_COLUMN='$(jq --arg review_required ${{ env.REVIEW_REQUIRED_COLUMN_NAME }} '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name==$review_required) | .id' data.json) >> $GITHUB_ENV
echo 'IN_REVIEW_COLUMN='$(jq --arg in_review ${{ env.IN_REVIEW_COLUMN_NAME }} '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name==$in_review) | .id' data.json) >> $GITHUB_ENV
echo 'APPROVED_COLUMN='$(jq --arg approved ${{ env.APPROVED_COLUMN_NAME }} '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name==$approved) | .id' data.json) >> $GITHUB_ENV
echo 'MERGED_COLUMN='$(jq --arg merged ${{ env.MERGED_COLUMN_NAME }} '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name==$merged) | .id' data.json) >> $GITHUB_ENV
echo 'DONE_COLUMN='$(jq --arg done ${{ env.DONE_COLUMN_NAME }} '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name==$done) | .id' data.json) >> $GITHUB_ENV
echo 'ITERATION_FIELD_ID='$(jq --arg iteration_field_name $ITERATION_FIELD_NAME '.data.organization.projectV2.fields.nodes[] | select(.name==$iteration_field_name) | .id' data.json) >> $GITHUB_ENV
echo 'CURRENT_ITERATION='$(jq --arg iteration_field_name $ITERATION_FIELD_NAME '.data.organization.projectV2.fields.nodes[] | select(.name==$iteration_field_name) | .configuration.iterations[0] | .id' data.json) >> $GITHUB_ENV
- name: "Get PR state, review decision and author"
id: pr-status
run: |
gh api graphql -f query='
query($pr_url: URI!) {
resource(url: $pr_url) {
... on PullRequest {
reviewThreads(last: 100) {
edges {
node {
isResolved
}
}
}
reviewDecision
id
isDraft
state
author{
login
}
reviews(last: 1) {
nodes {
state
}
}
}
}
}' -f pr_url=$PR_URL > data.json
echo 'REVIEW_DECISION='$(jq '.data.resource | .reviewDecision' data.json) >> $GITHUB_ENV
echo 'NUM_REVIEWS='$(jq '.data.resource.reviews.nodes | length' data.json) >> $GITHUB_ENV
echo 'LATEST_REVIEW_STATE='$(jq '.data.resource.reviews.nodes[] | .state' data.json) >> $GITHUB_ENV
echo 'IS_PR_DRAFT='$(jq '.data.resource | .isDraft' data.json) >> $GITHUB_ENV
echo 'PR_STATE='$(jq '.data.resource | .state' data.json) >> $GITHUB_ENV
echo 'PR_ID='$(jq '.data.resource | .id' data.json) >> $GITHUB_ENV
echo 'AUTHOR_NAME='$(jq '.data.resource.author | .login' data.json) >> $GITHUB_ENV
- name: "Get PR author id"
id: pr-author
if: steps.pr-status.outcome == 'success'
run: |
gh api graphql -f query='
query($author_name: String!) {
search (query: $author_name, type: USER, first: 1){
edges {
node {
... on User {
id
}
}
}
}
}' -f author_name=$AUTHOR_NAME > data.json
echo 'AUTHOR_ID='$(jq '.data.search.edges[] | .node | .id' data.json) >> $GITHUB_ENV
- name: "Add linked issue to the project"
id: issue-to-project
if: |
env.LINKED_ISSUE_ID != '' &&
contains(github.event.pull_request.labels.*.name, env.EXCLUDE_LABEL) != true
run: |
issue_item_id="$( gh api graphql -f query='
mutation($user:String!, $project:ID!, $issue:ID!) {
addProjectV2ItemById(input: {clientMutationId: $user, projectId: $project, contentId: $issue}) {
item {
id
}
}
}' -f project=$PROJECT_ID -f issue=$LINKED_ISSUE_ID -f user=$USER --jq '.data.addProjectV2ItemById.item.id')"
echo 'BOARD_ITEM_ID='$issue_item_id >> $GITHUB_ENV
- name: "Add exclusion labeled PR to the project"
id: pr-to-project
if: |
steps.issue-to-project.outcome == 'skipped' &&
contains(github.event.pull_request.labels.*.name, env.EXCLUDE_LABEL) == true
run: |
pr_item_id="$( gh api graphql -f query='
mutation($user:String!, $project:ID!, $pr:ID!) {
addProjectV2ItemById(input: {clientMutationId: $user, projectId: $project, contentId: $pr}) {
item {
id
}
}
}' -f project=$PROJECT_ID -f pr=$PR_ID -f user=$USER --jq '.data.addProjectV2ItemById.item.id')"
echo 'BOARD_ITEM_ID='$pr_item_id >> $GITHUB_ENV
- name: "Add BOT PR to the project"
id: bot-pr-to-project
if: steps.bot-pr.outcome == 'success'
run: |
pr_item_id="$( gh api graphql -f query='
mutation($user:String!, $project:ID!, $pr:ID!) {
addProjectV2ItemById(input: {clientMutationId: $user, projectId: $project, contentId: $pr}) {
item {
id
}
}
}' -f project=$PROJECT_ID -f pr=$PR_ID -f user=$USER --jq '.data.addProjectV2ItemById.item.id')"
echo 'BOARD_ITEM_ID='$pr_item_id >> $GITHUB_ENV
- name: "Reopen if the linked issue closed"
id: reopen-issue
if: steps.issue-to-project.outcome == 'success' && env.LINKED_ISSUE_STATE == '"CLOSED"' && env.PR_STATE != '"MERGED"'
run: |
gh api graphql -f query='
mutation($clientMutationId:String!, $issueId:ID!) {
reopenIssue(input: {clientMutationId:$clientMutationId, issueId:$issueId}) {
issue{
id
}
}
}' -f clientMutationId=$AUTHOR_ID -f issueId=$LINKED_ISSUE_ID
- run: env
- name: "Set draft work item for progress column"
id: draft-pr
if: github.event.pull_request.draft == 'true' || env.IS_PR_DRAFT == 'true'
run: |
echo 'ITEM_ID='${{ env.BOARD_ITEM_ID }} >> $GITHUB_ENV
echo 'CURRENT_ITERATION='$CURRENT_ITERATION >> $GITHUB_ENV
echo 'CURRENT_STATUS='${{ env.IN_PROGRESS_COLUMN }} >> $GITHUB_ENV
- name: "Set work item for review required column"
id: review-required
if: |
github.event.action == 'ready_for_review' ||
env.IS_PR_DRAFT != 'true' && env.NUM_REVIEWS == 0 && env.REVIEW_DECISION == '"REVIEW_REQUIRED"'
run: |
echo 'ITEM_ID='${{ env.BOARD_ITEM_ID }} >> $GITHUB_ENV
echo 'CURRENT_STATUS='${{ env.REVIEW_REQUIRED_COLUMN }} >> $GITHUB_ENV
- name: "Set work item for in review column"
id: changes-requested
if: |
(steps.draft-pr.outcome == 'skipped' && env.NUM_REVIEWS > 0 &&
(env.REVIEW_DECISION == '"CHANGES_REQUESTED"' || env.LATEST_REVIEW_STATE == '"COMMENTED"'
|| env.LATEST_REVIEW_STATE == '"DISMISSED"'))
run: |
echo 'ITEM_ID='${{ env.BOARD_ITEM_ID }} >> $GITHUB_ENV
echo 'CURRENT_STATUS='${{ env.IN_REVIEW_COLUMN }} >> $GITHUB_ENV
- name: "Set work item for approved column"
id: approved
if: |
(steps.draft-pr.outcome == 'skipped' && (env.REVIEW_DECISION == '"APPROVED"'
|| env.LATEST_REVIEW_STATE == '"APPROVED"'))
run: |
echo 'ITEM_ID='${{ env.BOARD_ITEM_ID }} >> $GITHUB_ENV
echo 'CURRENT_STATUS='${{ env.APPROVED_COLUMN }} >> $GITHUB_ENV
- name: "Set work item for merged column"
id: merged
if: env.PR_STATE == '"MERGED"' || github.event.pull_request.merged == true
run: |
echo 'ITEM_ID='${{ env.BOARD_ITEM_ID }} >> $GITHUB_ENV
echo 'CURRENT_STATUS='${{ env.MERGED_COLUMN }} >> $GITHUB_ENV
- name: "Close linked issue when PR merged"
id: close-issue
if: steps.merged.outcome == 'success' && steps.linked.outcome == 'success'
run: |
gh api graphql -f query='
mutation($clientMutationId:String!, $issueId:ID!) {
closeIssue(input: {clientMutationId:$clientMutationId, issueId:$issueId}) {
issue{
id
}
}
}' -f clientMutationId=$AUTHOR_ID -f issueId=$LINKED_ISSUE_ID
- name: "Set closed PR for done column"
id: closed-pr
if: steps.exclude-linked.outcome == 'success' && github.event.pull_request.closed == true
run: |
echo 'ITEM_ID='${{ env.BOARD_ITEM_ID }} >> $GITHUB_ENV
echo 'CURRENT_STATUS='${{ env.DONE_COLUMN }} >> $GITHUB_ENV
- name: "Set closed PR issue to in progress column"
id: closed-pr-with-issue
if: steps.linked.outcome == 'success' && github.event.pull_request.merged == true && env.PR_STATE != '"MERGED"'
run: |
echo 'ITEM_ID='${{ env.BOARD_ITEM_ID }} >> $GITHUB_ENV
echo 'CURRENT_STATUS='${{ env.IN_PROGRESS_COLUMN }} >> $GITHUB_ENV
- name: Move project board item
run: |
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$status_field: ID!
$status_value: String!
$iteration_field: ID!
$iteration_value: String!
) {
set_status: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $status_field
value: {
singleSelectOptionId: $status_value
}
}) {
projectV2Item {
id
}
}
set_iteration: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $iteration_field
value: {
iterationId: $iteration_value
}
}) {
projectV2Item {
id
}
}
}' -f project=$PROJECT_ID \
-f item=$ITEM_ID \
-f status_field=$STATUS_FIELD_ID \
-f status_value=${{ env.CURRENT_STATUS }} \
-f iteration_field=$ITERATION_FIELD_ID \
-f iteration_value=${{ env.CURRENT_ITERATION }}
verify-changelog-updated:
name: "Verify CHANGELOG Updated"
needs: project-board-automation
runs-on: ubuntu-latest
if: |
github.event.pull_request.draft != true
&& contains(github.event.pull_request.labels.*.name, 'no-changelog') != true
steps:
- name: "Checkout"
id: checkout
uses: actions/[email protected]
- name: "Check changelog entry"
id: check-changelog
uses: Zomzog/[email protected]
with:
fileName: CHANGELOG.md
noChangelogLabel: "no-changelog"
checkNotification: Simple
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# yamllint enable rule:line-length