name: Publish to NPM # This workflow handles all publishing to npm for releases and pre-release nightly # builds. We must use a single file rather than separate workflow files because # Trusted Publishing currently supports only a single workflow file. on: release: types: [published] schedule: - cron: '0 2 * * *' # Nightly at 02:00 UTC workflow_dispatch: inputs: publish_type: description: 'Type of publish' required: true type: choice options: - release - master-nightly - minor-nightly jobs: # Determine which publish type(s) to run based on trigger setup: runs-on: ubuntu-latest outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - name: Determine publish matrix id: set-matrix run: | if [ "${{ github.event_name }}" == "release" ]; then echo 'matrix=["release"]' >> $GITHUB_OUTPUT elif [ "${{ github.event_name }}" == "schedule" ]; then echo 'matrix=["master-nightly", "minor-nightly"]' >> $GITHUB_OUTPUT else echo 'matrix=["${{ inputs.publish_type }}"]' >> $GITHUB_OUTPUT fi publish: needs: setup runs-on: ubuntu-latest permissions: contents: read id-token: write strategy: fail-fast: false matrix: type: ${{ fromJson(needs.setup.outputs.matrix) }} steps: - name: Checkout uses: actions/checkout@v4 with: ref: ${{ matrix.type == 'minor-nightly' && 'minor' || matrix.type == 'master-nightly' && 'master' || '' }} fetch-depth: ${{ matrix.type == 'release' && 1 || 0 }} # For nightly builds: check if there were commits in the last 24 hours - name: Check for new commits id: commit_check if: matrix.type != 'release' run: | COMMITS=$(git rev-list --count --since="24 hours" HEAD) echo "Commits found: $COMMITS" if [ "$COMMITS" -eq 0 ]; then echo "should_publish=false" >> $GITHUB_OUTPUT else echo "should_publish=true" >> $GITHUB_OUTPUT fi - name: Setup Node.js if: matrix.type == 'release' || steps.commit_check.outputs.should_publish == 'true' uses: actions/setup-node@v6 with: node-version: '24.x' registry-url: 'https://registry.npmjs.org' - name: Update npm if: matrix.type == 'release' || steps.commit_check.outputs.should_publish == 'true' run: npm install -g npm@latest - name: Install dependencies if: matrix.type == 'release' || steps.commit_check.outputs.should_publish == 'true' run: npm install --no-save - name: Build if: matrix.type == 'release' || steps.commit_check.outputs.should_publish == 'true' run: npm run build # Nightly builds: configure git and bump version - name: Configure Git if: matrix.type != 'release' && steps.commit_check.outputs.should_publish == 'true' run: | git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" - name: Get current date if: matrix.type != 'release' && steps.commit_check.outputs.should_publish == 'true' id: date run: echo "date=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT - name: Version packages (master-nightly) if: matrix.type == 'master-nightly' && steps.commit_check.outputs.should_publish == 'true' run: | CURRENT_VERSION=$(node -p "require('./lerna.json').version") IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION" PATCH=$((VERSION_PARTS[2] + 1)) NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${PATCH}-master-${{ steps.date.outputs.date }}" npx lerna version $NEW_VERSION --no-git-tag-version --yes --no-push --force-publish - name: Version packages (minor-nightly) if: matrix.type == 'minor-nightly' && steps.commit_check.outputs.should_publish == 'true' run: | CURRENT_VERSION=$(node -p "require('./lerna.json').version") IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION" MINOR=$((VERSION_PARTS[1] + 1)) NEW_VERSION="${VERSION_PARTS[0]}.${MINOR}.0-minor-${{ steps.date.outputs.date }}" npx lerna version $NEW_VERSION --no-git-tag-version --yes --no-push --force-publish - name: Commit version changes if: matrix.type != 'release' && steps.commit_check.outputs.should_publish == 'true' run: | git add . git commit -m "chore: Bump version for ${{ matrix.type }} pre-release" # Publish to npm with appropriate dist-tag # Note: we do not use `lerna publish` because at the time of writing, it fails to publish # using the Trusted Publishing workflow for some reason. - name: Publish to NPM (release) if: matrix.type == 'release' run: npx lerna exec --no-private -- npm publish --access public - name: Publish to NPM (master-nightly) if: matrix.type == 'master-nightly' && steps.commit_check.outputs.should_publish == 'true' run: npx lerna exec --no-private -- npm publish --access public --tag master - name: Publish to NPM (minor-nightly) if: matrix.type == 'minor-nightly' && steps.commit_check.outputs.should_publish == 'true' run: npx lerna exec --no-private -- npm publish --dd --access public --tag minor - name: Skip publish (no new commits) if: matrix.type != 'release' && steps.commit_check.outputs.should_publish == 'false' run: echo "No new commits in last 24 hours – skipping ${{ matrix.type }} publish."