# envaudit: check every new or changed Harbor task on each pull request.
# Copy to .github/workflows/envaudit.yml in a Harbor-format benchmark repo (Terminal-Bench,
# Terminal-Bench-Science, ...) and add ANTHROPIC_API_KEY under Settings > Secrets and variables > Actions.
# The job fails if any changed task's grader can be passed without doing the task. The verified
# grader patches, if any, are in the envaudit-report artifact under envaudit_fixes/.
# Pull requests from forks get no secrets on GitHub, so for those the scan cannot call the API.
name: envaudit

on:
  pull_request:

permissions:
  contents: read

jobs:
  envaudit:
    runs-on: ubuntu-latest
    timeout-minutes: 360
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0  # full history, so --changed-since can find the merge base

      # Docker comes installed and running on GitHub's ubuntu runners; Harbor runs every task in it.
      - name: Check Docker
        run: docker info --format 'Docker {{.ServerVersion}}'

      - uses: astral-sh/setup-uv@v6

      - name: Install envaudit and Harbor
        run: |
          pipx install envaudit-cli
          uv tool install harbor
          harbor --version

      - name: Audit changed tasks
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        run: envaudit harbor . --changed-since origin/${{ github.base_ref }} --fix --fail-on hack --budget 5

      - name: Upload report and fixes
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: envaudit-report
          path: |
            report.html
            report.json
            envaudit_fixes/
          if-no-files-found: ignore
