name: reproduce

on:
  pull_request:
  push:
    branches: [main]

concurrency:
  group: reproduce-${{ github.ref }}
  cancel-in-progress: true

jobs:
  check-only-host:
    name: "run_all.sh check-only (host python)"
    runs-on: ubuntu-22.04
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v4

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

      - name: Install minimal host deps
        run: |
          python -m pip install --upgrade pip
          pip install pytest numpy scipy jsonschema

      - name: Run check-only end-to-end
        run: bash run_all.sh check-only

      - name: Run pytest
        run: pytest tests/test_reproduce_e2e.py -v

      - name: Upload reproducibility reports
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: reproduce-reports
          path: |
            outputs/sigma_check.md
            outputs/reproduce_report.md
            outputs/fom_repro.json
          if-no-files-found: ignore

  docker-cpu-build:
    name: "docker build Dockerfile.cpu"
    runs-on: ubuntu-22.04
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Build CPU reproducibility image
        run: |
          docker build -f Dockerfile.cpu -t cf10:cpu-ci .

      - name: Smoke-test image (check-only)
        run: |
          docker run --rm -v "$PWD/outputs:/workspace/outputs" cf10:cpu-ci check-only

      - name: Upload docker-run reports
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: docker-reports
          path: outputs/
          if-no-files-found: ignore
