name: GitHub macOS CI

on: [push, pull_request]

permissions:
  contents: read

jobs:
  macOS:
    runs-on: macos-12

    steps:
      - uses: actions/checkout@v3

      - name: Install system dependencies
        run: |
          brew install gnu-time opam gtksourceview3 adwaita-icon-theme expat libxml2 pkg-config
          pip3 install macpack

      - name: Install OCaml dependencies
        run: |
          export PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig
          opam init -a -j "$NJOBS" --compiler=ocaml-base-compiler.$COMPILER
          opam switch set ocaml-base-compiler.$COMPILER
          eval $(opam env)
          opam update
          opam install -j "$NJOBS" ocamlfind${FINDLIB_VER} ounit lablgtk3-sourceview3 zarith.1.11 dune.3.8.3
          opam list
        env:
          COMPILER: "4.12.0"
          FINDLIB_VER: ".1.8.1"
          OPAMYES: "true"
          MACOSX_DEPLOYMENT_TARGET: "10.11"
          NJOBS: "2"

      - name: Build Coq
        run: |
          eval $(opam env)
          ./configure -prefix "$(pwd)/_install_ci" -native-compiler no
          make dunestrap
          dune build -p coq-core,coq-stdlib,coqide-server,coqide,coq
        env:
          MACOSX_DEPLOYMENT_TARGET: "10.11"
          NJOBS: "2"

      - name: Install Coq
        run: |
          eval $(opam env)
          dune install --prefix="$(pwd)/_install_ci" coq-core coq-stdlib coqide-server coqide coq

      - name: Run Coq Test Suite
        run: |
          eval $(opam env)
          cd test-suite
          make clean
          export OCAMLPATH="$(pwd)/../_install_ci/lib":"$OCAMLPATH"
          BIN="$(pwd)/../_install_ci/bin/"
          LIB="$(pwd)/../_install_ci/lib/coq/"
          make -j "$NJOBS" BIN="$BIN" COQLIB="$LIB" PRINT_LOGS=1 TIMED=1 all
        env:
          NJOBS: "2"
