From 8dac23ab285582afe7cdd2b463a5f1e3b1f3cb00 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Tue, 24 Jan 2023 15:16:11 -0700 Subject: [PATCH] fix: capture exit code from npm view --- .github/workflows/release.yml | 42 ++++-- lib/content/CODEOWNERS | 2 +- lib/content/_job-release-integration.yml | 30 ++++- lib/content/index.js | 1 + lib/content/release.yml | 9 +- .../test/apply/source-snapshots.js.test.cjs | 126 +++++++++++++----- 6 files changed, 163 insertions(+), 47 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5a68bd0f..d3092a03 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: @@ -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 ] @@ -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)) diff --git a/lib/content/CODEOWNERS b/lib/content/CODEOWNERS index 3bee8753..9ed0a549 100644 --- a/lib/content/CODEOWNERS +++ b/lib/content/CODEOWNERS @@ -1 +1 @@ -* @npm/cli-team +* {{ codeowner }} diff --git a/lib/content/_job-release-integration.yml b/lib/content/_job-release-integration.yml index f9777298..098d2236 100644 --- a/lib/content/_job-release-integration.yml +++ b/lib/content/_job-release-integration.yml @@ -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 diff --git a/lib/content/index.js b/lib/content/index.js index f63e5d12..903366ae 100644 --- a/lib/content/index.js +++ b/lib/content/index.js @@ -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', diff --git a/lib/content/release.yml b/lib/content/release.yml index af8e54fe..c0c73323 100644 --- a/lib/content/release.yml +++ b/lib/content/release.yml @@ -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)) diff --git a/tap-snapshots/test/apply/source-snapshots.js.test.cjs b/tap-snapshots/test/apply/source-snapshots.js.test.cjs index fbc6431e..eef05cd2 100644 --- a/tap-snapshots/test/apply/source-snapshots.js.test.cjs +++ b/tap-snapshots/test/apply/source-snapshots.js.test.cjs @@ -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: @@ -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 ] @@ -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)) @@ -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: @@ -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 ] @@ -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)) @@ -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: @@ -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 ] @@ -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))