Skip to content

NPM Release

NPM Release #286

Workflow file for this run

name: NPM Release
on:
push:
tags:
- 'v*' # Trigger on version tags like v1.0.0, v1.2.3, etc.
schedule:
# Run daily at 10:00 PM UTC for nightly builds
- cron: '0 22 * * *'
workflow_dispatch: # Allow manual trigger
jobs:
check-version:
if: startsWith(github.ref, 'refs/tags/')
uses: ./.github/workflows/shared-check-version.yml
publish-npm:
needs: [check-version]
if: always() && (needs.check-version.result == 'success' || needs.check-version.result == 'skipped')
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Determine build type
id: build_type
shell: bash
run: |
set -ex
if [[ "${{ github.event_name }}" == "schedule" ]] || ([[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ ! "${{ github.ref }}" =~ ^refs/tags/ ]]); then
echo "type=nightly" >> $GITHUB_OUTPUT
echo "Build type: nightly"
else
echo "type=production" >> $GITHUB_OUTPUT
echo "Build type: production"
fi
- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 22.x
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Get current version
id: get_version
shell: bash
run: |
VERSION=$(node -p "require('./packages/poml-build/package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Current version: $VERSION"
- name: Create nightly version
if: steps.build_type.outputs.type == 'nightly'
id: create_nightly
shell: bash
run: |
# Create a nightly version with timestamp
TIMESTAMP=$(date +%Y%m%d%H%M)
node bump-version.js ${{ steps.get_version.outputs.version }} "$TIMESTAMP"
NIGHTLY_VERSION=$(node -p "require('./packages/poml-build/package.json').version")
echo "Nightly version: $NIGHTLY_VERSION"
echo "nightly_version=$NIGHTLY_VERSION" >> $GITHUB_OUTPUT
- name: Install dependencies
run: npm ci
- name: Build webview and CLI
run: |
npm run build-webview
npm run build-cli
- name: Build NPM package
run: |
cd packages/poml-build
npm pack
ls -la *.tgz
- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: npm-package-${{ github.event_name }}
path: packages/poml-build/*.tgz
compression-level: 0
- name: Publish to npm (nightly)
if: steps.build_type.outputs.type == 'nightly'
run: |
cd packages/poml-build
npm publish --provenance --access public --tag nightly
- name: Publish to npm (production)
if: steps.build_type.outputs.type == 'production'
run: |
cd packages/poml-build
npm publish --provenance --access public
- name: Verify nightly publication
if: steps.build_type.outputs.type == 'nightly'
run: |
# Wait a bit for the package to be available
sleep 30
npm view pomljs@${{ steps.create_nightly.outputs.nightly_version }}
echo "✅ Nightly package successfully published to npm registry!"
- name: Verify production publication
if: steps.build_type.outputs.type == 'production'
run: |
# Wait a bit for the package to be available
sleep 30
npm view pomljs@${{ needs.check-version.outputs.npm_version }}
echo "✅ Package successfully published to npm!"