name: Build PR

on:
  pull_request:
    paths-ignore:
      - 'README.md'
    branches:
      - 'master'

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-20.04
        ocaml-version:
          - 4.10.1

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

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Retrieve date for cache key
        id: cache-key
        run: echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")"
        shell: bash

      - name: Restore opam cache
        id: opam-cache
        uses: actions/cache@v2
        with:
          path: "~/.opam"
          # invalidate cache daily, gets built daily using a scheduled job
          key: ${{ steps.cache-key.outputs.date }}

      - name: Use OCaml ${{ matrix.ocaml-version }}
        uses: avsm/setup-ocaml@v1
        with:
          ocaml-version: ${{ matrix.ocaml-version }}

      - run: opam pin add GT.dev . --no-action
      - run: opam depext GT.dev --yes --with-test
      - run: opam install . --deps-only --with-test
      - run: opam exec -- make #dune build
      - run: opam exec -- make test # dune runtest
