name: Deploy web

on:
  push:
    branches:
      - 'release'
      - 'develop'

jobs:
  build:
    strategy:
      matrix:
        ocaml-version:
          - 4.14.x

    runs-on: ubuntu-latest

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

      - name: Use OCaml ${{ matrix.ocaml-version }}
        uses: ocaml/setup-ocaml@v2
        with:
          ocaml-compiler: ${{ matrix.ocaml-version }}
          cache-prefix: v2

      - name: Setup yarn
        uses: actions/setup-node@v3
        with:
          cache: 'yarn'
          cache-dependency-path: 'web/yarn.lock'

      - run: opam install . --deps-only --with-doc --with-test

      - run: opam exec -- dune build

      - run: cd web && yarn

      - name: Deploy live version
        run: opam exec -- make -C web minify

      - name: Deploy docs (dev)
        if: github.event_name == 'push' && github.ref_name == 'develop'
        uses: JamesIves/github-pages-deploy-action@v4.3.4
        with:
          folder: _site
          target-folder: dev
          single-commit: true

      - name: Deploy docs (release)
        if: github.event_name == 'push' && github.ref_name == 'release'
        uses: JamesIves/github-pages-deploy-action@v4.3.4
        with:
          folder: _site
          target-folder: .
          single-commit: true
