name: CI

on:
  push:
    tags:
      - '*'
    #branches: [ master ]
  workflow_dispatch:

jobs:
  build:
    strategy:
      matrix:
        os:
          - ubuntu-latest
          # - macos-latest
        ocaml-compiler:
          - 4.13.0
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Install libgtk-3-dev
        run: sudo apt-get update && sudo apt-get -y install libgtk-3-dev
  
      - name: Setup OCaml ${{ matrix.ocaml-compiler }}
        uses: ocaml/setup-ocaml@v2
        with:
          ocaml-compiler: ${{ matrix.ocaml-compiler }}
          dune-cache: true

      - name: Install dependencies
        run: opam install . --deps-only

      - name: Build doculib
        run: opam exec -- dune build

#      - name: Build and deploy documentation
#        if: matrix.os == 'ubuntu-latest'    
#        uses: ocaml/setup-ocaml/deploy-doc@v2
#        with:
#          destination-dir: docs

      - name: Rename binary (macOS)
        if: matrix.os == 'macOS-latest'
        run: mv _build/default/doculib.exe _build/default/doculib

      - name: Save binary (macOS)
        if: matrix.os == 'macOS-latest'
        uses: actions/upload-artifact@v2
        with:
          name: doculib-${{ github.ref_name }}-${{ runner.os }}-x86_64
          path: _build/default/doculib

      - name: Build package (debian)
        if: matrix.os == 'ubuntu-latest'
        run: mkdir release/packages &&
             bash release/release_amd64.sh

      - name: Save package (debian)
        if: matrix.os == 'ubuntu-latest'
        uses: actions/upload-artifact@v2
        with:
          name: doculib-${{ github.ref_name }}-${{ runner.os }}-x86_64
          path: release/packages/doculib_*_amd64.deb
