name: Publish Package

on:
  workflow_dispatch:
    inputs:
      channel:
        description: "Version suffix, e.g. -beta.xx, -latest"
        type: choice
        options:
          - latest
          - beta
        default: "beta"
      dry_run:
        description: "Perform a dry run without publishing"
        type: boolean
        default: false

jobs:
  publish:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - name: Install pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 9
      - name: Use Node.js 22
        uses: actions/setup-node@v4
        with:
          node-version: 22
          registry-url: "https://registry.npmjs.org"
          scope: "@limlabs"
      - name: Install dependencies
        run: pnpm install
      - name: Publish package
        run: |
          if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
          echo "Performing a dry run..."
          pnpm publish --access public --dry-run --no-git-checks
          elif [ "${{ github.event.inputs.channel }}" = "latest" ]; then
          pnpm publish --access public --no-git-checks
          else
          pnpm publish --access public --tag ${{ github.event.inputs.channel }} --no-git-checks
          fi
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
