-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrelease.yml
217 lines (196 loc) · 8.85 KB
/
release.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
name: Release
on:
workflow_dispatch:
inputs:
release-pr:
description: a release PR number to rerun release jobs on
type: string
push:
branches:
{{#each branches}}
- {{ . }}
{{/each}}
permissions:
contents: write
pull-requests: write
checks: write
jobs:
release:
outputs:
pr: $\{{ steps.release.outputs.pr }}
release: $\{{ steps.release.outputs.release }}
releases: $\{{ steps.release.outputs.releases }}
branch: $\{{ steps.release.outputs.pr-branch }}
pr-number: $\{{ steps.release.outputs.pr-number }}
comment-id: $\{{ steps.pr-comment.outputs.result }}
check-id: $\{{ steps.check.outputs.check_id }}
{{> job jobName="Release" }}
- name: Release Please
id: release
env:
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
run: |
{{ rootNpxPath }} --offline template-oss-release-please "$\{{ github.ref_name }}" "$\{{ inputs.release-pr }}"
- name: Post Pull Request Comment
if: steps.release.outputs.pr-number
uses: actions/github-script@v6
id: pr-comment
env:
PR_NUMBER: $\{{ steps.release.outputs.pr-number }}
REF_NAME: $\{{ github.ref_name }}
with:
script: |
const { REF_NAME, PR_NUMBER: issue_number } = process.env
const { runId, repo: { owner, repo } } = context
const { data: workflow } = await github.rest.actions.getWorkflowRun({ owner, repo, run_id: runId })
let body = '## Release Manager\n\n'
const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number })
let commentId = comments.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id
body += `Release workflow run: ${workflow.html_url}\n\n#### Force CI to Update This Release\n\n`
body += `This PR will be updated and CI will run for every non-\`chore:\` commit that is pushed to \`{{ defaultBranch }}\`. `
body += `To force CI to update this PR, run this command:\n\n`
body += `\`\`\`\ngh workflow run release.yml -r ${REF_NAME} -R ${owner}/${repo} -f release-pr=${issue_number}\n\`\`\``
if (commentId) {
await github.rest.issues.updateComment({ owner, repo, comment_id: commentId, body })
} else {
const { data: comment } = await github.rest.issues.createComment({ owner, repo, issue_number, body })
commentId = comment?.id
}
return commentId
{{> stepChecks jobCheck=(obj name="Release" sha="steps.release.outputs.pr-sha") }}
update:
needs: release
outputs:
sha: $\{{ steps.commit.outputs.sha }}
check-id: $\{{ steps.check.outputs.check_id }}
{{> job
jobName="Update - Release"
jobIf="needs.release.outputs.pr"
jobCheckout=(obj ref="${{ needs.release.outputs.branch }}" fetch-depth=0)
}}
- name: Run Post Pull Request Actions
env:
RELEASE_PR_NUMBER: $\{{ needs.release.outputs.pr-number }}
RELEASE_COMMENT_ID: $\{{ needs.release.outputs.comment-id }}
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
run: |
{{ rootNpmPath }} exec --offline -- template-oss-release-manager --lockfile={{ lockfile }} --publish={{ publish }}
{{ rootNpmPath }} run rp-pull-request --ignore-scripts {{~#if allFlags}} {{ allFlags }}{{else}} --if-present{{/if}}
- name: Commit
id: commit
env:
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
run: |
git commit --all --amend --no-edit || true
git push --force-with-lease
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
{{> stepChecks jobName="Update - Release" jobCheck=(obj sha="steps.commit.outputs.sha" name="Release" )}}
{{> stepChecks jobCheck=(obj id="needs.release.outputs.check-id" )}}
ci:
name: CI - Release
needs: [release, update]
if: needs.release.outputs.pr
uses: ./.github/workflows/ci-release.yml
with:
ref: $\{{ needs.release.outputs.branch }}
check-sha: $\{{ needs.update.outputs.sha }}
post-ci:
needs: [release, update, ci]
{{> job jobName="Post CI - Release" jobIf="needs.release.outputs.pr && always()" jobSkipSetup=true }}
- name: Get Needs Result
id: needs-result
run: |
result=""
if [[ "$\{{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
result="failure"
elif [[ "$\{{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
result="cancelled"
else
result="success"
fi
echo "result=$result" >> $GITHUB_OUTPUT
{{> stepChecks jobCheck=(obj id="needs.update.outputs.check-id" status="steps.needs-result.outputs.result") }}
post-release:
needs: release
{{> job jobName="Post Release - Release" jobIf="needs.release.outputs.releases" jobSkipSetup=true }}
- name: Create Release PR Comment
uses: actions/github-script@v6
env:
RELEASES: $\{{ needs.release.outputs.releases }}
with:
script: |
const releases = JSON.parse(process.env.RELEASES)
const { runId, repo: { owner, repo } } = context
const issue_number = releases[0].prNumber
let body = '## Release Workflow\n\n'
for (const { pkgName, version, url } of releases) {
body += `- \`${pkgName}@${version}\` ${url}\n`
}
const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number })
.then(cs => cs.map(c => ({ id: c.id, login: c.user.login, body: c.body })))
console.log(`Found comments: ${JSON.stringify(comments, null, 2)}`)
const releaseComments = comments.filter(c => c.login === 'github-actions[bot]' && c.body.includes('Release is at'))
for (const comment of releaseComments) {
console.log(`Release comment: ${JSON.stringify(comment, null, 2)}`)
await github.rest.issues.deleteComment({ owner, repo, comment_id: comment.id })
}
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: `${body}- Workflow run: :arrows_counterclockwise: ${runUrl}`,
})
release-integration:
needs: release
name: Release Integration
if: needs.release.outputs.release
{{> jobReleaseIntegration }}
post-release-integration:
needs: [release, release-integration]
{{> job jobName="Post Release Integration - Release" jobIf="needs.release.outputs.release && always()" jobSkipSetup=true }}
- name: Get Needs Result
id: needs-result
run: |
if [[ "$\{{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
result="x"
elif [[ "$\{{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
result="heavy_multiplication_x"
else
result="white_check_mark"
fi
echo "result=$result" >> $GITHUB_OUTPUT
- name: Update Release PR Comment
uses: actions/github-script@v6
env:
PR_NUMBER: $\{{ fromJSON(needs.release.outputs.release).prNumber }}
RESULT: $\{{ steps.needs-result.outputs.result }}
with:
script: |
const { PR_NUMBER: issue_number, RESULT } = process.env
const { runId, repo: { owner, repo } } = context
const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number })
const updateComment = comments.find(c =>
c.user.login === 'github-actions[bot]' &&
c.body.startsWith('## Release Workflow\n\n') &&
c.body.includes(runId)
)
if (updateComment) {
console.log('Found comment to update:', JSON.stringify(updateComment, null, 2))
let body = updateComment.body.replace(/Workflow run: :[a-z_]+:/, `Workflow run: :${RESULT}:`)
const tagCodeowner = RESULT !== 'white_check_mark'
if (tagCodeowner) {
body += `\n\n:rotating_light:`
body += ` {{ codeowner }}: The post-release workflow failed for this release.`
body += ` Manual steps may need to be taken after examining the workflow output`
body += ` from the above workflow run. :rotating_light:`
}
await github.rest.issues.updateComment({
owner,
repo,
body,
comment_id: updateComment.id,
})
} else {
console.log('No matching comments found:', JSON.stringify(comments, null, 2))
}