-
-
Notifications
You must be signed in to change notification settings - Fork 11
140 lines (118 loc) · 4.84 KB
/
infra-meeting-release.yaml
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
name: "Prepare infra meeting notes as release"
on:
workflow_dispatch:
inputs:
milestone_id:
description: '"Current" milestone id to prepare as release'
required: true
type: string
milestone_name:
description: '"Current" milestone name'
required: true
default: 'current'
type: string
jobs:
release:
name: "Prepare infra meeting notes as release"
runs-on: "ubuntu-latest"
steps:
- name: "Get current date"
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: "Generate markdown from current milestone"
id: milestones_as_markdown
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const getMilestoneAsMarkdown = async function(milestone, milestoneName, issuesState, closeReason, labels) {
const opts = github.rest.issues.listForRepo.endpoint.merge({
...context.issue,
milestone,
state: issuesState,
sort: 'created',
direction: 'desc',
per_page: 100,
labels: labels,
})
const issues = await github.paginate(opts)
let markdown = ''
let category = ''
let query = ''
if (issuesState == 'open') {
if (labels == 'triage') {
category = 'New Issues (to triage)'
} else {
category = 'Work in Progress'
}
} else {
// issues states can only be 'closed' if not 'open'
query = '?closed=1'
if (closeReason == 'completed') {
category = 'Done'
} else {
// Close reason can only be "Not planned" if not "Completed"
category = 'Closed as not planned'
}
}
title = `* [${category}](${context.payload.repository.html_url}/milestone/${milestone}${query}):`
if (issues.length > 0) {
for (const issue of issues) {
if ((issuesState == 'open') || ((issuesState == 'closed') && (issue.state_reason == closeReason))){
markdown = markdown.concat("\r\n").concat(` * [${issue.title}](${issue.html_url})`)
}
}
}
if (markdown != '') markdown = title.concat("\r\n").concat(markdown)
return markdown
}
done = await getMilestoneAsMarkdown(context.payload.inputs.milestone_id, context.payload.inputs.milestone_name, 'closed', 'completed', '')
notPlanned = await getMilestoneAsMarkdown(context.payload.inputs.milestone_id, context.payload.inputs.milestone_name, 'closed', 'not_planned', '')
wip = await getMilestoneAsMarkdown(context.payload.inputs.milestone_id, context.payload.inputs.milestone_name, 'open', '', '')
try {
todoMilestone = parseInt(context.payload.inputs.milestone_id) + 1
todo = await getMilestoneAsMarkdown('', context.payload.inputs.milestone_name, 'open', '', 'triage')
} catch (error) {
console.error(error);
todo = ''
}
return `Markdown for the infra team sync meeting notes preparation:
<pre><code>
${done}
${notPlanned}
${wip}
${todo}
</code></pre>
<details><summary>Preview:</summary>
${done}
* New items:
* placeholder 1
* placeholder 2
${wip}
${todo}
</details>
Generated from the ["${context.payload.inputs.milestone_name}"](${context.payload.repository.html_url}/milestone/${context.payload.inputs.milestone_id}) milestones.`
- name: "Create release"
id: create_release
uses: actions/github-script@v6
env:
CURRENT_DATE: ${{ steps.date.outputs.date }}
RELEASE_BODY: ${{steps.milestones_as_markdown.outputs.result}}
with:
script: |
name = `infra-team-sync-${process.env.CURRENT_DATE}`
tag = `${name}_${context.runNumber}`
try {
await github.rest.repos.createRelease({
name: name,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.RELEASE_BODY,
tag_name: tag,
draft: true,
generate_release_notes: true,
prerelease: false,
});
} catch (error) {
core.setFailed(error.message);
}