name: Validate Python e2e freethread

on:
  push:
    branches:
      - main
    paths-ignore:
      - '**.md'
  pull_request:
    paths-ignore:
      - '**.md'
  schedule:
    - cron: 30 3 * * *
  workflow_dispatch:

jobs:
  setup-versions-from-manifest:
    name: Setup ${{ matrix.python }} ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            macos-15-intel,
            ubuntu-latest,
            ubuntu-24.04-arm
          ]
        python: [3.13.0t, 3.13.1t, 3.13.2t]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: setup-python ${{ matrix.python }}
        id: setup-python
        uses: ./
        with:
          python-version: ${{ matrix.python }}

      - name: Check python-path
        run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
        shell: bash

      - name: Verify Python version
        run: ${{ steps.setup-python.outputs.python-path }} -VVV

      - name: Run simple code
        run: python -c 'import math; print(math.factorial(5))'

  setup-versions-from-file:
    name: Setup ${{ matrix.python }} ${{ matrix.os }} version file
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            macos-15-intel,
            ubuntu-latest,
            ubuntu-24.04-arm
          ]
        python: [3.13.0t, 3.13.1t, 3.13.2t]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: build-version-file ${{ matrix.python }}
        run: echo ${{ matrix.python }} > .python-version

      - name: setup-python ${{ matrix.python }}
        id: setup-python
        uses: ./
        with:
          python-version-file: .python-version

      - name: Check python-path
        run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
        shell: bash

      - name: Verify Python version
        run: ${{ steps.setup-python.outputs.python-path }} -VVV

      - name: Run simple code
        run: python -c 'import math; print(math.factorial(5))'

  setup-versions-from-file-without-parameter:
    name: Setup ${{ matrix.python }} ${{ matrix.os }} version file without parameter
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            macos-15-intel,
            ubuntu-latest,
            ubuntu-24.04-arm
          ]
        python: [3.13.0t, 3.13.1t, 3.13.2t]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: build-version-file ${{ matrix.python }}
        run: echo ${{ matrix.python }} > .python-version

      - name: setup-python ${{ matrix.python }}
        id: setup-python
        uses: ./

      - name: Check python-path
        run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
        shell: bash

      - name: Verify Python version
        run: ${{ steps.setup-python.outputs.python-path }} -VVV

      - name: Run simple code
        run: python -c 'import math; print(math.factorial(5))'

  setup-versions-from-standard-pyproject-file:
    name: Setup ${{ matrix.python }} ${{ matrix.os }} standard pyproject file
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            macos-15-intel,
            ubuntu-latest,
            ubuntu-24.04-arm
          ]
        python: [3.13.0, 3.13.1, 3.13.2]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: build-version-file ${{ matrix.python }}
        run: |
          echo '[project]
            requires-python = "${{ matrix.python }}"
          ' > pyproject.toml

      - name: setup-python ${{ matrix.python }}
        id: setup-python
        uses: ./
        with:
          python-version-file: pyproject.toml
          freethreaded: true

      - name: Check python-path
        run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
        shell: bash

      - name: Run simple code
        run: python -c 'import math; print(math.factorial(5))'

  setup-versions-from-poetry-pyproject-file:
    name: Setup ${{ matrix.python }} ${{ matrix.os }} poetry pyproject file
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            macos-15-intel,
            ubuntu-latest,
            ubuntu-24.04-arm
          ]
        python: [3.13.0, 3.13.1, 3.13.2]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: build-version-file ${{ matrix.python }}
        run: |
          echo '[tool.poetry.dependencies]
            python = "${{ matrix.python }}"
          ' > pyproject.toml

      - name: setup-python ${{ matrix.python }}
        id: setup-python
        uses: ./
        with:
          python-version-file: pyproject.toml
          freethreaded: true

      - name: Check python-path
        run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
        shell: bash

      - name: Run simple code
        run: python -c 'import math; print(math.factorial(5))'

  setup-versions-from-tool-versions-file:
    name: Setup ${{ matrix.python }} ${{ matrix.os }} .tool-versions file
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            macos-15-intel,
            ubuntu-latest,
            ubuntu-24.04-arm
          ]
        python: [3.13.0t, 3.13.1t, 3.13.2t, 3.14t-dev]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: build-tool-versions-file ${{ matrix.python }}
        run: |
          echo "python ${{ matrix.python }}" > .tool-versions

      - name: setup-python using .tool-versions ${{ matrix.python }}
        id: setup-python-tool-versions
        uses: ./
        with:
          python-version-file: .tool-versions

  setup-versions-from-pipfile-with-python_version:
    name: Setup ${{ matrix.python }} ${{ matrix.os }} Pipfile
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            macos-15-intel,
            ubuntu-latest,
            ubuntu-24.04-arm
          ]
        python: [3.13t, 3.14t-dev]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: build-version-file ${{ matrix.python }}
        run: |
          echo '[requires]
            python_version = "${{ matrix.python }}"
          ' > Pipfile

      - name: setup-python ${{ matrix.python }}
        id: setup-python
        uses: ./
        with:
          python-version-file: Pipfile

      - name: Check python-path
        run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
        shell: bash

      - name: Run simple code
        run: python -c 'import math; print(math.factorial(5))'

  setup-versions-from-pipfile-with-python_full_version:
    name: Setup ${{ matrix.python }} ${{ matrix.os }} .tool-versions file
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            macos-15-intel,
            ubuntu-latest,
            ubuntu-24.04-arm
          ]
        python: [3.13.0t, 3.13.1t, 3.13.2t, 3.14t-dev]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: build-version-file ${{ matrix.python }}
        run: |
          echo '[requires]
            python_full_version = "${{ matrix.python }}"
          ' > Pipfile

      - name: setup-python ${{ matrix.python }}
        id: setup-python
        uses: ./
        with:
          python-version-file: Pipfile

      - name: Check python-path
        run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
        shell: bash

      - name: Run simple code
        run: python -c 'import math; print(math.factorial(5))'

  setup-pre-release-version-from-manifest:
    name: Setup 3.14.0-alpha.6 ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            macos-15-intel,
            ubuntu-latest,
            ubuntu-24.04-arm
          ]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: setup-python 3.14.0-alpha.6
        id: setup-python
        uses: ./
        with:
          python-version: '3.14.0-alpha.6'
          freethreaded: true

      - name: Check python-path
        run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
        shell: bash

      - name: Verify Python version
        run: ${{ steps.setup-python.outputs.python-path }} -VVV

      - name: Run simple code
        run: python -c 'import math; print(math.factorial(5))'

  setup-dev-version:
    name: Setup 3.14t-dev ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            ubuntu-24.04-arm,
            ubuntu-latest,
            macos-15-intel
          ]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: setup-python 3.14t-dev
        id: setup-python
        uses: ./
        with:
          python-version: '3.14t-dev'

      - name: Check python-path
        run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
        shell: bash

      - name: Validate version
        run: ${{ startsWith(steps.setup-python.outputs.python-version, '3.14.') }}
        shell: bash

      - name: Run simple code
        run: python -c 'import math; print(math.factorial(5))'

  setup-prerelease-version:
    name: Setup 3.14t ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            ubuntu-24.04-arm,
            ubuntu-latest,
            macos-15-intel
          ]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: setup-python 3.14t
        id: setup-python
        uses: ./
        with:
          python-version: '3.14t'
          allow-prereleases: true

      - name: Check python-path
        run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
        shell: bash

      - name: Validate version
        run: ${{ startsWith(steps.setup-python.outputs.python-version, '3.14.') }}
        shell: bash

      - name: Run simple code
        run: python -c 'import math; print(math.factorial(5))'

  setup-versions-noenv:
    name: Setup ${{ matrix.python }} ${{ matrix.os }} (noenv)
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            macos-15-intel,
            ubuntu-latest,
            ubuntu-24.04-arm
          ]
        python: [3.13.0t, 3.13.1t, 3.13.2t]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: setup-python ${{ matrix.python }}
        id: setup-python
        uses: ./
        with:
          python-version: ${{ matrix.python }}
          update-environment: false

      - name: Verify Python version
        run: ${{ steps.setup-python.outputs.python-path }} -VVV

      - name: Run simple code
        run: ${{ steps.setup-python.outputs.python-path }} -c 'import math; print(math.factorial(5))'

  check-latest:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            ubuntu-24.04-arm,
            ubuntu-latest,
            macos-15-intel
          ]
        python-version: [3.13t, 3.14t-dev]
    steps:
      - uses: actions/checkout@v6
      - name: Setup Python and check latest
        id: setup-python
        uses: ./
        with:
          python-version: ${{ matrix.python-version }}
          check-latest: true
      - name: Verify Python version
        run: ${{ steps.setup-python.outputs.python-path }} -VVV

  setup-python-multiple-python-versions:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            ubuntu-24.04-arm,
            ubuntu-latest,
            macos-15-intel
          ]
    steps:
      - uses: actions/checkout@v6
      - name: Setup Python and check latest
        id: setup-python
        uses: ./
        with:
          python-version: |
            3.13.1t
            3.13.2t
            3.14t-dev
      - name: Verify Python version
        run: ${{ steps.setup-python.outputs.python-path }} -VVV

  setup-versions-with-freethread-input:
    name: Setup ${{ matrix.python }} ${{ matrix.os }} using freethread input parameter
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          [
            macos-latest,
            windows-latest,
            ubuntu-22.04,
            ubuntu-22.04-arm,
            macos-15-intel,
            ubuntu-latest,
            ubuntu-24.04-arm
          ]
        python: [3.13.1, 3.13.2, 3.14-dev, 3.14.0-alpha.6]
    steps:
      - name: Checkout
        uses: actions/checkout@v6
      - name: setup-python ${{ matrix.python }}
        id: setup-python
        uses: ./
        with:
          python-version: ${{ matrix.python }}
          freethreaded: true

      - name: Check python-path
        run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
        shell: bash
      - name: Validate GIL
        run: python ./__tests__/verify-freethreaded.py
