name: Android
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]
  schedule:
    - cron:  '5 12 * * 0'

jobs:
  build:
    name: ${{ matrix.type }}-build
    runs-on: ubuntu-latest
    strategy:
      matrix:
        type: [manager]
      fail-fast: false
    steps:
      - uses: actions/checkout@v2

      - name: Set up JDK 1.9
        uses: actions/setup-java@v1
        with:
          java-version: 1.9

      - name: Setup Android SDK
        uses: android-actions/setup-android@v2

      - name: Cache dependencies
        uses: actions/cache@v2.1.3
        with:
          path: 3rdParty/buildCache
          key: android-${{ matrix.type }}-${{ hashFiles('android/*.sh') }}
          restore-keys: android-${{ matrix.type }}-

      - name: Build
        run:  |
          ./android/ci_build_all.sh
          bash <(curl -s https://codecov.io/bash)

      - name: Deploy to BinTray
        if: ${{ success() }}
        env:
          BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }}
          PULL_REQUEST: ${{ github.event.number }}
          PULL_REQUEST_SHA: ${{ github.event.pull_request.head.sha }}
        run: ./deploy/prepare_deployment.sh android_${{ matrix.type }} && ./deploy/deploy_to_bintray.sh deploy/android_${{ matrix.type }}/
