# This is a basic workflow to help you get started with Actions

name: check_correctness

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: 'master'
  pull_request:
    branches: '**'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      - name: Opam modules cache
        uses: actions/cache@v1
        env:
          cache-name: cache-opam-modules
        with:
          # The opam files are in a global switch
          path: ~/.opam
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('mlang.opam', 'Makefile') }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-
            ${{ runner.os }}-build-
            ${{ runner.os }}-

      - name: Set up OCaml
        uses: ocaml/setup-ocaml@v2
        with:
          # Version of the OCaml compiler to initialise
          ocaml-compiler: 4.11.2

      - name: Install dependencies
        run: |
          sudo apt install m4 perl python3 clang git build-essential lzip libgmp-dev libmpfr-dev
          opam update
          make init-without-switch

      - name: Formatting
        run : |
          eval $(opam env)
          dune build @fmt

      - name: Build Mlang
        run: |
          eval $(opam env)
          make build

      - name: Test interpreter
        run: |
          eval $(opam env)
          OPTIMIZE=0 make tests

      - name: Test DGFIP C backend
        run: |
          eval $(opam env)
          make test_dgfip_c_backend

