name: Version Bump
on:
  push:
    branches:
      - main
  workflow_dispatch:
    inputs:
      prerelease:
        type: boolean
        description: Pre-release?
        default: true
      bump:
        type: choice
        description: Which version?
        default: 'minor'
        options:
          - minor
          - patch

env:
  PRERELEASE: ${{github.event.inputs.prerelease}}
  DEFAULT_BUMP: ${{github.event.inputs.bump}}
  APP_ID: 257305

jobs:
  build:
    runs-on: ubuntu-22.04
    steps:
      - name: Generate token
        id: generate_token
        uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
        with:
          app_id: ${{ env.APP_ID }}
          private_key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }}
          permissions: >-
            {"contents": "write"}
      - uses: actions/checkout@v4
        with:
          fetch-depth: "0"
      - uses: actions/setup-node@v4
        with:
          node-version: 16
      - run: npm install -g semver
      - name: Bump version and push tag
        env:
          GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
        run: .github/actions/github-tag-action/entrypoint.sh
