#file: noinspection SpellCheckingInspection
name: Generate APK Debug

on:
  push:
    branches:
      - '*'
    paths-ignore:
      - '**.md'
  pull_request:
    branches:
      - '*'
    paths-ignore:
      - '**.md'
  workflow_dispatch:

jobs:
  build:

    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    steps:
      - name: Check out repository
        uses: actions/checkout@v3
        with:
          submodules: true

      - name: Set up Java 19
        uses: actions/setup-java@v3
        with:
          java-version: 19
          distribution: 'temurin'

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

      - name: Setup Gradle
        uses: gradle/gradle-build-action@v2
        with:
          gradle-home-cache-includes: |
            caches
            notifications
            jdks

      - name: Change wrapper permissions
        run: chmod +x ./gradlew

      # temporary disabled
      # - name: Run tests
      #  run: ./gradlew test

      - name: Build apk debug
        run: ./gradlew app:assembleDefaultDebug

      # will not upload, just build to check if it builds
      - name: Build apk fdroid-debug
        run: ./gradlew app:assembleFdroidDebug

      # UPLOAD ARTIFACT SECTION
      # Will be shorter, when https://github.com/actions/upload-artifact/pull/354 will be merged
      # FoxMMM-default-debug
      - name: Upload FoxMMM-default-arm64-v8a-debug
        uses: actions/upload-artifact@v3
        with:
          name: FoxMMM-default-arm64-v8a-debug
          path: app/build/outputs/apk/default/debug/*-default-arm64-v8a-debug.apk

      - name: Upload FoxMMM-default-armeabi-v7a-debug
        uses: actions/upload-artifact@v3
        with:
          name: FoxMMM-default-armeabi-v7a-debug
          path: app/build/outputs/apk/default/debug/*-default-armeabi-v7a-debug.apk

      - name: Upload FoxMMM-default-universal-debug
        uses: actions/upload-artifact@v3
        with:
          name: FoxMMM-default-universal-debug
          path: app/build/outputs/apk/default/debug/*-default-universal-debug.apk

      - name: Upload FoxMMM-default-x86-debug
        uses: actions/upload-artifact@v3
        with:
          name: FoxMMM-default-x86-debug
          path: app/build/outputs/apk/default/debug/*-default-x86-debug.apk

      - name: Upload FoxMMM-default-x86_64-debug
        uses: actions/upload-artifact@v3
        with:
          name: FoxMMM-default-x86_64-debug
          path: app/build/outputs/apk/default/debug/*-default-x86_64-debug.apk
