name: Update the Python versions

on:
  workflow_dispatch:
    inputs:
      tag:
        description: 'Tag to update'
        required: false
        type: string

jobs:
  update:
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: pdm-project/setup-pdm@v4
        with:
          python-version: '3.11'
          cache: 'true'
      - run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          pdm install

      - run: pdm run update
        id: update
        continue-on-error: true
        env:
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
          TARGET_VERSION: ${{ github.event.inputs.tag }}

      - name: Push changes
        if: steps.update.outcome == 'success'
        uses: ad-m/github-push-action@master
        with:
          tags: true

      - name: Create Release
        if: steps.update.outcome == 'success'
        uses: ncipollo/release-action@v1
        with:
          name: ${{ steps.update.outputs.VERSION }}
          tag: ${{ steps.update.outputs.VERSION }}
          token: ${{ secrets.GH_TOKEN }}
