Skip to content

feat: add npm deployment workflow and update package files #2

feat: add npm deployment workflow and update package files

feat: add npm deployment workflow and update package files #2

Workflow file for this run

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