# This workflow publishes a package to NPM under the `next` tag

name: Prerelease package on npm

on:
  push:
    branches:
      - prerelease

jobs:
  prerelease:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Set up node
        uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
        with:
          node-version: 20
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Get package version
        uses: martinbeentjes/npm-get-version-action@3cf273023a0dda27efcd3164bdfb51908dd46a5b # v1.3.1
        id: version

      - name: Publish if prerelease
        run: |
          if [[ "${{ steps.version.outputs.current-version}}" =~ ^(.*-(alpha|beta|next|rc)(\..+)?)$ ]]; then
            npm publish --access public --tag next
          else
            echo "Skipping publish since version is not a prerelease."
          fi
        env:
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}
