name: Publish to PyPI

on:
  push:
    tags:
      - 'v*.*.*'  # v1.2.0, v1.2.1 등의 태그가 푸시되면 실행

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install uv
        uses: astral-sh/setup-uv@v4
        with:
          version: "latest"

      - name: Install dependencies
        run: uv sync

      - name: Run core tests (fast)
        run: |
          uv run pytest tests/test_filter_fix.py -v

  publish:
    needs: test
    runs-on: ubuntu-latest
    permissions:
      contents: write    # 저장소 체크아웃 + GitHub Release 생성용
      id-token: write    # PyPI Trusted Publishers용

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install uv
        uses: astral-sh/setup-uv@v4
        with:
          version: "latest"

      - name: Build package
        run: uv build

      - name: Publish to PyPI
        run: |
          uv publish
        env:
          UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v1
        with:
          generate_release_notes: true
          files: |
            dist/*.tar.gz
            dist/*.whl
