name: Publish to NPM
on:
  workflow_dispatch:
    inputs:
      major:
        description: 'Major'
        type: boolean
        default: false
      minor:
        description: 'Minor'
        type: boolean
        default: false

permissions:
  id-token: write # Required for OIDC
  contents: read

jobs:
  publish_job:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          token: ${{ secrets.PAT_GITHUB }}
      - name: Setup Git config
        run: |
          git config --local user.email 'hello@rive.app'
          git config --local user.name ${{ github.actor }}
      - uses: actions/setup-node@v4
        with:
          node-version: '24'
          registry-url: 'https://registry.npmjs.org'
      - name: Upgrade npm for OIDC support
        run: npm install -g npm@latest
      - name: Install Modules
        run: npm install
      - name: Run type check
        run: npm run types:check
      - name: Run Linter
        run: npm run lint
      - name: Run Tests
        run: npm test
      - if: ${{ inputs.major == true }}
        name: Major Release - Bump version number, update changelog, push and tag
        run: npm run release:major
      - if: ${{inputs.major == false && inputs.minor == true}}
        name: Minor release - Bump version number, update changelog, push and tag
        run: npm run release:minor
      - if: ${{inputs.major == false && inputs.minor == false}}
        name: Patch release - Bump version number, update changelog, push and tag
        run: npm run release:patch
