# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: "Assemble"

on:
  pull_request:
    branches: [ master, stable-* ]

# Declare default permissions as read only.
permissions: read-all

concurrency:
  group: assemble-flavors-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  flavor:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        flavor: [ Generic, Gplay ]
    steps:
      - name: Checkout
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          persist-credentials: false

      - name: set up JDK 17
        uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
        with:
          distribution: "temurin"
          java-version: 17

      - name: Gradle validate
        uses: gradle/actions/wrapper-validation@4d9f0ba0025fe599b4ebab900eb7f3a1d93ef4c2 # v5.0.0

      - name: Build ${{ matrix.flavor }}
        run: |
          echo "org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8" >> gradle.properties
          ./gradlew --no-daemon assemble${{ matrix.flavor }}

      - name: Archive apk
        uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
        if: ${{ always() }}
        with:
          name: Nextcloud-${{ matrix.flavor }}-APK
          path: app/build/outputs/apk/**/**/*.apk
          retention-days: 5
