on:
  workflow_dispatch:
    inputs:
      release_notes:
        description: Release notes (use \n for newlines)
        type: string
        required: false
      github_release:
        description: 'Create Gitea Release'
        default: true
        type: boolean
      bump:
        description: 'Bump type'
        required: false
        default: 'patch'
        type: choice
        options:
          - 'major'
          - 'minor'
          - 'patch'


jobs:
  bump:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Install UV
        uses: astral-sh/setup-uv@v5
      - name: Set up Python
        run: uv python install
        with:
          python-version-file: "pyproject.toml"
      - name: Install dependencies
        run: uv sync --locked --all-extras --dev
      - name: Install Bump tool
        run: uv tool install bump-my-version
      - name: Bump version
        id: bump_version
        run: |
          uv tool run bump-my-version --bump ${{ github.event.inputs.bump }} --tag --allow-dirty
      - name: Add release notes
        id: add_release_notes
        run: |
          echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
          echo "${{ github.event.inputs.release_notes }}" >> $GITHUB_ENV
          echo "EOF" >> $GITHUB_ENV
      - name: Create Gitea Release
        if: ${{ github.event.inputs.github_release == 'true' }}
        uses: softprops/action-gh-release@v1
        with:
          tag_name: ${{ github.sha }}
          release_name: Release ${{ github.sha }}
          body: ${{ env.RELEASE_NOTES }}
          draft: false
          prerelease: false
        env:
          GITHUB_TOKEN: ${{ secrets.TOKEN }}
          GITHUB_REPOSITORY: ${{ github.repository }}