-
-
Notifications
You must be signed in to change notification settings - Fork 11
146 lines (125 loc) · 5.37 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
141
142
143
144
145
146
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
next_milestone_id:
description: '"Next" milestone id'
required: true
# "permanent" 'next' milestone: https://github.com/jenkins-infra/helpdesk/milestone/10
default: '10'
type: string
next_milestone_name:
description: '"Next" milestone name'
required: true
default: 'next'
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 and next milestone"
id: milestones_as_markdown
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const getMilestoneAsMarkdown = async function(milestone, milestoneName, issuesState, closeReason) {
const opts = github.rest.issues.listForRepo.endpoint.merge({
...context.issue,
milestone,
state: issuesState,
sort: 'created',
direction: 'desc',
per_page: 100,
})
const issues = await github.paginate(opts)
let markdown = ''
let category = (closeReason == 'completed') ? 'Done' : 'Closed as not planned'
let query = '?closed=1'
// There should not be any closed issue in the 'next' milestone, only 'Done' ones
if (issuesState == 'open') {
category = (milestoneName != 'next') ? 'Work In Progress' : 'Backlog'
if (milestoneName == 'todo') category = 'TODO (next milestone)'
query = ''
}
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))){
const assigned = issues.assignees ? issues.assignees.join(', ') : 'unassigned'
markdown = markdown.concat("\r\n").concat(` * [${issue.title}](${issue.html_url}) (${assigned})`)
}
}
}
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(todoMilestone, 'todo', 'open', '')
} catch (error) {
console.error(error);
todo = ''
}
next = await getMilestoneAsMarkdown(context.payload.inputs.next_milestone_id, context.payload.inputs.next_milestone_name, 'open', '')
return `Markdown for the infra team sync meeting notes preparation:
<pre><code>
${done}
${notPlanned}
${wip}
<!--
${next}
-->
</code></pre>
<details><summary>Preview:</summary>
${done}
* New items:
* placeholder 1
* placeholder 2
${wip}
${todo}
<!--
${next}
-->
</details>
Generated from the ["${context.payload.inputs.milestone_name}"](${context.payload.repository.html_url}/milestone/${context.payload.inputs.milestone_id}) and the ["${context.payload.inputs.next_milestone_name}"](${context.payload.repository.html_url}/milestone/${context.payload.inputs.next_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);
}