Skip to content

Publish Package

Publish Package #47

Workflow file for this run

name: Publish Package
on:
workflow_run:
workflows: ['CI']
types:
- completed
branches:
- main
jobs:
publish:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build
run: npm run build
- name: Get latest beta version
id: get-version
run: |
# Get package name from package.json
PACKAGE_NAME=$(node -p "require('./package.json').name")
echo "Package name: $PACKAGE_NAME"
# Get all versions and filter for latest beta
LATEST_VERSION=$(npm view "${PACKAGE_NAME}@beta" version 2>/dev/null || echo "0.1.0-beta.0")
if [ -z "$LATEST_VERSION" ] || [ "$LATEST_VERSION" = "null" ]; then
LATEST_VERSION="0.1.0-beta.0"
fi
echo "Current version: $LATEST_VERSION"
# Extract the base version and beta number
BASE_VERSION=$(echo $LATEST_VERSION | cut -d'-' -f1)
BETA_NUM=$(echo $LATEST_VERSION | grep -o 'beta\.[0-9]*' | cut -d'.' -f2)
NEXT_BETA=$((BETA_NUM + 1))
NEXT_VERSION="${BASE_VERSION}-beta.${NEXT_BETA}"
echo "Next version will be: $NEXT_VERSION"
echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
- name: Update package.json version
run: |
npm version ${{ steps.get-version.outputs.next_version }} --no-git-tag-version
- name: Publish to npm
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTOMATION_TOKEN }}" > .npmrc
# Publish the package with beta tag
npm publish --access public --tag beta
# Update the beta tag to point to this version
PACKAGE_NAME=$(node -p "require('./package.json').name")
PACKAGE_VERSION=$(node -p "require('./package.json').version")
npm dist-tag add ${PACKAGE_NAME}@${PACKAGE_VERSION} beta
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTOMATION_TOKEN }}