name: CI

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  build:
    name: Build on JDK ${{ matrix.java }} and ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        java: [8, 11]
        os: [ubuntu-latest, windows-latest]

    steps:

    - uses: actions/checkout@v1

    - name: Set up JDK ${{ matrix.java }}
      uses: actions/setup-java@v1
      with:
        java-version: ${{ matrix.java }}

    - name: Cache dependencies
      uses: actions/cache@v1
      with:
        path: ~/.m2/repository
        key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
        restore-keys: |
          ${{ runner.os }}-maven

    - name: Build with Maven
      run: mvn -Pjacoco clean verify -B -V --no-transfer-progress ${{ matrix.flags }}

    - name: Codecov coverage
      uses: codecov/codecov-action@v1
      with:
        file: '*jacoco.xml'

    - name: Codacy coverage
      shell: bash
      env:
        CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
      run: |
        if [ "$CODACY_PROJECT_TOKEN" != "" ]; then
          bash <(curl -Ls https://coverage.codacy.com/get.sh) report -l Java -r integrations/target/site/jacoco-aggregate/jacoco.xml
        else
          echo "No secrets provided for codacy coverage report"
        fi
