# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8
    - name: Prepare dependencies
      run: |
          sudo apt-key update
          sudo apt-get update -qq
          sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
          sudo apt-get update; sudo apt-get install -y gcc-4.8 g++-4.8
          sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20
          sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20
          sudo update-alternatives --config gcc
          sudo update-alternatives --config g++
          mkdir $HOME/usr
          export PATH="$HOME/usr/bin:$PATH"
          wget https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.sh
          chmod +x cmake-3.7.2-Linux-x86_64.sh
          "./cmake-3.7.2-Linux-x86_64.sh --prefix=$HOME/usr --exclude-subdir --skip-license"
          sudo apt-get -y update
          sudo apt-get -y install mono-runtime mono-mcs
          sudo wget http://master.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list
          sudo sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key
          add -'
          sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
          sudo apt-get update && sudo apt-get -y --allow-unauthenticated install --reinstall d-apt-keyring && sudo apt-get update
          #sudo apt-get -y install dmd-bin dart
          sudo apt-get -y install dart
          wget http://haxe.org/website-content/downloads/3.4.2/downloads/haxe-3.4.2-linux64.tar.gz
          wget http://nekovm.org/media/neko-2.1.0-linux64.tar.gz
          tar xzf haxe-3.4.2-linux64.tar.gz
          tar xzf neko-2.1.0-linux64.tar.gz
          nvm install 8 || true
          nvm use 8 || true
          export HAXE_STD_PATH=$PWD/haxe-3.4.2/std
          export HAXELIB_PATH=$PWD/haxe-3.4.2/lib
          export LD_LIBRARY_PATH=$PWD/neko-2.1.0-linux64
          export NEKOPATH=$PWD/neko-2.1.0-linux64
          export HAXEPATH=$PWD/haxe-3.4.2
          export PATH=$HAXEPATH:$NEKOPATH:$PATH
          haxelib --quiet --always setup $HAXELIB_PATH
          haxelib --quiet --always install hxcpp > /dev/null
          ls -la $PWD
          ls -la $PWD/haxe-3.4.2
          g++ --version || true
          which java || true
          java -version || true
          which haxe || true
          haxe -version || true
          which neko || true
          neko -version || true
          which nvm || true
          nvm --version || true
          which node || true
          node --version || true
          #dmd --version || true
          "./gradlew --version"
    - name: Grant execute permission for gradlew
      run: chmod +x gradlew
    - name: Build with Gradle
      run: ./gradlew build
