v0.1.1 #6
Workflow file for this run
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
name: NPM publish CD workflow | |
# Allow the workflow to write back to the repo | |
permissions: | |
contents: write | |
on: | |
release: | |
# This specifies that the build will be triggered when we publish a release | |
types: [published] | |
jobs: | |
build: | |
# Run on latest version of ubuntu | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# "ref" specifies the branch to check out. | |
# "github.event.release.target_commitish" is a global variable and specifies the branch the release targeted | |
ref: ${{ github.event.release.target_commitish }} | |
# install Node.js | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 21 | |
cache: 'npm' | |
registry-url: 'https://registry.npmjs.org/' | |
# clean install of your projects' deps. We use "npm ci" to avoid package lock changes | |
- run: npm ci | |
# set up git since we will later push to the repo | |
- run: git config --global user.name "GitHub CD bot" | |
- run: git config --global user.email "[email protected]" | |
# upgrade npm version in package.json to the tag used in the release. | |
- run: npm version ${{ github.event.release.tag_name }} | |
# build the project | |
- run: npm run build | |
# run tests just in case | |
# - run: npm test | |
# publish to NPM -> there is one caveat, continue reading for the fix | |
- run: npm publish --access=public | |
env: | |
# Use a token to publish to NPM. See below for how to set it up | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
# Add the changed files back to the repo | |
- run: git status | |
- run: git add . | |
- run: git commit -m "Publish ${{ github.event.release.tag_name }}" | |
# push the version changes to GitHub | |
- run: git push | |
env: | |
# The secret is passed automatically. Nothing to configure. | |
github-token: ${{ secrets.GITHUB_TOKEN }} |