name: Builds, tests & co

on:
  - push
  - pull_request

permissions: read-all

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - macos-latest
#          - windows-latest
        ocaml-compiler:
          - "5.2"
          - "4.14"
        rocq_version:
          - "9.0.0"
          - "9.1.1"
        exclude:
          - ocaml-compiler: "5.5"
            rocq_version: "9.0.0"

    runs-on: ${{ matrix.os }}

    steps:
      - name: Install Xq for testings
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install xq

      - name: Checkout tree
        uses: actions/checkout@v4

      - name: Set-up OCaml
        uses: ocaml/setup-ocaml@v3
        with:
          ocaml-compiler: ${{ matrix.ocaml-compiler }}
          opam-repositories: |
            rocq-released: https://rocq-prover.org/opam/released
            default: https://github.com/ocaml/opam-repository.git

      - name: Set-up Rocq for testing
        run: |
          opam install -y rocq-core.${{ matrix.rocq_version }} rocq-stdlib
          opam install -y . --deps-only --with-test

      - name: Build
        run: opam exec -- make all

      - name: Test
        run: opam exec -- make test

      - name: Upload the test results as artifacts
        uses: actions/upload-artifact@v4
        with:
          name: test-${{ matrix.os }}-ocaml.${{ matrix.ocaml-compiler }}-rocq.${{ matrix.rocq_version }}
          path: test
