name: CI

on:
  - pull_request
  - push

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

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

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

      - name: Try to restore opam cache
        if: runner.os != 'Windows'
        id: opam-cache
        uses: actions/cache@v2
        with:
          path: |
            ~/.opam
            !~/.opam/log
          key: ${{ matrix.os }}-${{ matrix.ocaml-version }}-v10

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

      - name: Install LLVM repositories Ubuntu
        if: runner.os == 'Linux'
        run: |
          wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
          sudo add-apt-repository -y 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main'

      - name: Install OS packages
        run: sudo apt-get update && sudo apt-get install -yq ninja-build libboost-system-dev libboost-test-dev llvm-13-dev

      - run: opam pin add scilla.dev git+https://github.com/Zilliqa/scilla\#master --no-action
      - run: opam depext scilla --yes
      - run: opam install scilla --yes

      - run: opam install ./ --deps-only --with-test --yes
      - run: opam exec -- make test
      - run: opam install ocamlformat.0.22.4 --yes
      - run: opam exec -- make fmt
