Skip to content

Commit

Permalink
fix: capture exit code from npm view
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Jan 24, 2023
1 parent efce5a9 commit 8dac23a
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 47 deletions.
42 changes: 32 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,6 @@ jobs:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v3
with:
Expand All @@ -330,9 +324,30 @@ jobs:
run: npm -v
- name: View in Registry
run: |
name=$(cat package.json | jq -r .name)
version="${{ fromJSON(needs.release.output.release).version }}"
npm view ${name}@${version}
EXIT_CODE=0
function is_published {
if npm view "$@" --loglevel=error > /dev/null; then
echo 0
else
echo 1
fi
}
for release in $(echo '${{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do
name=$(echo "$release" | base64 --decode | jq -r .pkgName)
version=$(echo "$release" | base64 --decode | jq -r .version)
spec="$name@$version"
status=$(is_published "$spec")
if [[ "$status" -eq 1 ]]; then
echo "$spec ERROR"
EXIT_CODE=$status
else
echo "$spec OK"
fi
done
exit $EXIT_CODE
post-release-integration:
needs: [ release, release-integration ]
Expand Down Expand Up @@ -370,11 +385,18 @@ jobs:
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}:`)
if (RESULT === 'x') {
body += `\n\n:rotating_light:`
body += ` @npm/cli-team: 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,
body: updateComment.body.replace(/Workflow run: :[a-z_]+:/, `Workflow run: :${RESULT}:`),
})
} else {
console.log('No matching comments found:', JSON.stringify(comments, null, 2))
Expand Down
2 changes: 1 addition & 1 deletion lib/content/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @npm/cli-team
* {{ codeowner }}
30 changes: 25 additions & 5 deletions lib/content/_job-release-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,30 @@ defaults:
run:
shell: bash
steps:
{{> stepGit }}
{{> stepNode }}
{{> stepNode lockfile=false }}
- name: View in Registry
run: |
name=$(cat package.json | jq -r .name)
version="$\{{ fromJSON(needs.release.output.release).version }}"
npm view ${name}@${version}
EXIT_CODE=0
function is_published {
if npm view "$@" --loglevel=error > /dev/null; then
echo 0
else
echo 1
fi
}
for release in $(echo '$\{{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do
name=$(echo "$release" | base64 --decode | jq -r .pkgName)
version=$(echo "$release" | base64 --decode | jq -r .version)
spec="$name@$version"
status=$(is_published "$spec")
if [[ "$status" -eq 1 ]]; then
echo "$spec ERROR"
EXIT_CODE=$status
else
echo "$spec OK"
fi
done
exit $EXIT_CODE
1 change: 1 addition & 0 deletions lib/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ module.exports = {
ignorePaths: [],
ciVersions: ['14.17.0', '14.x', '16.13.0', '16.x', '18.0.0', '18.x'],
lockfile: false,
codeowner: '@npm/cli-team',
npm: 'npm',
npx: 'npx',
npmSpec: 'latest',
Expand Down
9 changes: 8 additions & 1 deletion lib/content/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,18 @@ jobs:
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}:`)
if (RESULT === 'x') {
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,
body: updateComment.body.replace(/Workflow run: :[a-z_]+:/, `Workflow run: :${RESULT}:`),
})
} else {
console.log('No matching comments found:', JSON.stringify(comments, null, 2))
Expand Down
126 changes: 96 additions & 30 deletions tap-snapshots/test/apply/source-snapshots.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,12 +1068,6 @@ jobs:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v3
with:
Expand All @@ -1084,9 +1078,30 @@ jobs:
run: npm -v
- name: View in Registry
run: |
name=$(cat package.json | jq -r .name)
version="\${{ fromJSON(needs.release.output.release).version }}"
npm view \${name}@\${version}
EXIT_CODE=0
function is_published {
if npm view "$@" --loglevel=error > /dev/null; then
echo 0
else
echo 1
fi
}
for release in $(echo '\${{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do
name=$(echo "$release" | base64 --decode | jq -r .pkgName)
version=$(echo "$release" | base64 --decode | jq -r .version)
spec="$name@$version"
status=$(is_published "$spec")
if [[ "$status" -eq 1 ]]; then
echo "$spec ERROR"
EXIT_CODE=$status
else
echo "$spec OK"
fi
done
exit $EXIT_CODE
post-release-integration:
needs: [ release, release-integration ]
Expand Down Expand Up @@ -1124,11 +1139,18 @@ jobs:
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}:\`)
if (RESULT === 'x') {
body += \`/n/n:rotating_light:\`
body += \` @npm/cli-team: 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,
body: updateComment.body.replace(/Workflow run: :[a-z_]+:/, \`Workflow run: :\${RESULT}:\`),
})
} else {
console.log('No matching comments found:', JSON.stringify(comments, null, 2))
Expand Down Expand Up @@ -2620,12 +2642,6 @@ jobs:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v3
with:
Expand All @@ -2636,9 +2652,30 @@ jobs:
run: npm -v
- name: View in Registry
run: |
name=$(cat package.json | jq -r .name)
version="\${{ fromJSON(needs.release.output.release).version }}"
npm view \${name}@\${version}
EXIT_CODE=0
function is_published {
if npm view "$@" --loglevel=error > /dev/null; then
echo 0
else
echo 1
fi
}
for release in $(echo '\${{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do
name=$(echo "$release" | base64 --decode | jq -r .pkgName)
version=$(echo "$release" | base64 --decode | jq -r .version)
spec="$name@$version"
status=$(is_published "$spec")
if [[ "$status" -eq 1 ]]; then
echo "$spec ERROR"
EXIT_CODE=$status
else
echo "$spec OK"
fi
done
exit $EXIT_CODE
post-release-integration:
needs: [ release, release-integration ]
Expand Down Expand Up @@ -2676,11 +2713,18 @@ jobs:
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}:\`)
if (RESULT === 'x') {
body += \`/n/n:rotating_light:\`
body += \` @npm/cli-team: 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,
body: updateComment.body.replace(/Workflow run: :[a-z_]+:/, \`Workflow run: :\${RESULT}:\`),
})
} else {
console.log('No matching comments found:', JSON.stringify(comments, null, 2))
Expand Down Expand Up @@ -4015,12 +4059,6 @@ jobs:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v3
with:
Expand All @@ -4031,9 +4069,30 @@ jobs:
run: npm -v
- name: View in Registry
run: |
name=$(cat package.json | jq -r .name)
version="\${{ fromJSON(needs.release.output.release).version }}"
npm view \${name}@\${version}
EXIT_CODE=0
function is_published {
if npm view "$@" --loglevel=error > /dev/null; then
echo 0
else
echo 1
fi
}
for release in $(echo '\${{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do
name=$(echo "$release" | base64 --decode | jq -r .pkgName)
version=$(echo "$release" | base64 --decode | jq -r .version)
spec="$name@$version"
status=$(is_published "$spec")
if [[ "$status" -eq 1 ]]; then
echo "$spec ERROR"
EXIT_CODE=$status
else
echo "$spec OK"
fi
done
exit $EXIT_CODE
post-release-integration:
needs: [ release, release-integration ]
Expand Down Expand Up @@ -4071,11 +4130,18 @@ jobs:
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}:\`)
if (RESULT === 'x') {
body += \`/n/n:rotating_light:\`
body += \` @npm/cli-team: 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,
body: updateComment.body.replace(/Workflow run: :[a-z_]+:/, \`Workflow run: :\${RESULT}:\`),
})
} else {
console.log('No matching comments found:', JSON.stringify(comments, null, 2))
Expand Down

0 comments on commit 8dac23a

Please sign in to comment.