feat: add npm deployment workflow and update package files #2
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: Deploy to npm | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
publish-npm: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Set up Node.js environment | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
registry-url: 'https://registry.npmjs.org/' | |
# Install dependencies | |
- name: Install dependencies | |
run: npm install | |
# Get the short hash of the last commit | |
- name: Get short commit hash | |
id: get_hash | |
run: echo "HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
# Update the version in package.json | |
- name: Update version | |
run: | | |
VERSION="0.0.1-alpha.$HASH" | |
jq --arg ver "$VERSION" '.version = $ver' package.json > tmp.json && mv tmp.json package.json | |
# Build the package | |
- name: Build package | |
run: npm run build | |
# Run tests | |
- name: Run tests | |
run: npm test | |
# Publish to npm | |
- name: Publish to npm | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: npm publish |