name: PYPI-TEST-PUBLISH

on:
  workflow_dispatch:
    inputs:
      TESTPYPI_VESION:
        description: 'TestPyPI Version'
        required: true

permissions:
  contents: read

jobs:
  publish:
    name: Publish to Test PyPi
    runs-on: ubuntu-latest
    environment:
      name: test
      url: https://test.pypi.org/project/linkify-it-py/
    permissions:
      id-token: write
    steps:
      - name: Checkout source
        uses: actions/checkout@v6
      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: 3.12
      - name: Replace version
        run:
          sed -rie "s/__version__ = \"(.*)\"/__version__ = \"\1.${{ inputs.TESTPYPI_VESION }}\""/g linkify_it/__init__.py
      - name: Build package
        run: |
          pip install build
          python -m build
      - name: Publish package distributions to TestPyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          repository-url: https://test.pypi.org/legacy/
