name: Tag Service

on:
  workflow_dispatch:
    inputs:
      bump:
        description: 'How much to bump the version by'
        required: true
        type: choice
        options:
          - major
          - minor
          - patch
          - prerelease
          - finalize-prerelease
      service:
        description: 'Which service to release'
        required: true
        type: choice
        options:
          - ci-builder
          - indexer
          - op-heartbeat
          - chain-mon
          - op-node
          - op-batcher
          - op-proposer
          - op-challenger
          - op-ufm
          - proxyd
          - ufm-metamask
      prerelease:
        description: Increment major/minor/patch as prerelease?
        required: false
        type: boolean
        default: false

jobs:
  release:
    runs-on: ubuntu-latest
    environment: op-stack-production

    steps:
      - uses: actions/checkout@v4
      - name: Fetch tags
        run: git fetch --tags origin --force
      - name: Setup Python 3.10
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - name: Install deps
        run: pip install -r requirements.txt
        working-directory: ops/tag-service
      - run: ops/tag-service/tag-service.py --bump="$BUMP" --service="$SERVICE"
        env:
          INPUT_GITHUB_TOKEN: ${{ github.token }}
          BUMP: ${{ github.event.inputs.bump }}
          SERVICE: ${{ github.event.inputs.service }}
        if: ${{ github.event.inputs.prerelease == 'false' }}
      - run: ops/tag-service/tag-service.py --bump="$BUMP" --service="$SERVICE" --pre-release
        env:
          INPUT_GITHUB_TOKEN: ${{ github.token }}
          BUMP: ${{ github.event.inputs.bump }}
          SERVICE: ${{ github.event.inputs.service }}
        if: ${{ github.event.inputs.prerelease == 'true' }}
