Skip to content

Commit 7102893

Browse files
authoredMar 23, 2023
feat: add autopublish (#296)
1 parent f92b1ca commit 7102893

File tree

7 files changed

+62
-46
lines changed

7 files changed

+62
-46
lines changed
 

‎.github/workflows/release.yml

+13-29
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ jobs:
171171
RELEASE_COMMENT_ID: ${{ needs.release.outputs.comment-id }}
172172
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
173173
run: |
174-
npm exec --offline -- template-oss-release-manager --lockfile=false
174+
npm exec --offline -- template-oss-release-manager --lockfile=false --publish=true
175175
npm run rp-pull-request --ignore-scripts -ws -iwr --if-present
176176
- name: Commit
177177
id: commit
@@ -320,41 +320,25 @@ jobs:
320320
defaults:
321321
run:
322322
shell: bash
323+
permissions:
324+
deployments: write
323325
steps:
326+
- name: Checkout
327+
uses: actions/checkout@v3
328+
with:
329+
ref: ${{ fromJSON(needs.release.outputs.release).tagName }}
324330
- name: Setup Node
325331
uses: actions/setup-node@v3
326332
with:
327333
node-version: 18.x
328334
- name: Install npm@latest
329-
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
330-
- name: npm Version
331-
run: npm -v
332-
- name: View in Registry
333335
run: |
334-
EXIT_CODE=0
335-
336-
function is_published {
337-
if npm view "$@" --loglevel=error > /dev/null; then
338-
echo 0
339-
else
340-
echo 1
341-
fi
342-
}
343-
344-
for release in $(echo '${{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do
345-
name=$(echo "$release" | base64 --decode | jq -r .pkgName)
346-
version=$(echo "$release" | base64 --decode | jq -r .version)
347-
spec="$name@$version"
348-
status=$(is_published "$spec")
349-
if [[ "$status" -eq 1 ]]; then
350-
echo "$spec ERROR"
351-
EXIT_CODE=$status
352-
else
353-
echo "$spec OK"
354-
fi
355-
done
356-
357-
exit $EXIT_CODE
336+
npm i --prefer-online --no-fund --no-audit -g npm@latest
337+
npm config set '//registry.npmjs.org/:_authToken'=\${PUBLISH_TOKEN}
338+
- name: Publish
339+
env:
340+
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
341+
run: npm publish
358342

359343
post-release-integration:
360344
needs: [ release, release-integration ]

‎bin/release-manager.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,7 @@ const args = process.argv.slice(2).reduce((acc, a) => {
1616
return acc
1717
}, {})
1818

19-
/* eslint-disable max-len */
20-
const DEFAULT_RELEASE_PROCESS = `
21-
1. Checkout the release branch and test
22-
23-
\`\`\`sh
24-
gh pr checkout <PR-NUMBER> --force
25-
npm ${args.lockfile ? 'ci' : 'update'}
26-
npm test
27-
gh pr checks --watch
28-
\`\`\`
29-
19+
const PUBLISH_STEPS = `
3020
1. Publish workspaces
3121
3222
\`\`\`sh
@@ -38,8 +28,22 @@ const DEFAULT_RELEASE_PROCESS = `
3828
\`\`\`sh
3929
npm publish <PUBLISH-FLAGS>
4030
\`\`\`
31+
`
32+
33+
/* eslint-disable max-len */
34+
const DEFAULT_RELEASE_PROCESS = `
35+
1. Checkout the release branch and test
36+
37+
\`\`\`sh
38+
gh pr checkout <PR-NUMBER> --force
39+
npm ${args.lockfile ? 'ci' : 'update'}
40+
npm test
41+
gh pr checks --watch
42+
\`\`\`
43+
44+
${!args.publish ? PUBLISH_STEPS : ''}
4145
42-
1. Merge release PR
46+
1. Merge release PR ${args.publish ? `:rotating_light: Merging this will auto publish :rotating_light:` : ''}
4347
4448
\`\`\`sh
4549
gh pr merge --rebase

‎lib/content/_job-release-integration.yml

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
{{#if publish}}
2+
runs-on: ubuntu-latest
3+
defaults:
4+
run:
5+
shell: bash
6+
permissions:
7+
deployments: write
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v3
11+
with:
12+
ref: $\{{ fromJSON(needs.release.outputs.release).tagName }}
13+
- name: Setup Node
14+
uses: actions/setup-node@v3
15+
with:
16+
node-version: 18.x
17+
- name: Install npm@latest
18+
run: |
19+
npm i --prefer-online --no-fund --no-audit -g npm@latest
20+
npm config set '//registry.npmjs.org/:_authToken'=\${PUBLISH_TOKEN}
21+
- name: Publish
22+
env:
23+
PUBLISH_TOKEN: $\{{ secrets.PUBLISH_TOKEN }}
24+
run: npm publish
25+
{{else}}
126
runs-on: ubuntu-latest
227
defaults:
328
run:
@@ -30,3 +55,4 @@ steps:
3055
done
3156
3257
exit $EXIT_CODE
58+
{{/if}}

‎lib/content/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ module.exports = {
151151
ciVersions: ['14.17.0', '14.x', '16.13.0', '16.x', '18.0.0', '18.x'],
152152
lockfile: false,
153153
codeowner: '@npm/cli-team',
154+
publish: false,
154155
npm: 'npm',
155156
npx: 'npx',
156157
npmSpec: 'latest',

‎lib/content/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
RELEASE_COMMENT_ID: $\{{ needs.release.outputs.comment-id }}
8686
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
8787
run: |
88-
{{ rootNpmPath }} exec --offline -- template-oss-release-manager --lockfile={{ lockfile }}
88+
{{ rootNpmPath }} exec --offline -- template-oss-release-manager --lockfile={{ lockfile }} --publish={{ publish }}
8989
{{ rootNpmPath }} run rp-pull-request --ignore-scripts {{~#if allFlags}} {{ allFlags }}{{else}} --if-present{{/if}}
9090
- name: Commit
9191
id: commit

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"test-ignore": "^(workspace/test-workspace)/"
7777
},
7878
"templateOSS": {
79-
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten."
79+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
80+
"publish": true
8081
},
8182
"engines": {
8283
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ jobs:
925925
RELEASE_COMMENT_ID: \${{ needs.release.outputs.comment-id }}
926926
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
927927
run: |
928-
npm exec --offline -- template-oss-release-manager --lockfile=false
928+
npm exec --offline -- template-oss-release-manager --lockfile=false --publish=false
929929
npm run rp-pull-request --ignore-scripts --if-present
930930
- name: Commit
931931
id: commit
@@ -2510,7 +2510,7 @@ jobs:
25102510
RELEASE_COMMENT_ID: \${{ needs.release.outputs.comment-id }}
25112511
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
25122512
run: |
2513-
npm exec --offline -- template-oss-release-manager --lockfile=false
2513+
npm exec --offline -- template-oss-release-manager --lockfile=false --publish=false
25142514
npm run rp-pull-request --ignore-scripts -ws -iwr --if-present
25152515
- name: Commit
25162516
id: commit
@@ -3938,7 +3938,7 @@ jobs:
39383938
RELEASE_COMMENT_ID: \${{ needs.release.outputs.comment-id }}
39393939
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
39403940
run: |
3941-
npm exec --offline -- template-oss-release-manager --lockfile=false
3941+
npm exec --offline -- template-oss-release-manager --lockfile=false --publish=false
39423942
npm run rp-pull-request --ignore-scripts -ws -iwr --if-present
39433943
- name: Commit
39443944
id: commit

0 commit comments

Comments
 (0)
Please sign in to comment.