Skip to content

Commit 3640080

Browse files
committed
feat: add checks to release pull request
1 parent 5b65537 commit 3640080

32 files changed

+1113
-309
lines changed

.github/workflows/audit.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ on:
1010

1111
jobs:
1212
audit:
13-
name: Audit
13+
name: Audit Dependencies
1414
if: github.repository_owner == 'npm'
1515
runs-on: ubuntu-latest
16+
defaults:
17+
run:
18+
shell: bash
1619
steps:
1720
- name: Checkout
1821
uses: actions/checkout@v3

.github/workflows/ci-release.yml

+50
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,34 @@ on:
88
ref:
99
required: true
1010
type: string
11+
check-sha:
12+
required: true
13+
type: string
1114

1215
jobs:
1316
lint-all:
1417
name: Lint All
1518
if: github.repository_owner == 'npm'
1619
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
shell: bash
1723
steps:
24+
- name: Create Check
25+
uses: LouisBrunner/[email protected]
26+
id: check
27+
28+
with:
29+
token: ${{ secrets.GITHUB_TOKEN }}
30+
status: in_progress
31+
name: Lint All
32+
sha: ${{ inputs.check-sha }}
33+
# XXX: this does not work when using the default GITHUB_TOKEN.
34+
# Instead we post the main job url to the PR as a comment which
35+
# will link to all the other checks. To work around this we would
36+
# need to create a GitHub that would create on-demand tokens.
37+
# https://github.com/LouisBrunner/checks-action/issues/18
38+
# details_url:
1839
- name: Checkout
1940
uses: actions/checkout@v3
2041
with:
@@ -37,6 +58,13 @@ jobs:
3758
run: npm run lint --ignore-scripts
3859
- name: Post Lint
3960
run: npm run postlint --ignore-scripts
61+
- name: Conclude Check
62+
uses: LouisBrunner/[email protected]
63+
if: always()
64+
with:
65+
token: ${{ secrets.GITHUB_TOKEN }}
66+
conclusion: ${{ job.status }}
67+
check_id: ${{ steps.check.outputs.check_id }}
4068

4169
test-all:
4270
name: Test All - ${{ matrix.platform.name }} - Node ${{ matrix.node-version }}
@@ -66,6 +94,21 @@ jobs:
6694
run:
6795
shell: ${{ matrix.platform.shell }}
6896
steps:
97+
- name: Create Check
98+
uses: LouisBrunner/[email protected]
99+
id: check
100+
101+
with:
102+
token: ${{ secrets.GITHUB_TOKEN }}
103+
status: in_progress
104+
name: Test All - ${{ matrix.platform.name }} - Node ${{ matrix.node-version }}
105+
sha: ${{ inputs.check-sha }}
106+
# XXX: this does not work when using the default GITHUB_TOKEN.
107+
# Instead we post the main job url to the PR as a comment which
108+
# will link to all the other checks. To work around this we would
109+
# need to create a GitHub that would create on-demand tokens.
110+
# https://github.com/LouisBrunner/checks-action/issues/18
111+
# details_url:
69112
- name: Checkout
70113
uses: actions/checkout@v3
71114
with:
@@ -102,3 +145,10 @@ jobs:
102145
run: echo "::add-matcher::.github/matchers/tap.json"
103146
- name: Test
104147
run: npm test --ignore-scripts -ws -iwr --if-present
148+
- name: Conclude Check
149+
uses: LouisBrunner/[email protected]
150+
if: always()
151+
with:
152+
token: ${{ secrets.GITHUB_TOKEN }}
153+
conclusion: ${{ job.status }}
154+
check_id: ${{ steps.check.outputs.check_id }}

.github/workflows/ci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
name: Lint
1919
if: github.repository_owner == 'npm'
2020
runs-on: ubuntu-latest
21+
defaults:
22+
run:
23+
shell: bash
2124
steps:
2225
- name: Checkout
2326
uses: actions/checkout@v3
@@ -41,7 +44,7 @@ jobs:
4144
run: npm run postlint --ignore-scripts
4245

4346
test:
44-
name: Test - ${{ matrix.platform.name }} - Node ${{ matrix.node-version }}
47+
name: Test All - ${{ matrix.platform.name }} - Node ${{ matrix.node-version }}
4548
if: github.repository_owner == 'npm'
4649
strategy:
4750
fail-fast: false

.github/workflows/post-dependabot.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ permissions:
99

1010
jobs:
1111
template-oss:
12-
name: "@npmcli/template-oss"
12+
name: template-oss
1313
if: github.repository_owner == 'npm' && github.actor == 'dependabot[bot]'
1414
runs-on: ubuntu-latest
15+
defaults:
16+
run:
17+
shell: bash
1518
steps:
1619
- name: Checkout
1720
uses: actions/checkout@v3

.github/workflows/pull-request.yml

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
name: Lint Commits
1616
if: github.repository_owner == 'npm'
1717
runs-on: ubuntu-latest
18+
defaults:
19+
run:
20+
shell: bash
1821
steps:
1922
- name: Checkout
2023
uses: actions/checkout@v3

.github/workflows/release.yml

+143-30
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,24 @@ on:
1111
permissions:
1212
contents: write
1313
pull-requests: write
14+
checks: write
1415

1516
jobs:
16-
release-please:
17-
name: Release Please
17+
release:
1818
outputs:
1919
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
2127
if: github.repository_owner == 'npm'
2228
runs-on: ubuntu-latest
29+
defaults:
30+
run:
31+
shell: bash
2332
steps:
2433
- name: Checkout
2534
uses: actions/checkout@v3
@@ -37,29 +46,72 @@ jobs:
3746
run: npm -v
3847
- name: Install Dependencies
3948
run: npm i --ignore-scripts --no-audit --no-fund
40-
- name: npx template-oss-release-please ${{ github.ref_name }}
49+
- name: Release Please
4150
id: release
4251
env:
4352
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 }
4565
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
51100
outputs:
52-
ref: ${{ steps.ref.outputs.branch }}
53101
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
54109
steps:
55-
- name: Output PR Head Branch
56-
id: ref
57-
run: echo "::set-output name=branch::${{ fromJSON(needs.release-please.outputs.pr).headBranchName }}"
58110
- name: Checkout
59111
uses: actions/checkout@v3
60112
with:
61113
fetch-depth: 0
62-
ref: ${{ steps.ref.outputs.branch }}
114+
ref: ${{ needs.release.outputs.branch }}
63115
- name: Setup Git User
64116
run: |
65117
git config --global user.email "[email protected]"
@@ -75,30 +127,89 @@ jobs:
75127
- name: Install Dependencies
76128
run: npm i --ignore-scripts --no-audit --no-fund
77129
- 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
80137
id: commit
81138
env:
82139
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83140
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 }}
87166

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
92171
uses: ./.github/workflows/ci-release.yml
93172
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 }}
96204

97205
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
101209
runs-on: ubuntu-latest
210+
defaults:
211+
run:
212+
shell: bash
102213
steps:
103214
- name: Checkout
104215
uses: actions/checkout@v3
@@ -117,5 +228,7 @@ jobs:
117228
- name: Install Dependencies
118229
run: npm i --ignore-scripts --no-audit --no-fund
119230
- name: Run Post Release Actions
231+
env:
232+
RELEASES: ${{ needs.release.outputs.releases }}
120233
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

Comments
 (0)