Skip to content

Add GitHub Actions workflows for npm publishing #2

Add GitHub Actions workflows for npm publishing

Add GitHub Actions workflows for npm publishing #2

name: NPM Publish Beta
on:
push:
branches:
- develop
pull_request:
branches:
- master
jobs:
publish-beta:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Generate beta version
id: beta-version
run: |
# Get the current version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")
# For PR: use PR number in version
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BETA_VERSION="$CURRENT_VERSION-beta.pr.${{ github.event.pull_request.number }}"
else
# For develop: use commit hash
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
BETA_VERSION="$CURRENT_VERSION-beta.$SHORT_SHA"
fi
# Set output for use in next step
echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT
# Update package.json with new version
npm version $BETA_VERSION --no-git-tag-version
- name: Publish beta to npm
run: npm publish --tag beta --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}