- name: Setup ocaml
  id: ocaml
  continue-on-error: true
  uses: kLabz/setup-ocaml@win32
  with:
    ocaml-compiler: 4.08.1
    opam-depext: false
    opam-repositories: |
      opam-repository-mingw: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset
      default: https://github.com/ocaml/opam-repository.git
    opam-local-packages: |
      haxe.opam
    cache-prefix: w32-v1

# TODO make it work on first try
# (when cygwin cache doesn't exist, ocaml install fails with a curl error)
- name: Setup ocaml (second chance)
  if: steps.ocaml.outcome == 'failure'
  uses: kLabz/setup-ocaml@win32
  with:
    ocaml-compiler: 4.08.1
    opam-depext: false
    opam-repositories: |
      opam-repository-mingw: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset
      default: https://github.com/ocaml/opam-repository.git
    opam-local-packages: |
      haxe.opam
    cache-prefix: w32-v1

- name: Install dependencies
  shell: pwsh
  run: |
    Set-PSDebug -Trace 1
    curl.exe -fsSL -o "libmbedtls.tar.xz" --retry 3 https://github.com/Simn/mingw64-mbedtls/releases/download/2.16.3/mingw64-$($env:MINGW_ARCH)-mbedtls-2.16.3-1.tar.xz
    & "$($env:CYG_ROOT)/bin/bash.exe" @('-lc', 'curl -L https://cpanmin.us | perl - App::cpanminus')
    & "$($env:CYG_ROOT)/bin/bash.exe" @('-lc', 'cpanm IPC::System::Simple module')
    & "$($env:CYG_ROOT)/bin/bash.exe" @('-lc', 'cpanm String::ShellQuote')
    & "$($env:CYG_ROOT)/bin/bash.exe" @('-lc', 'echo "$OLDPWD"')
    & "$($env:CYG_ROOT)/bin/bash.exe" @('-lc', 'cd "$OLDPWD" && tar -C / -xvf libmbedtls.tar.xz')
