name: CI
on:
  workflow_dispatch:
  pull_request:
    types: [opened, reopened, synchronize]
  push:
    branches: [master]

jobs:
  build:
    runs-on: ubuntu-24.04
    steps:
    - name: Checkout Tree
      uses: actions/checkout@v4
      with:
        submodules: true
    - name: Check Copyright Headers
      run: checks/headers
    - name: Get Z3 submodule commit hash
      id: z3hash
      run: |
        echo "z3_hash=$(git rev-parse HEAD:z3)" >> $GITHUB_OUTPUT
    - name: Restore Z3 build cache
      id: cache-z3
      uses: actions/cache@v4
      with:
        path: z3/build
        key: z3-build-${{ steps.z3hash.outputs.z3_hash }}
    - name: Configure and Build Z3 (if cache miss)
      if: steps.cache-z3.outputs.cache-hit != 'true'
      working-directory: ${{ runner.workspace }}/vampire
      run: |
        mkdir -p z3/build
        cd z3/build
        cmake .. -DCMAKE_BUILD_TYPE=Release -DZ3_BUILD_EXECUTABLE=OFF -DZ3_BUILD_TEST_EXECUTABLES=OFF
        make -j8
      env:
        CXX: clang++
    - name: Configure and Build Vampire (Debug + Unit Tests)
      working-directory: ${{ runner.workspace }}/vampire
      run: |
        mkdir -p build
        cd build
        cmake .. -DCMAKE_BUILD_TYPE=Debug
        make vtest -j8
      env:
        CXX: clang++
    - name: Run Unit Tests
      working-directory: ${{runner.workspace}}/vampire/build
      run: ctest --output-on-failure
    - name: Configure and Build Vampire (Release)
      working-directory: ${{ runner.workspace }}/vampire/build
      run: |
        cmake .. -DCMAKE_BUILD_TYPE=Release
        make -j8
      env:
        CXX: clang++
    - name: Run Sanity Checks
      run: checks/sanity build/vampire
