name: Release

on:
  workflow_dispatch:
    inputs:
      dry-run:
        required: false
        type: boolean
        default: false
        description: "Whether to run the release in dry-run mode"

env:
  VENV: .venv

jobs:
  release:
    name: Release
    permissions:
      contents: write
      pull-requests: write
    runs-on: ubuntu-latest
    environment: release
    steps:
      - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Setup Environment
        uses: ./.github/actions/setup-env

      - name: Install project dependencies
        run: . script/bootstrap

      - name: Release
        uses: cycjimmy/semantic-release-action@b12c8f6015dc215fe37bc154d4ad456dd3833c90 # v6.0.0
        with:
          branches: |
            [
              'main'
            ]
          dry_run: ${{ inputs.dry-run }}
          extra_plugins: |
            @semantic-release/changelog
            @semantic-release/exec
            @semantic-release/git
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_PUBLISH_TOKEN }}
          GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_PAT }}
