name: Main workflow

on:
  pull_request:
  push:
    branches:
      - "1.30"
      - "1.40" # for future
      - "1.50"
      - "more-dune"

permissions: read-all
env:
  OPAMCONFIRMLEVEL: unsafe-yes

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - macos-latest
          # intel macos
          - macos-13
        ocaml-compiler:
          - 4.14.2

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

    steps:
      - name: Checkout tree
        uses: actions/checkout@v4

      - name: Set-up OCaml ${{ matrix.ocaml-compiler }}
        uses: ocaml/setup-ocaml@v3
        with:
          ocaml-compiler: ${{ matrix.ocaml-compiler }}

      - run: gcc --version

      - name: Prepare to install cross-compiler (Ubuntu specific)
        if: ${{ matrix.os == 'ubuntu-latest' }}
        run: |
          sudo dpkg --add-architecture i386
          sudo apt update -y

      - run: opam pin add Lama.dev . --no-action
      - run: opam depext Lama.dev --yes --with-test
      - run: opam install . --deps-only --with-test
      - run: eval $(opam env)

      - run: rm -fr runtime32
        if: ${{ matrix.os == 'macos-latest' || matrix.os == 'macos-13' }}
      - run: opam exec -- dune b src runtime runtime32 stdlib tutorial
        if: ${{ matrix.os != 'macos-latest' && matrix.os != 'macos-13'}}
      - run: opam exec -- dune b src runtime stdlib tutorial
        if: ${{ matrix.os == 'macos-latest' || matrix.os == 'macos-13' }}
      - run: opam exec -- dune b @install --profile=release
      - run: opam exec -- dune    install --profile=release
      - run: opam exec -- dune test stdlib/regression
      - run: opam exec -- dune test regression_long
      - run: opam exec -- dune test regression
      - run: opam exec -- make regression-all

      #  fails on mac
      # - run: opam exec -- dune b
      # - run: opam exec -- dune    install --profile=release
      # - run: opam exec -- dune test stdlib/regression
      # - run: opam exec -- dune test regression
      # - run: opam exec -- dune test regression_long

      # works
      # - run: rm -fr runtime32
      #   if: ${{ matrix.os == 'macos-latest' }}
      # - run: opam exec -- dune b src runtime stdlib tutorial
      #   if: ${{ matrix.os == 'macos-latest' }}
      # - run: opam exec -- make install
      #   if: ${{ matrix.os != 'macos-latest' }}
      # - run: opam exec -- make regression-all

      # - run: opam exec -- dune test stdlib/regression -j1
      # - run: opam exec -- dune b
      # - run: opam exec -- dune b @install
      # - run: opam exec -- dune install
      # - run: opam exec -- make regression
      # - run: opam exec -- dune test regression
