name: "Build"

on:
  - push
  - pull_request

jobs:
  build: # Check build on various OSes

    strategy:
      matrix:
        os:
          - ubuntu-latest
        ocaml-compiler:
          - 4.02.x
          - 4.04.x
          - 4.06.x
          - 4.08.x
          - 4.10.x
          - 4.12.x
          - 4.14.x
        include:
          - os: ubuntu-latest
            ocaml-compiler: 4.14.x
            # We don't need to compute coverage for more than one build
            send-coverage: true
            # Mdx tests Mdx tests
            run-mdx: true
      fail-fast: false

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

    steps:
      # Clone the project
      - uses: actions/checkout@v2

      # Setup
      - name: Setup OCaml ${{ matrix.ocaml-version }}
        uses: ocaml/setup-ocaml@v2
        with:
          # Do not pin odoc to not break Mdx installation
          opam-pin: false
          ocaml-compiler: ${{ matrix.ocaml-compiler }}
          opam-local-packages: |
            odoc.opam

      - name: Install dependencies
        run: opam install -y --deps-only -t ./odoc.opam ./odoc-parser.opam

      - name: dune runtest
        run: opam exec -- dune runtest

      - name: Mdx tests
        if: matrix.run-mdx == true
        run: |
          opam install -y mdx
          opam exec -- dune build @runmdx

      - name: Send coverage stats to Coveralls
        if: matrix.send-coverage == true
        run: |
          opam install bisect_ppx
          opam exec -- dune runtest --instrument-with bisect_ppx --force
          opam exec -- bisect-ppx-report send-to Coveralls
        env:
          COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PULL_REQUEST_NUMBER: ${{ github.event.number }}
