11
11
permissions :
12
12
contents : write
13
13
pull-requests : write
14
+ checks : write
14
15
15
16
jobs :
16
- release-please :
17
- name : Release Please
17
+ release :
18
18
outputs :
19
19
pr : ${{ steps.release.outputs.pr }}
20
- release : ${{ steps.release.outputs.release }}
20
+ releases : ${{ steps.release.outputs.releases }}
21
+ release-flags : ${{ steps.release.outputs.release-flags }}
22
+ branch : ${{ steps.release.outputs.pr-branch }}
23
+ pr-number : ${{ steps.release.outputs.pr-number }}
24
+ comment-id : ${{ steps.pr-comment.outputs.result }}
25
+ check-id : ${{ steps.check.outputs.check_id }}
26
+ name : Release
21
27
if : github.repository_owner == 'npm'
22
28
runs-on : ubuntu-latest
29
+ defaults :
30
+ run :
31
+ shell : bash
23
32
steps :
24
33
- name : Checkout
25
34
uses : actions/checkout@v3
@@ -37,29 +46,72 @@ jobs:
37
46
run : npm -v
38
47
- name : Install Dependencies
39
48
run : npm i --ignore-scripts --no-audit --no-fund
40
- - name : npx template-oss-release-please ${{ github.ref_name }}
49
+ - name : Release Please
41
50
id : release
42
51
env :
43
52
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
44
- run : npx --offline template-oss-release-please ${{ github.ref_name }}
53
+ run : |
54
+ npx --offline template-oss-release-please ${{ github.ref_name }}
55
+ - name : Post Pull Request Comment
56
+ if : steps.release.outputs.pr-number
57
+ uses : actions/github-script@v6
58
+ id : pr-comment
59
+ env :
60
+ PR_NUMBER : ${{ steps.release.outputs.pr-number }}
61
+ with :
62
+ script : |
63
+ const repo = { owner: context.repo.owner, repo: context.repo.repo }
64
+ const issue = { ...repo, issue_number: process.env.PR_NUMBER }
45
65
46
- post-pr :
47
- name : Post Pull Request
48
- needs : release-please
49
- if : needs.release-please.outputs.pr
50
- runs-on : ubuntu-latest
66
+ const { data: workflow } = await github.rest.actions.getWorkflowRun({ ...repo, run_id: context.runId })
67
+
68
+ let body = '## Release Manager\n\n'
69
+
70
+ const comments = await github.paginate(github.rest.issues.listComments, issue)
71
+ let commentId = comments?.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id
72
+
73
+ body += `- Release workflow run: ${workflow.html_url}`
74
+ if (commentId) {
75
+ await github.rest.issues.updateComment({ ...repo, comment_id: commentId, body })
76
+ } else {
77
+ const { data: comment } = await github.rest.issues.createComment({ ...issue, body })
78
+ commentId = comment?.id
79
+ }
80
+
81
+ return commentId
82
+ - name : Create Check
83
+ uses :
LouisBrunner/[email protected]
84
+ id : check
85
+ if : steps.release.outputs.pr-number
86
+ with :
87
+ token : ${{ secrets.GITHUB_TOKEN }}
88
+ status : in_progress
89
+ name : Release
90
+ sha : ${{ steps.release.outputs.pr-sha }}
91
+ # XXX: this does not work when using the default GITHUB_TOKEN.
92
+ # Instead we post the main job url to the PR as a comment which
93
+ # will link to all the other checks. To work around this we would
94
+ # need to create a GitHub that would create on-demand tokens.
95
+ # https://github.com/LouisBrunner/checks-action/issues/18
96
+ # details_url:
97
+
98
+ update :
99
+ needs : release
51
100
outputs :
52
- ref : ${{ steps.ref.outputs.branch }}
53
101
sha : ${{ steps.commit.outputs.sha }}
102
+ check-id : ${{ steps.check.outputs.check_id }}
103
+ name : Update - Release
104
+ if : github.repository_owner == 'npm' && needs.release.outputs.pr
105
+ runs-on : ubuntu-latest
106
+ defaults :
107
+ run :
108
+ shell : bash
54
109
steps :
55
- - name : Output PR Head Branch
56
- id : ref
57
- run : echo "::set-output name=branch::${{ fromJSON(needs.release-please.outputs.pr).headBranchName }}"
58
110
- name : Checkout
59
111
uses : actions/checkout@v3
60
112
with :
61
113
fetch-depth : 0
62
- ref : ${{ steps.ref .outputs.branch }}
114
+ ref : ${{ needs.release .outputs.branch }}
63
115
- name : Setup Git User
64
116
run : |
65
117
git config --global user.email "[email protected] "
@@ -75,30 +127,89 @@ jobs:
75
127
- name : Install Dependencies
76
128
run : npm i --ignore-scripts --no-audit --no-fund
77
129
- name : Run Post Pull Request Actions
78
- run : npm run rp-pull-request --ignore-scripts -ws -iwr --if-present
79
- - name : Commit and Push
130
+ env :
131
+ RELEASE_PR_NUMBER : ${{ needs.release.outputs.pr-number }}
132
+ RELEASE_COMMENT_ID : ${{ needs.release.outputs.comment-id }}
133
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
134
+ run : |
135
+ npm run rp-pull-request --ignore-scripts -ws -iwr --if-present
136
+ - name : Commit
80
137
id : commit
81
138
env :
82
139
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
83
140
run : |
84
- git commit -am "chore: post pull request" || true
85
- echo "::set-output sha=$(git rev-parse HEAD)"
86
- git push
141
+ git commit --all --amend --no-edit || true
142
+ git push --force-with-lease
143
+ echo "::set-output name=sha::$(git rev-parse HEAD)"
144
+ - name : Create Check
145
+ uses :
LouisBrunner/[email protected]
146
+ id : check
147
+
148
+ with :
149
+ token : ${{ secrets.GITHUB_TOKEN }}
150
+ status : in_progress
151
+ name : Release
152
+ sha : ${{ steps.commit.outputs.sha }}
153
+ # XXX: this does not work when using the default GITHUB_TOKEN.
154
+ # Instead we post the main job url to the PR as a comment which
155
+ # will link to all the other checks. To work around this we would
156
+ # need to create a GitHub that would create on-demand tokens.
157
+ # https://github.com/LouisBrunner/checks-action/issues/18
158
+ # details_url:
159
+ - name : Conclude Check
160
+ uses :
LouisBrunner/[email protected]
161
+ if : always()
162
+ with :
163
+ token : ${{ secrets.GITHUB_TOKEN }}
164
+ conclusion : ${{ job.status }}
165
+ check_id : ${{ needs.release.outputs.check-id }}
87
166
88
- release-test :
89
- name : Test
90
- needs : post-pr
91
- if : needs.post-pr .outputs.ref
167
+ ci :
168
+ name : CI - Release
169
+ needs : [ release, update ]
170
+ if : needs.release .outputs.pr
92
171
uses : ./.github/workflows/ci-release.yml
93
172
with :
94
- ref : ${{ needs.post-pr.outputs.ref }}
95
- sha : ${{ needs.post-pr.outputs.sha }}
173
+ ref : ${{ needs.release.outputs.branch }}
174
+ check-sha : ${{ needs.update.outputs.sha }}
175
+
176
+ post-ci :
177
+ needs : [ release, update, ci ]
178
+ name : Post CI - Release
179
+ if : github.repository_owner == 'npm' && needs.release.outputs.pr && always()
180
+ runs-on : ubuntu-latest
181
+ defaults :
182
+ run :
183
+ shell : bash
184
+ steps :
185
+ - name : Get Needs Result
186
+ id : needs-result
187
+ run : |
188
+ result=""
189
+ if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
190
+ result="failure"
191
+ elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
192
+ result="cancelled"
193
+ else
194
+ result="success"
195
+ fi
196
+ echo "::set-output name=result::$result"
197
+ - name : Conclude Check
198
+ uses :
LouisBrunner/[email protected]
199
+ if : always()
200
+ with :
201
+ token : ${{ secrets.GITHUB_TOKEN }}
202
+ conclusion : ${{ steps.needs-result.outputs.result }}
203
+ check_id : ${{ needs.update.outputs.check-id }}
96
204
97
205
post-release :
98
- name : Post Release
99
- needs : release-please
100
- if : github.repository_owner == 'npm' && needs.release-please .outputs.release
206
+ needs : release
207
+ name : Post Release - Release
208
+ if : github.repository_owner == 'npm' && needs.release.outputs.releases
101
209
runs-on : ubuntu-latest
210
+ defaults :
211
+ run :
212
+ shell : bash
102
213
steps :
103
214
- name : Checkout
104
215
uses : actions/checkout@v3
@@ -117,5 +228,7 @@ jobs:
117
228
- name : Install Dependencies
118
229
run : npm i --ignore-scripts --no-audit --no-fund
119
230
- name : Run Post Release Actions
231
+ env :
232
+ RELEASES : ${{ needs.release.outputs.releases }}
120
233
run : |
121
- npm run rp-release --ignore-scripts -ws -iwr -- if-present
234
+ npm run rp-release --ignore-scripts -- if-present ${{ join(fromJSON(needs.release.outputs.release-flags), ' ') }}
0 commit comments