Skip to content

npm publish

npm publish #12

name: Publish to NPM
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout code
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Setup Node.js (v20) and configure pnpm cache
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
# Step 3: Install pnpm
- name: Install pnpm
run: |
npm install -g pnpm
pnpm --version # Verify that pnpm is installed and accessible
# Step 4: Install dependencies using pnpm
- name: Install dependencies
run: pnpm install
# Step 5: Run tests (replace with your actual test command)
- name: Run tests
run: pnpm run test
# Step 6: Build the library (replace with your actual build command)
- name: Build the library
run: pnpm run build
- name: Check NPM_TOKEN
run: echo "NPM_TOKEN is set"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# Step 7: Publish to NPM (on successful build)
- uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
# Step 8: Create GitHub Release (optional)
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: |
dist/**
# Step 9: Post-publish cleanup (optional)
- name: Post-publish cleanup
run: rm -rf dist