name: Android CI

on:
  pull_request:
  push:
    branches:
    - 'main'
    - '4.**'
    - '5.**'

permissions:
  contents: read # to fetch code (actions/checkout)

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: set up JDK 11
      uses: actions/setup-java@v3
      with:
        distribution: temurin
        java-version: 11

    - name: Validate Gradle Wrapper
      uses: gradle/wrapper-validation-action@v1

    - name: Remove Android 31 (S)
      run: $ANDROID_HOME/tools/bin/sdkmanager --uninstall "platforms;android-31"

    - name: Build with Gradle
      run: ./gradlew qa

    - name: Archive reports for failed build
      if: ${{ failure() }}
      uses: actions/upload-artifact@v3
      with:
        name: reports
        path: '*/build/reports'
