name: Publish Manually
on:
  workflow_dispatch:
    inputs:
      nodeVersion:
        description: 'Node Version'
        required: true
        default: '24.x'
        type: choice
        options:
          - '24.x'
          - '22.x'
          - '20.x'
          - '18.x'
          - '16.x'
          - '14.x'
      tag:
        description: 'NPM Registry Tag Name'
        required: true
        default: 'next'
        type: choice
        options:
          - 'next'
          - 'v1-legacy'
      dryRun:
        description: Do a dry-run publish (no registry write)
        required: true
        default: true
        type: boolean

jobs:
  publish:
    name: Publish Release Manually
    runs-on: ubuntu-latest
    steps:
      - name: Checkout ⬇
        uses: actions/checkout@v1

      - name: Setup Node.js ${{ inputs.nodeVersion }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ inputs.nodeVersion }}
          registry-url: 'https://registry.npmjs.org'

      - name: Install
        run: npm ci

      - name: Build 🛠
        run: npm run build --if-present

      - name: Test 🚦
        run: npm test

      - name: Publish
        if: ${{ inputs.dryRun == false }}
        run: npm publish --access public --tag ${{ inputs.tag }}
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

      - name: Dry-run publish (no registry write)
        if: ${{ inputs.dryRun }}
        run: npm publish --access public --tag "${{ inputs.tag }}" --dry-run
