name: LLM Translation Proofreader

on:
  # danger! PRs have access to env secrets.
  # Only safe as we guard the job to trusted groups below.
  pull_request_target:
    branches: [master]

concurrency:
  group: proofreader-${{ github.event.pull_request.number }}
  cancel-in-progress: true

jobs:
  proofreader:
    name: LLM Translation Proofreader
    if: contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'),
                 github.event.pull_request.author_association)
    runs-on: ubuntu-24.04
    env:
      OPENAI_BASE_URL: "https://api.ppq.ai"
      OPENAI_MODEL: "google/gemini-3-flash-preview"
      CONCURRENCY: "50"
      OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          ref: ${{ github.event.pull_request.head.sha }}

      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.14"

      - name: Install dependencies
        run: pip install polib aiohttp unidiff

      - name: Compute diff
        run: |
          git fetch --depth=1 origin ${{ github.event.repository.default_branch }}
          git diff origin/${{ github.event.repository.default_branch }}..HEAD -- locale/ > /tmp/locale.diff
          echo "Diff size:"
          wc -l /tmp/locale.diff

      - name: Run proofreader
        run: python llm_proofreader/llm_proofreader.py --diff /tmp/locale.diff --output-dir /tmp/proofreader_reports

      - name: Upload reports
        if: always()
        uses: actions/upload-artifact@v7
        with:
          name: proofreader-reports
          path: /tmp/proofreader_reports/
          if-no-files-found: ignore
