pkg: Publish to npm #22
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: 'Publish to npm' | |
on: | |
release: | |
types: [published] | |
jobs: | |
publish: | |
name: Publish | |
runs-on: ubuntu-latest | |
steps: | |
- name: 'π Checkout Code' | |
uses: actions/checkout@v4 | |
- name: 'β Check if package.json Version matches tag' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const fs = require('fs') | |
const packageJson = JSON.parse(fs.readFileSync('${{ github.workspace }}/package.json')) | |
const pjv = packageJson.version | |
const tv = "${{ github.ref_name }}".replace('v', '') | |
if (pjv !== tv) { | |
throw new Error(`The tagged release, ${tv}, doesn't match the package.json version, ${pjv}. Please fix the issue, delete the tag & release and try again.`) | |
} | |
- name: 'π’ Use Node.js' | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: 'https://registry.npmjs.org' | |
- name: 'β‘οΈ Install Packages' | |
run: yarn install | |
- name: 'ποΈ Build' | |
run: yarn build | |
- name: 'π’ Publish' | |
run: yarn npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH }} |