forked from DataDog/dd-trace-java
-
Notifications
You must be signed in to change notification settings - Fork 3
176 lines (168 loc) · 6.83 KB
/
draft-release-notes-on-tag.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
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
name: Draft release notes on tag
on:
create:
workflow_dispatch:
jobs:
draft_release_notes:
name: Draft release notes
if: (github.event.ref_type == 'tag' && github.event.master_branch == 'master') || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Get milestone title
id: milestoneTitle
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # 6.4.1
with:
result-encoding: string
script: |
// Get the milestone title ("X.Y.Z") from tag name ("vX.Y.Z(-rc)")
const match = '${{github.event.ref}}'.match(/v(\d+\.\d+\.\d+)(?:-rc\d+)?/i)
if (!match) {
core.setFailed('Failed to parse tag name into milestone name: ${{github.event.ref}}')
return
}
const milestoneTitle = match[1]
// Look for the milestone
const milestone = (await github.paginate('GET /repos/{owner}/{repo}/milestones', {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all'
})).find(m => m.title == milestoneTitle)
if (!milestone) {
core.setFailed(`Failed to find milestone: ${milestoneTitle}`)
return
}
// Get pull requests of the milestone
const pullRequests = (await github.paginate('/repos/{owner}/{repo}/issues', {
owner: context.repo.owner,
repo: context.repo.repo,
milestone: milestone.number,
state: 'closed'
}))
.filter(i => i.pull_request && i.pull_request.merged_at) // Skip closed but not merged
.filter(p => !p.labels.find(label => label.name == 'tag: no release notes')) // Skip excluded
// Group PR by components and instrumentations
var prByComponents = new Map()
var prByInstrumentations = new Map()
var otherPRs = new Array()
for (let pullRequest of pullRequests) {
var captured = false
for (let label of pullRequest.labels) {
const index = label.name.indexOf(':')
if (index == -1) {
core.notice('Unsupported label: ${label.name}')
continue
}
const labelKey = label.name.substring(0, index)
const labelValue = label.name.slice(index + 1)
var map = null
if (labelKey == 'comp') {
map = prByComponents
} else if (labelKey == 'inst') {
map = prByInstrumentations
}
if (map) {
var prs = map.get(label.description)
if (!prs) {
prs = new Array()
map.set(label.description, prs)
}
prs.push(pullRequest)
captured = true
}
}
if (!captured) {
otherPRs.push(pullRequest)
}
}
// Sort components and instrumenations
prByComponents = new Map([...prByComponents].sort());
const lastInstrumentation = 'All other instrumentations'
prByInstrumentations = new Map([...prByInstrumentations].sort(
(a, b) => {
if (a[0] == lastInstrumentation) {
return 1
} else if (b[0] == lastInstrumentation) {
return -1
}
return String(a[0]).localeCompare(b[0])
}
));
// Generate changelog
const decorators = {
'tag: breaking change': ':warning:',
'tag: experimental': ':test_tube:',
'tag: diagnostics': ':mag:',
'tag: performance': ':zap:',
'tag: security': ':closed_lock_with_key:',
'type: bug': ':bug:',
'type: documentation': ':book:',
'type: enhancement': ':sparkles:',
'type: feature request': ':bulb:',
'type: refactoring': ':broom:'
}
function decorate(pullRequest) {
var line = ''
var decorated = false;
for (let label of pullRequest.labels) {
if (decorators[label.name]) {
line += decorators[label.name]
decorated = true
}
}
if (decorated) {
line += ' '
}
return line
}
function cleanUpTitle(title) {
// Remove tags between brackets
return title.replace(/\[[^\]]+\]/g, '')
}
function format(pullRequest) {
var line = `${decorate(pullRequest)}${cleanUpTitle(pullRequest.title)} (#${pullRequest.number} - @${pullRequest.user.login}`
// Add special thanks if community labeled
if (pullRequest.labels.some(label => label.name == "tag: community")) {
line += ` - thanks for the contribution!`
}
line += ')'
return line;
}
var changelog = ''
if ('${{github.event.ref}}'.match(/rc/i)) {
changelog += ':warning: This is a RELEASE CANDIDATE and is NOT intended for use in production. Please contact Datadog support regarding any problems in this RC.\n'
}
if (prByComponents.size > 0) {
changelog += '# Components\n\n';
for (let pair of prByComponents) {
changelog += '## '+pair[0]+'\n\n'
for (let pullRequest of pair[1]) {
changelog += '* ' + format(pullRequest) + '\n'
}
changelog += '\n'
}
}
if (prByInstrumentations.size > 0) {
changelog += '# Instrumentations\n\n'
for (let pair of prByInstrumentations) {
changelog += '## '+pair[0]+'\n\n'
for (let pullRequest of pair[1]) {
changelog += '* ' + format(pullRequest) + '\n'
}
changelog += '\n'
}
}
if (otherPRs.length > 0) {
changelog += '# Other changes\n\n'
for (let pullRequest of otherPRs) {
changelog += '* ' + format(pullRequest) + '\n'
}
}
// Create release with the draft changelog
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ github.event.ref }}',
name: milestoneTitle,
draft: true,
body: changelog
})