name: Release to NPM and GitHub

on:
  workflow_dispatch:
    inputs:
      releaseType:
        description: "Release Type"
        required: true
        type: choice
        options:
          - "major"
          - "minor"
          - "patch"
        default: "patch"

env:
  NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: "main"
          fetch-depth: 0

      - uses: actions/setup-node@v3
        with:
          node-version: 16

      - name: NPM Setup
        run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN

      - name: Git Setup
        run: |
          git config user.name "${GITHUB_ACTOR}"
          git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"

      - name: Install Dependencies
        run: npm ci

      - name: Release
        run: npm run release.ci -- ${{github.event.inputs.releaseType}}
        env:
          GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
