- name: Install dependencies
  run: |
    set -ex
    sudo add-apt-repository ppa:avsm/ppa -y # provides OPAM 2
    sudo add-apt-repository ppa:haxe/ocaml -y # provides newer version of mbedtls
    sudo apt-get update -qqy
    sudo apt-get install -qqy ocaml-nox camlp5 opam libpcre3-dev zlib1g-dev libgtk2.0-dev libmbedtls-dev ninja-build libstring-shellquote-perl

- name: Install OCaml libraries
  run: |
    set -ex
    opam init # --disable-sandboxing
    opam update
    opam pin add haxe . --no-action
    opam install haxe --deps-only --assume-depexts
    opam list
    ocamlopt -v

- name: Set ADD_REVISION=1 for non-release
  if: ${{ !startsWith(github.ref, 'refs/tags/') }}
  run: echo "ADD_REVISION=1" >> $GITHUB_ENV

- name: Build Haxe
  run: |
    set -ex
    eval $(opam env)
    opam config exec -- make -s -j`nproc` STATICLINK=1 haxe
    opam config exec -- make -s haxelib
    make -s package_unix
    ls -l out
    ldd -v ./haxe
    ldd -v ./haxelib

# https://stackoverflow.com/questions/58033366/how-to-get-current-branch-within-github-actions
- name: Extract branch name
  id: extract_branch
  shell: bash
  run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"

- name: Build xmldoc
  run: |
    set -ex
    make -s xmldoc
    cat >extra/doc/info.json <<EOL
      {
        "commit": "$GITHUB_SHA",
        "branch": "${{ steps.extract_branch.outputs.branch }}"
      }
    EOL

- name: Upload xmldoc artifact
  uses: actions/upload-artifact@v1.0.0
  with:
    name: xmldoc
    path: extra/doc

- name: Upload artifact
  uses: actions/upload-artifact@v1.0.0
  with:
    name: linuxBinaries
    path: out
