on:
  push:

jobs:
  ide:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: ${{ env.FETCH_DEPTH }}
      - name: Setup Node.js environment
        uses: actions/setup-node@v4
      - run: npm ci
        working-directory: ide
  server:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: ${{ env.FETCH_DEPTH }}
      - uses: ocaml/setup-ocaml@v3
        with:
          ocaml-compiler: 4.14.0
        env:
          OPAMLOCKED: locked
      - name: OCaml cache
        id: ocaml-cache
        uses: actions/cache@v3
        env:
          cache-name: cache-ocaml
          dune-cache: true
        with:
          path: _opam
          key: ${{ runner.os }}-${{ env.cache-name }}-ocaml5.2-${{ hashFiles('**/*.opam') }}
          restore-keys: |
            ${{ runner.os }}-${{ env.cache-name }}-ocaml5.2
      - run: opam install . --deps-only
      - run: opam exec -- dune build
      # Cleanup _opam before updating cache
      - if: ${{ steps.cache-ocaml.outputs.cache-hit != 'true' }}
        name: Cleanup _opam before updating cache
        continue-on-error: true
        run: |
          opam clean
          ls
