# 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@v5

      - name: Set up node
        uses: actions/setup-node@v5
        with:
          node-version: 20
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Get package version
        uses: martinbeentjes/npm-get-version-action@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}}
