-
Notifications
You must be signed in to change notification settings - Fork 1
446 lines (426 loc) · 18 KB
/
new-event-intake.yml
File metadata and controls
446 lines (426 loc) · 18 KB
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
name: Event Intake
on:
issues:
types: [opened, edited, reopened, labeled]
concurrency:
group: new-event-intake-${{ github.event.issue.number }}
cancel-in-progress: true
permissions:
contents: write
issues: write
pull-requests: write
env:
STATUS_COMMENT_MARKER: <!-- new-event-intake-status -->
jobs:
process-new-event:
if: contains(github.event.issue.labels.*.name, 'new event')
runs-on: ubuntu-latest
timeout-minutes: 10
env:
PCD_TEAM_ASSIGNEES: ${{ vars.PCD_TEAM_ASSIGNEES }}
PCD_TEAM_REVIEWERS: ${{ vars.PCD_TEAM_REVIEWERS }}
outputs:
valid: ${{ steps.generate.outputs.valid }}
branch: ${{ steps.generate.outputs.branch }}
commit_message: ${{ steps.generate.outputs.commit_message }}
pr_title: ${{ steps.generate.outputs.pr_title }}
pr_body_path: ${{ steps.generate.outputs.pr_body_path }}
validation_comment_path: ${{ steps.generate.outputs.validation_comment_path }}
event_name: ${{ steps.generate.outputs.event_name }}
pr_label: ${{ steps.generate.outputs.pr_label }}
action_verb: ${{ steps.generate.outputs.action_verb }}
steps:
- name: Log trigger context
run: |
echo "event_action=${{ github.event.action }}"
echo "issue_number=${{ github.event.issue.number }}"
echo "issue_labels=${{ join(github.event.issue.labels.*.name, ', ') }}"
echo "sender=${{ github.event.sender.login }}"
- name: Label and assign intake issue
uses: actions/github-script@v8
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue_number = context.issue.number;
const desiredLabels = [
{ name: 'needs review', color: 'fbca04', description: 'Submission is ready for maintainer review' },
{ name: 'new event', color: '0e8a16', description: 'New event submission intake' },
];
for (const label of desiredLabels) {
try {
await github.rest.issues.getLabel({ owner, repo, name: label.name });
} catch (error) {
if (error.status !== 404) throw error;
await github.rest.issues.createLabel({ owner, repo, ...label });
}
}
await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: desiredLabels.map((label) => label.name),
});
const assignees = (process.env.PCD_TEAM_ASSIGNEES || '')
.split(',')
.map((value) => value.trim())
.filter(Boolean);
if (assignees.length) {
await github.rest.issues.addAssignees({
owner,
repo,
issue_number,
assignees,
});
}
- uses: actions/checkout@v6
with:
ref: ${{ github.event.repository.default_branch }}
persist-credentials: false
- uses: actions/setup-node@v6
with:
node-version: '24'
- name: Install script dependencies
run: npm install --prefix /tmp/script-deps open-location-code
- name: Generate event files from issue
id: generate
run: node .github/scripts/process-new-event-issue.mjs
- name: Log generate outputs
if: always()
run: |
echo "valid=${{ steps.generate.outputs.valid }}"
echo "branch=${{ steps.generate.outputs.branch }}"
echo "event_name=${{ steps.generate.outputs.event_name }}"
echo "validation_comment_path=${{ steps.generate.outputs.validation_comment_path }}"
echo "pr_body_path=${{ steps.generate.outputs.pr_body_path }}"
- name: Log PR body
if: steps.generate.outputs.valid == 'true'
run: cat "${{ steps.generate.outputs.pr_body_path }}"
- name: Log validation comment
if: steps.generate.outputs.valid == 'false'
run: cat "${{ steps.generate.outputs.validation_comment_path }}"
- name: Upload event files artifact
if: steps.generate.outputs.valid == 'true'
uses: actions/upload-artifact@v4
with:
name: event-files-${{ github.event.issue.number }}
path: pcd-website/src/content/events/
retention-days: 1
- name: Upload PR body artifact
if: steps.generate.outputs.valid == 'true'
uses: actions/upload-artifact@v4
with:
name: pr-body-${{ github.event.issue.number }}
path: ${{ steps.generate.outputs.pr_body_path }}
retention-days: 1
- name: Upload validation comment artifact
if: steps.generate.outputs.valid == 'false'
uses: actions/upload-artifact@v4
with:
name: validation-comment-${{ github.event.issue.number }}
path: ${{ steps.generate.outputs.validation_comment_path }}
retention-days: 1
process-edit-event:
if: contains(github.event.issue.labels.*.name, 'edit event')
runs-on: ubuntu-latest
timeout-minutes: 10
env:
PCD_TEAM_ASSIGNEES: ${{ vars.PCD_TEAM_ASSIGNEES }}
PCD_TEAM_REVIEWERS: ${{ vars.PCD_TEAM_REVIEWERS }}
outputs:
valid: ${{ steps.generate.outputs.valid }}
branch: ${{ steps.generate.outputs.branch }}
commit_message: ${{ steps.generate.outputs.commit_message }}
pr_title: ${{ steps.generate.outputs.pr_title }}
pr_body_path: ${{ steps.generate.outputs.pr_body_path }}
validation_comment_path: ${{ steps.generate.outputs.validation_comment_path }}
event_name: ${{ steps.generate.outputs.event_name }}
pr_label: ${{ steps.generate.outputs.pr_label }}
action_verb: ${{ steps.generate.outputs.action_verb }}
steps:
- name: Log trigger context
run: |
echo "event_action=${{ github.event.action }}"
echo "issue_number=${{ github.event.issue.number }}"
echo "issue_labels=${{ join(github.event.issue.labels.*.name, ', ') }}"
echo "sender=${{ github.event.sender.login }}"
- name: Label and assign intake issue
uses: actions/github-script@v8
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue_number = context.issue.number;
const desiredLabels = [
{ name: 'needs review', color: 'fbca04', description: 'Submission is ready for maintainer review' },
{ name: 'edit event', color: '0075ca', description: 'Edit event submission intake' },
];
for (const label of desiredLabels) {
try {
await github.rest.issues.getLabel({ owner, repo, name: label.name });
} catch (error) {
if (error.status !== 404) throw error;
await github.rest.issues.createLabel({ owner, repo, ...label });
}
}
await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: desiredLabels.map((label) => label.name),
});
const assignees = (process.env.PCD_TEAM_ASSIGNEES || '')
.split(',')
.map((value) => value.trim())
.filter(Boolean);
if (assignees.length) {
await github.rest.issues.addAssignees({
owner,
repo,
issue_number,
assignees,
});
}
- uses: actions/checkout@v6
with:
ref: ${{ github.event.repository.default_branch }}
persist-credentials: false
- uses: actions/setup-node@v6
with:
node-version: '24'
- name: Install script dependencies
run: npm install --prefix /tmp/script-deps open-location-code
- name: Generate event files from issue
id: generate
run: node .github/scripts/process-edit-event-issue.mjs
- name: Log generate outputs
if: always()
run: |
echo "valid=${{ steps.generate.outputs.valid }}"
echo "branch=${{ steps.generate.outputs.branch }}"
echo "event_name=${{ steps.generate.outputs.event_name }}"
echo "validation_comment_path=${{ steps.generate.outputs.validation_comment_path }}"
echo "pr_body_path=${{ steps.generate.outputs.pr_body_path }}"
- name: Log PR body
if: steps.generate.outputs.valid == 'true'
run: cat "${{ steps.generate.outputs.pr_body_path }}"
- name: Log validation comment
if: steps.generate.outputs.valid == 'false'
run: cat "${{ steps.generate.outputs.validation_comment_path }}"
- name: Upload event files artifact
if: steps.generate.outputs.valid == 'true'
uses: actions/upload-artifact@v4
with:
name: event-files-${{ github.event.issue.number }}
path: pcd-website/src/content/events/
retention-days: 1
- name: Upload PR body artifact
if: steps.generate.outputs.valid == 'true'
uses: actions/upload-artifact@v4
with:
name: pr-body-${{ github.event.issue.number }}
path: ${{ steps.generate.outputs.pr_body_path }}
retention-days: 1
- name: Upload validation comment artifact
if: steps.generate.outputs.valid == 'false'
uses: actions/upload-artifact@v4
with:
name: validation-comment-${{ github.event.issue.number }}
path: ${{ steps.generate.outputs.validation_comment_path }}
retention-days: 1
handle-validation-failure:
needs: [process-new-event, process-edit-event]
if: |
always() && (
(needs.process-new-event.result != 'skipped' && (
needs.process-new-event.result == 'failure' ||
needs.process-new-event.outputs.valid == 'false'
)) ||
(needs.process-edit-event.result != 'skipped' && (
needs.process-edit-event.result == 'failure' ||
needs.process-edit-event.outputs.valid == 'false'
))
)
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Download validation comment artifact
uses: actions/download-artifact@v4
with:
name: validation-comment-${{ github.event.issue.number }}
path: /tmp/validation-comment
- name: Upsert validation status comment
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const marker = process.env.STATUS_COMMENT_MARKER;
const commentPath = `/tmp/validation-comment/validation-${context.issue.number}.md`;
const body = `${marker}\n${fs.readFileSync(commentPath, 'utf8')}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find((comment) =>
comment.user?.type === 'Bot' &&
comment.body?.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
create-pr:
needs: [process-new-event, process-edit-event]
if: |
always() && (
(needs.process-new-event.result != 'skipped' && needs.process-new-event.outputs.valid == 'true') ||
(needs.process-edit-event.result != 'skipped' && needs.process-edit-event.outputs.valid == 'true')
)
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
pull-request-number: ${{ steps.create_pr.outputs.pull-request-number }}
pull-request-url: ${{ steps.create_pr.outputs.pull-request-url }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.repository.default_branch }}
- name: Download event files artifact
uses: actions/download-artifact@v4
with:
name: event-files-${{ github.event.issue.number }}
path: pcd-website/src/content/events/
- name: Download PR body artifact
uses: actions/download-artifact@v4
with:
name: pr-body-${{ github.event.issue.number }}
path: /tmp/pr-body
- name: Log resolved PR inputs
run: |
echo "branch=${{ needs.process-new-event.outputs.branch || needs.process-edit-event.outputs.branch }}"
echo "title=${{ needs.process-new-event.outputs.pr_title || needs.process-edit-event.outputs.pr_title }}"
echo "body_path=/tmp/pr-body/pr-body-${{ github.event.issue.number }}.md"
cat "/tmp/pr-body/pr-body-${{ github.event.issue.number }}.md"
- name: Create pull request
id: create_pr
uses: peter-evans/create-pull-request@v8
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ needs.process-new-event.outputs.branch || needs.process-edit-event.outputs.branch }}
delete-branch: true
add-paths: |
pcd-website/src/content/events/**
commit-message: ${{ needs.process-new-event.outputs.commit_message || needs.process-edit-event.outputs.commit_message }}
title: ${{ needs.process-new-event.outputs.pr_title || needs.process-edit-event.outputs.pr_title }}
body-path: /tmp/pr-body/pr-body-${{ github.event.issue.number }}.md
- name: Log create-pr outputs
if: always()
run: |
echo "pull-request-number=${{ steps.create_pr.outputs.pull-request-number }}"
echo "pull-request-url=${{ steps.create_pr.outputs.pull-request-url }}"
post-pr-actions:
needs: [process-new-event, process-edit-event, create-pr]
if: always() && needs.create-pr.outputs.pull-request-number != ''
runs-on: ubuntu-latest
timeout-minutes: 5
env:
PCD_TEAM_REVIEWERS: ${{ vars.PCD_TEAM_REVIEWERS }}
steps:
- name: Label pull request
uses: actions/github-script@v8
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue_number = Number('${{ needs.create-pr.outputs.pull-request-number }}');
const prLabel = '${{ needs.process-new-event.outputs.pr_label || needs.process-edit-event.outputs.pr_label }}';
const desiredLabels = [
{ name: 'needs review', color: 'fbca04', description: 'Submission is ready for maintainer review' },
{ name: prLabel, color: prLabel === 'new event' ? '0e8a16' : '0075ca', description: prLabel === 'new event' ? 'New event submission intake' : 'Edit event submission intake' },
];
for (const label of desiredLabels) {
try {
await github.rest.issues.getLabel({ owner, repo, name: label.name });
} catch (error) {
if (error.status !== 404) throw error;
await github.rest.issues.createLabel({ owner, repo, ...label });
}
}
await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: desiredLabels.map((label) => label.name),
});
- name: Request team review
if: env.PCD_TEAM_REVIEWERS != ''
uses: actions/github-script@v8
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const pull_number = Number('${{ needs.create-pr.outputs.pull-request-number }}');
const team_reviewers = (process.env.PCD_TEAM_REVIEWERS || '')
.split(',')
.map((value) => value.trim())
.filter(Boolean);
if (team_reviewers.length) {
await github.rest.pulls.requestReviewers({
owner,
repo,
pull_number,
team_reviewers,
});
}
- name: Upsert pull request status comment
uses: actions/github-script@v8
env:
PR_NUMBER: ${{ needs.create-pr.outputs.pull-request-number }}
PR_URL: ${{ needs.create-pr.outputs.pull-request-url }}
EVENT_NAME: ${{ needs.process-new-event.outputs.event_name || needs.process-edit-event.outputs.event_name }}
ACTION_VERB: ${{ needs.process-new-event.outputs.action_verb || needs.process-edit-event.outputs.action_verb }}
with:
script: |
const marker = process.env.STATUS_COMMENT_MARKER;
const body = [
marker,
`**${process.env.EVENT_NAME}** has been successfully parsed and a pull request has been opened for review: [#${process.env.PR_NUMBER}](${process.env.PR_URL}).`,
'',
`Once the PR is merged, your event will be **${process.env.ACTION_VERB}** the map at https://day.processing.org.`,
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find((comment) =>
comment.user?.type === 'Bot' &&
comment.body?.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}