# .github/workflows/proof.yml
name: CI Proof Verification

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  setup:
    name: Setup Environment
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y curl python3 python3-pip opam build-essential libffi-dev libssl-dev libgmp-dev libncurses-dev zlib1g-dev
          curl -s https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh | bash -s -- -y
          export PATH="/root/.elan/bin:${PATH}"
          opam init -y --disable-sandboxing
          opam install -y coq
          pip3 install numpy sympy

      - name: List proof files
        run: ls -R .

  build:
    name: Build Lean & Coq Proofs
    runs-on: ubuntu-22.04
    needs: setup
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Build Lean proofs
        run: lean --make proofs/Proofs.lean

      - name: Build Coq proofs
        run: coqc proofs/Proofs.v

      - name: Upload proof build logs
        run: |
          mkdir -p logs
          lean --make proofs/Proofs.lean > logs/lean_build.log 2>&1
          coqc proofs/Proofs.v > logs/coq_build.log 2>&1
      - uses: actions/upload-artifact@v3
        with:
          name: proof-build-logs
          path: logs/

  verify:
    name: GPT Verification
    runs-on: ubuntu-22.04
    needs: build
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Run GPT verification
        run: python3 gpt_verify.py proofs/Proofs

      - name: Upload GPT report
        run: python3 gpt_verify.py proofs/Proofs > gpt_report.json
      - uses: actions/upload-artifact@v3
        with:
          name: gpt-report
          path: gpt_report.json
