feat: build and publish by github action #3
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: | |
push: | |
tags: | |
- 'v*.*.*' | |
jobs: | |
publish: | |
name: Publish Package | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'npm' | |
- name: Extract tag version | |
id: extract_version | |
run: echo "TAG_VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV | |
- name: Insert version into package.json | |
run: | | |
node -e " | |
const fs = require('fs'); | |
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf-8')); | |
packageJson.version = process.env.TAG_VERSION; | |
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2)); | |
console.log('Updated version to', process.env.TAG_VERSION); | |
" | |
- name: Install dependencies | |
run: npm install | |
- name: Build the package | |
run: npm run build | |
- name: Configure npm | |
run: | | |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
npm whoami | |
- name: Publish to npm | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: npm publish --access public |