-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add release workflow to publish to NPM automatically
- Loading branch information
1 parent
9b11334
commit 143ceb9
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Publish | ||
on: | ||
release: | ||
types: [published] | ||
jobs: | ||
publish: | ||
name: Publish | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
# Set up .npmrc file to publish to npm | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
registry-url: https://registry.npmjs.org | ||
- run: npm ci | ||
# Get the 'version' field out of the package.json file | ||
- run: echo "version=$(cat package.json | jq '.version' --raw-output)" >> $GITHUB_OUTPUT | ||
id: package-json-version | ||
# Abort if the version in the package.json file (prefixed with 'v') doesn't match the tag name of the release | ||
- name: Check package.json version against tag name | ||
if: ${{ format('v{0}', steps.package-json-version.outputs.version) }} != ${{ github.event.release.tag_name }} | ||
uses: actions/github-script@v3 | ||
with: | ||
script: core.setFailed('Release tag does not match package.json version!') | ||
# Abort if this is a pre-release and the version in the package.json file doesn't contain a '-' to indicate that (e.g. v2.0.0-beta.1), or vice-versa | ||
- name: Check package.json version against pre-release | ||
if: ${{ contains(steps.package-json-version.outputs.version, '-') }} != ${{ github.event.release.prerelease }} | ||
uses: actions/github-script@v3 | ||
with: | ||
script: core.setFailed('Stability of release tag does not match package.json version!') | ||
# If this is a pre-release, publish it to NPM under the 'next' tag (default is 'latest') | ||
- run: npm publish ${{ github.event.release.prerelease && '--tag=next' || '' }} | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |