Skip to content

Commit

Permalink
feat: add autopublish (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Mar 23, 2023
1 parent f92b1ca commit 7102893
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 46 deletions.
42 changes: 13 additions & 29 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ jobs:
RELEASE_COMMENT_ID: ${{ needs.release.outputs.comment-id }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm exec --offline -- template-oss-release-manager --lockfile=false
npm exec --offline -- template-oss-release-manager --lockfile=false --publish=true
npm run rp-pull-request --ignore-scripts -ws -iwr --if-present
- name: Commit
id: commit
Expand Down Expand Up @@ -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 ]
Expand Down
28 changes: 16 additions & 12 deletions bin/release-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PR-NUMBER> --force
npm ${args.lockfile ? 'ci' : 'update'}
npm test
gh pr checks --watch
\`\`\`
const PUBLISH_STEPS = `
1. Publish workspaces
\`\`\`sh
Expand All @@ -38,8 +28,22 @@ const DEFAULT_RELEASE_PROCESS = `
\`\`\`sh
npm publish <PUBLISH-FLAGS>
\`\`\`
`

/* eslint-disable max-len */
const DEFAULT_RELEASE_PROCESS = `
1. Checkout the release branch and test
\`\`\`sh
gh pr checkout <PR-NUMBER> --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
Expand Down
26 changes: 26 additions & 0 deletions lib/content/_job-release-integration.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -30,3 +55,4 @@ steps:
done
exit $EXIT_CODE
{{/if}}
1 change: 1 addition & 0 deletions lib/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion lib/content/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions tap-snapshots/test/apply/source-snapshots.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ jobs:
RELEASE_COMMENT_ID: \${{ needs.release.outputs.comment-id }}
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
run: |
npm exec --offline -- template-oss-release-manager --lockfile=false
npm exec --offline -- template-oss-release-manager --lockfile=false --publish=false
npm run rp-pull-request --ignore-scripts --if-present
- name: Commit
id: commit
Expand Down Expand Up @@ -2510,7 +2510,7 @@ jobs:
RELEASE_COMMENT_ID: \${{ needs.release.outputs.comment-id }}
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
run: |
npm exec --offline -- template-oss-release-manager --lockfile=false
npm exec --offline -- template-oss-release-manager --lockfile=false --publish=false
npm run rp-pull-request --ignore-scripts -ws -iwr --if-present
- name: Commit
id: commit
Expand Down Expand Up @@ -3938,7 +3938,7 @@ jobs:
RELEASE_COMMENT_ID: \${{ needs.release.outputs.comment-id }}
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
run: |
npm exec --offline -- template-oss-release-manager --lockfile=false
npm exec --offline -- template-oss-release-manager --lockfile=false --publish=false
npm run rp-pull-request --ignore-scripts -ws -iwr --if-present
- name: Commit
id: commit
Expand Down

0 comments on commit 7102893

Please sign in to comment.