name: Build & Test

on:
  push: {}
  pull_request:
    branches:
      - master

jobs:
  lint:
    name: Linting

    strategy:
      fail-fast: true
      matrix:
        ocaml-compiler:
          - 4.14.x
        os:
          - ubuntu-latest

    runs-on: ${{ matrix.os }}
    steps:
      - uses: fkirc/skip-duplicate-actions@master

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

      - name: Check whitespaces
        run: ./LINT

      - name: Use OCaml ${{ matrix.ocaml-compiler }}
        uses: ocaml/setup-ocaml@v2
        with:
          ocaml-compiler: ${{ matrix.ocaml-compiler }}
          dune-cache: true

      - name: Install dependencies
        run: opam install --locked --deps-only --with-test --with-doc ./beluga.opam

      - name: Check format
        run: opam exec -- dune fmt

  build-and-test:
    name: Build & Test

    strategy:
      fail-fast: true
      matrix:
        ocaml-compiler:
          - 4.14.x
        os:
          - ubuntu-latest
          - macOS-latest
          # - windows-latest

    runs-on: ${{ matrix.os }}
    steps:
      # Cancel queued workflows from earlier commits in this branch
      - uses: fkirc/skip-duplicate-actions@master

      - name: Set git to use LF line ending
        run: |
          git config --global core.autocrlf false
          git config --global core.eol lf

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

      - name: Use OCaml ${{ matrix.ocaml-compiler }}
        uses: ocaml/setup-ocaml@v2
        with:
          ocaml-compiler: ${{ matrix.ocaml-compiler }}
          dune-cache: true

      - name: Install coreutils on MacOS
        if: runner.os == 'macOS'
        run: brew install coreutils

      - name: Install dependencies
        run: opam install --locked --deps-only --with-test --with-doc ./beluga.opam

      - name: Build
        run: opam exec -- make

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