diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 84fd7d17..01292d4a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -320,41 +320,25 @@ jobs: defaults: run: shell: bash + permissions: + deployments: write steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ fromJSON(needs.release.outputs.release).tagName }} - name: Setup Node uses: actions/setup-node@v3 with: node-version: 18.x - name: Install npm@latest - run: npm i --prefer-online --no-fund --no-audit -g npm@latest - - name: npm Version - run: npm -v - - name: View in Registry run: | - 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 + npm i --prefer-online --no-fund --no-audit -g npm@latest + npm config set '//registry.npmjs.org/:_authToken'=\${PUBLISH_TOKEN} + - name: Publish + env: + PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }} + run: npm publish post-release-integration: needs: [ release, release-integration ] diff --git a/bin/release-manager.js b/bin/release-manager.js index 5fdbc0ec..69686c6f 100755 --- a/bin/release-manager.js +++ b/bin/release-manager.js @@ -16,17 +16,7 @@ const args = process.argv.slice(2).reduce((acc, a) => { return acc }, {}) -/* eslint-disable max-len */ -const DEFAULT_RELEASE_PROCESS = ` -1. Checkout the release branch and test - - \`\`\`sh - gh pr checkout --force - npm ${args.lockfile ? 'ci' : 'update'} - npm test - gh pr checks --watch - \`\`\` - +const PUBLISH_STEPS = ` 1. Publish workspaces \`\`\`sh @@ -38,8 +28,22 @@ const DEFAULT_RELEASE_PROCESS = ` \`\`\`sh npm publish \`\`\` +` + +/* eslint-disable max-len */ +const DEFAULT_RELEASE_PROCESS = ` +1. Checkout the release branch and test + + \`\`\`sh + gh pr checkout --force + npm ${args.lockfile ? 'ci' : 'update'} + npm test + gh pr checks --watch + \`\`\` + +${!args.publish ? PUBLISH_STEPS : ''} -1. Merge release PR +1. Merge release PR ${args.publish ? `:rotating_light: Merging this will auto publish :rotating_light:` : ''} \`\`\`sh gh pr merge --rebase diff --git a/lib/content/_job-release-integration.yml b/lib/content/_job-release-integration.yml index 098d2236..e064d4e4 100644 --- a/lib/content/_job-release-integration.yml +++ b/lib/content/_job-release-integration.yml @@ -1,3 +1,28 @@ +{{#if publish}} +runs-on: ubuntu-latest +defaults: + run: + shell: bash +permissions: + deployments: write +steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: $\{{ fromJSON(needs.release.outputs.release).tagName }} + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 18.x + - name: Install npm@latest + run: | + npm i --prefer-online --no-fund --no-audit -g npm@latest + npm config set '//registry.npmjs.org/:_authToken'=\${PUBLISH_TOKEN} + - name: Publish + env: + PUBLISH_TOKEN: $\{{ secrets.PUBLISH_TOKEN }} + run: npm publish +{{else}} runs-on: ubuntu-latest defaults: run: @@ -30,3 +55,4 @@ steps: done exit $EXIT_CODE +{{/if}} diff --git a/lib/content/index.js b/lib/content/index.js index 903366ae..23f2c738 100644 --- a/lib/content/index.js +++ b/lib/content/index.js @@ -151,6 +151,7 @@ module.exports = { ciVersions: ['14.17.0', '14.x', '16.13.0', '16.x', '18.0.0', '18.x'], lockfile: false, codeowner: '@npm/cli-team', + publish: false, npm: 'npm', npx: 'npx', npmSpec: 'latest', diff --git a/lib/content/release.yml b/lib/content/release.yml index 9bb7a94b..39693f1c 100644 --- a/lib/content/release.yml +++ b/lib/content/release.yml @@ -85,7 +85,7 @@ jobs: RELEASE_COMMENT_ID: $\{{ needs.release.outputs.comment-id }} GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }} run: | - {{ rootNpmPath }} exec --offline -- template-oss-release-manager --lockfile={{ lockfile }} + {{ rootNpmPath }} exec --offline -- template-oss-release-manager --lockfile={{ lockfile }} --publish={{ publish }} {{ rootNpmPath }} run rp-pull-request --ignore-scripts {{~#if allFlags}} {{ allFlags }}{{else}} --if-present{{/if}} - name: Commit id: commit diff --git a/package.json b/package.json index 84439383..6e0a17be 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,8 @@ "test-ignore": "^(workspace/test-workspace)/" }, "templateOSS": { - "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten." + "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", + "publish": true }, "engines": { "node": "^14.17.0 || ^16.13.0 || >=18.0.0"