Skip to content

Commit 8dac23a

Browse files
committed
fix: capture exit code from npm view
1 parent efce5a9 commit 8dac23a

File tree

6 files changed

+163
-47
lines changed

6 files changed

+163
-47
lines changed

.github/workflows/release.yml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,6 @@ jobs:
314314
run:
315315
shell: bash
316316
steps:
317-
- name: Checkout
318-
uses: actions/checkout@v3
319-
- name: Setup Git User
320-
run: |
321-
git config --global user.email "npm-cli+bot@github.com"
322-
git config --global user.name "npm CLI robot"
323317
- name: Setup Node
324318
uses: actions/setup-node@v3
325319
with:
@@ -330,9 +324,30 @@ jobs:
330324
run: npm -v
331325
- name: View in Registry
332326
run: |
333-
name=$(cat package.json | jq -r .name)
334-
version="${{ fromJSON(needs.release.output.release).version }}"
335-
npm view ${name}@${version}
327+
EXIT_CODE=0
328+
329+
function is_published {
330+
if npm view "$@" --loglevel=error > /dev/null; then
331+
echo 0
332+
else
333+
echo 1
334+
fi
335+
}
336+
337+
for release in $(echo '${{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do
338+
name=$(echo "$release" | base64 --decode | jq -r .pkgName)
339+
version=$(echo "$release" | base64 --decode | jq -r .version)
340+
spec="$name@$version"
341+
status=$(is_published "$spec")
342+
if [[ "$status" -eq 1 ]]; then
343+
echo "$spec ERROR"
344+
EXIT_CODE=$status
345+
else
346+
echo "$spec OK"
347+
fi
348+
done
349+
350+
exit $EXIT_CODE
336351
337352
post-release-integration:
338353
needs: [ release, release-integration ]
@@ -370,11 +385,18 @@ jobs:
370385
371386
if (updateComment) {
372387
console.log('Found comment to update:', JSON.stringify(updateComment, null, 2))
388+
let body = updateComment.body.replace(/Workflow run: :[a-z_]+:/, `Workflow run: :${RESULT}:`)
389+
if (RESULT === 'x') {
390+
body += `\n\n:rotating_light:`
391+
body += ` @npm/cli-team: The post-release workflow failed for this release.`
392+
body += ` Manual steps may need to be taken after examining the workflow output`
393+
body += ` from the above workflow run. :rotating_light:`
394+
}
373395
await github.rest.issues.updateComment({
374396
owner,
375397
repo,
398+
body,
376399
comment_id: updateComment.id,
377-
body: updateComment.body.replace(/Workflow run: :[a-z_]+:/, `Workflow run: :${RESULT}:`),
378400
})
379401
} else {
380402
console.log('No matching comments found:', JSON.stringify(comments, null, 2))

lib/content/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @npm/cli-team
1+
* {{ codeowner }}

lib/content/_job-release-integration.yml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,30 @@ defaults:
33
run:
44
shell: bash
55
steps:
6-
{{> stepGit }}
7-
{{> stepNode }}
6+
{{> stepNode lockfile=false }}
87
- name: View in Registry
98
run: |
10-
name=$(cat package.json | jq -r .name)
11-
version="$\{{ fromJSON(needs.release.output.release).version }}"
12-
npm view ${name}@${version}
9+
EXIT_CODE=0
10+
11+
function is_published {
12+
if npm view "$@" --loglevel=error > /dev/null; then
13+
echo 0
14+
else
15+
echo 1
16+
fi
17+
}
18+
19+
for release in $(echo '$\{{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do
20+
name=$(echo "$release" | base64 --decode | jq -r .pkgName)
21+
version=$(echo "$release" | base64 --decode | jq -r .version)
22+
spec="$name@$version"
23+
status=$(is_published "$spec")
24+
if [[ "$status" -eq 1 ]]; then
25+
echo "$spec ERROR"
26+
EXIT_CODE=$status
27+
else
28+
echo "$spec OK"
29+
fi
30+
done
31+
32+
exit $EXIT_CODE

lib/content/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ module.exports = {
150150
ignorePaths: [],
151151
ciVersions: ['14.17.0', '14.x', '16.13.0', '16.x', '18.0.0', '18.x'],
152152
lockfile: false,
153+
codeowner: '@npm/cli-team',
153154
npm: 'npm',
154155
npx: 'npx',
155156
npmSpec: 'latest',

lib/content/release.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,18 @@ jobs:
189189
190190
if (updateComment) {
191191
console.log('Found comment to update:', JSON.stringify(updateComment, null, 2))
192+
let body = updateComment.body.replace(/Workflow run: :[a-z_]+:/, `Workflow run: :${RESULT}:`)
193+
if (RESULT === 'x') {
194+
body += `\n\n:rotating_light:`
195+
body += ` {{ codeowner }}: The post-release workflow failed for this release.`
196+
body += ` Manual steps may need to be taken after examining the workflow output`
197+
body += ` from the above workflow run. :rotating_light:`
198+
}
192199
await github.rest.issues.updateComment({
193200
owner,
194201
repo,
202+
body,
195203
comment_id: updateComment.id,
196-
body: updateComment.body.replace(/Workflow run: :[a-z_]+:/, `Workflow run: :${RESULT}:`),
197204
})
198205
} else {
199206
console.log('No matching comments found:', JSON.stringify(comments, null, 2))

tap-snapshots/test/apply/source-snapshots.js.test.cjs

Lines changed: 96 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,12 +1068,6 @@ jobs:
10681068
run:
10691069
shell: bash
10701070
steps:
1071-
- name: Checkout
1072-
uses: actions/checkout@v3
1073-
- name: Setup Git User
1074-
run: |
1075-
git config --global user.email "npm-cli+bot@github.com"
1076-
git config --global user.name "npm CLI robot"
10771071
- name: Setup Node
10781072
uses: actions/setup-node@v3
10791073
with:
@@ -1084,9 +1078,30 @@ jobs:
10841078
run: npm -v
10851079
- name: View in Registry
10861080
run: |
1087-
name=$(cat package.json | jq -r .name)
1088-
version="\${{ fromJSON(needs.release.output.release).version }}"
1089-
npm view \${name}@\${version}
1081+
EXIT_CODE=0
1082+
1083+
function is_published {
1084+
if npm view "$@" --loglevel=error > /dev/null; then
1085+
echo 0
1086+
else
1087+
echo 1
1088+
fi
1089+
}
1090+
1091+
for release in $(echo '\${{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do
1092+
name=$(echo "$release" | base64 --decode | jq -r .pkgName)
1093+
version=$(echo "$release" | base64 --decode | jq -r .version)
1094+
spec="$name@$version"
1095+
status=$(is_published "$spec")
1096+
if [[ "$status" -eq 1 ]]; then
1097+
echo "$spec ERROR"
1098+
EXIT_CODE=$status
1099+
else
1100+
echo "$spec OK"
1101+
fi
1102+
done
1103+
1104+
exit $EXIT_CODE
10901105
10911106
post-release-integration:
10921107
needs: [ release, release-integration ]
@@ -1124,11 +1139,18 @@ jobs:
11241139
11251140
if (updateComment) {
11261141
console.log('Found comment to update:', JSON.stringify(updateComment, null, 2))
1142+
let body = updateComment.body.replace(/Workflow run: :[a-z_]+:/, \`Workflow run: :\${RESULT}:\`)
1143+
if (RESULT === 'x') {
1144+
body += \`/n/n:rotating_light:\`
1145+
body += \` @npm/cli-team: The post-release workflow failed for this release.\`
1146+
body += \` Manual steps may need to be taken after examining the workflow output\`
1147+
body += \` from the above workflow run. :rotating_light:\`
1148+
}
11271149
await github.rest.issues.updateComment({
11281150
owner,
11291151
repo,
1152+
body,
11301153
comment_id: updateComment.id,
1131-
body: updateComment.body.replace(/Workflow run: :[a-z_]+:/, \`Workflow run: :\${RESULT}:\`),
11321154
})
11331155
} else {
11341156
console.log('No matching comments found:', JSON.stringify(comments, null, 2))
@@ -2620,12 +2642,6 @@ jobs:
26202642
run:
26212643
shell: bash
26222644
steps:
2623-
- name: Checkout
2624-
uses: actions/checkout@v3
2625-
- name: Setup Git User
2626-
run: |
2627-
git config --global user.email "npm-cli+bot@github.com"
2628-
git config --global user.name "npm CLI robot"
26292645
- name: Setup Node
26302646
uses: actions/setup-node@v3
26312647
with:
@@ -2636,9 +2652,30 @@ jobs:
26362652
run: npm -v
26372653
- name: View in Registry
26382654
run: |
2639-
name=$(cat package.json | jq -r .name)
2640-
version="\${{ fromJSON(needs.release.output.release).version }}"
2641-
npm view \${name}@\${version}
2655+
EXIT_CODE=0
2656+
2657+
function is_published {
2658+
if npm view "$@" --loglevel=error > /dev/null; then
2659+
echo 0
2660+
else
2661+
echo 1
2662+
fi
2663+
}
2664+
2665+
for release in $(echo '\${{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do
2666+
name=$(echo "$release" | base64 --decode | jq -r .pkgName)
2667+
version=$(echo "$release" | base64 --decode | jq -r .version)
2668+
spec="$name@$version"
2669+
status=$(is_published "$spec")
2670+
if [[ "$status" -eq 1 ]]; then
2671+
echo "$spec ERROR"
2672+
EXIT_CODE=$status
2673+
else
2674+
echo "$spec OK"
2675+
fi
2676+
done
2677+
2678+
exit $EXIT_CODE
26422679
26432680
post-release-integration:
26442681
needs: [ release, release-integration ]
@@ -2676,11 +2713,18 @@ jobs:
26762713
26772714
if (updateComment) {
26782715
console.log('Found comment to update:', JSON.stringify(updateComment, null, 2))
2716+
let body = updateComment.body.replace(/Workflow run: :[a-z_]+:/, \`Workflow run: :\${RESULT}:\`)
2717+
if (RESULT === 'x') {
2718+
body += \`/n/n:rotating_light:\`
2719+
body += \` @npm/cli-team: The post-release workflow failed for this release.\`
2720+
body += \` Manual steps may need to be taken after examining the workflow output\`
2721+
body += \` from the above workflow run. :rotating_light:\`
2722+
}
26792723
await github.rest.issues.updateComment({
26802724
owner,
26812725
repo,
2726+
body,
26822727
comment_id: updateComment.id,
2683-
body: updateComment.body.replace(/Workflow run: :[a-z_]+:/, \`Workflow run: :\${RESULT}:\`),
26842728
})
26852729
} else {
26862730
console.log('No matching comments found:', JSON.stringify(comments, null, 2))
@@ -4015,12 +4059,6 @@ jobs:
40154059
run:
40164060
shell: bash
40174061
steps:
4018-
- name: Checkout
4019-
uses: actions/checkout@v3
4020-
- name: Setup Git User
4021-
run: |
4022-
git config --global user.email "npm-cli+bot@github.com"
4023-
git config --global user.name "npm CLI robot"
40244062
- name: Setup Node
40254063
uses: actions/setup-node@v3
40264064
with:
@@ -4031,9 +4069,30 @@ jobs:
40314069
run: npm -v
40324070
- name: View in Registry
40334071
run: |
4034-
name=$(cat package.json | jq -r .name)
4035-
version="\${{ fromJSON(needs.release.output.release).version }}"
4036-
npm view \${name}@\${version}
4072+
EXIT_CODE=0
4073+
4074+
function is_published {
4075+
if npm view "$@" --loglevel=error > /dev/null; then
4076+
echo 0
4077+
else
4078+
echo 1
4079+
fi
4080+
}
4081+
4082+
for release in $(echo '\${{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do
4083+
name=$(echo "$release" | base64 --decode | jq -r .pkgName)
4084+
version=$(echo "$release" | base64 --decode | jq -r .version)
4085+
spec="$name@$version"
4086+
status=$(is_published "$spec")
4087+
if [[ "$status" -eq 1 ]]; then
4088+
echo "$spec ERROR"
4089+
EXIT_CODE=$status
4090+
else
4091+
echo "$spec OK"
4092+
fi
4093+
done
4094+
4095+
exit $EXIT_CODE
40374096
40384097
post-release-integration:
40394098
needs: [ release, release-integration ]
@@ -4071,11 +4130,18 @@ jobs:
40714130
40724131
if (updateComment) {
40734132
console.log('Found comment to update:', JSON.stringify(updateComment, null, 2))
4133+
let body = updateComment.body.replace(/Workflow run: :[a-z_]+:/, \`Workflow run: :\${RESULT}:\`)
4134+
if (RESULT === 'x') {
4135+
body += \`/n/n:rotating_light:\`
4136+
body += \` @npm/cli-team: The post-release workflow failed for this release.\`
4137+
body += \` Manual steps may need to be taken after examining the workflow output\`
4138+
body += \` from the above workflow run. :rotating_light:\`
4139+
}
40744140
await github.rest.issues.updateComment({
40754141
owner,
40764142
repo,
4143+
body,
40774144
comment_id: updateComment.id,
4078-
body: updateComment.body.replace(/Workflow run: :[a-z_]+:/, \`Workflow run: :\${RESULT}:\`),
40794145
})
40804146
} else {
40814147
console.log('No matching comments found:', JSON.stringify(comments, null, 2))

0 commit comments

Comments
 (0)