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 11
        uses: actions/setup-java@v3
        with:
          java-version: 11
          distribution: 'adopt'
          cache: gradle
        
      - name: Change wrapper permissions
        run: chmod +x ./gradlew
        
      - name: Run tests
        run: ./gradlew test

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

      - name: Build apk fdroid-debug
        run: ./gradlew app:assembleFdroidDebug

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

      - name: Upload apk fdroid-debug
        uses: actions/upload-artifact@v3
        with:
          name: FoxMmm-fdroid-debug
          path: app/build/outputs/apk/fdroid/debug/app-fdroid-debug.apk
