name: Test Release (TestPyPI)

# Trigger manually for testing releases
on:
  workflow_dispatch:
    inputs:
      version:
        description: 'Version to test (e.g., 2.1.0-rc1)'
        required: true
        type: string

permissions:
  contents: read
  id-token: write

jobs:
  test-release:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.10'

      - name: Install build dependencies
        run: |
          python -m pip install --upgrade pip
          pip install build twine

      - name: Build package
        run: |
          python -m build

      - name: Check package
        run: |
          twine check dist/*

      - name: Publish to TestPyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          repository-url: https://test.pypi.org/legacy/
          password: ${{ secrets.TEST_PYPI_API_TOKEN }}
          skip-existing: true

      - name: Test installation from TestPyPI
        run: |
          pip install --index-url https://test.pypi.org/simple/ \
            --extra-index-url https://pypi.org/simple \
            claude-force==${{ github.event.inputs.version }}

          # Verify installation
          claude-force --version

      - name: Report success
        run: |
          echo "✅ Test release successful!"
          echo "Version: ${{ github.event.inputs.version }}"
          echo "Install command:"
          echo "pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple claude-force==${{ github.event.inputs.version }}"
