name: Build

on:
  push:
  pull_request:

jobs:
  lint:
    name: Lint
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Validate Gradle Wrapper
        uses: gradle/actions/wrapper-validation@v3
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          java-version: 17
          distribution: temurin
      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v3
      - name: Build with Gradle
        run: ./gradlew lintDebug ktlintCheck
  assemble:
    name: Assemble
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Validate Gradle Wrapper
        uses: gradle/actions/wrapper-validation@v3
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          java-version: 17
          distribution: temurin
      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v3
      - name: Build with Gradle
        run: ./gradlew assembleDebug
        # Upload all build artifacts in separate steps. This can be shortened once https://github.com/actions/upload-artifact/pull/354 is merged.
      - name: Upload artifact phone-libre-arm64-v8a-debug.apk
        uses: actions/upload-artifact@v4
        with:
          name: phone-libre-arm64-v8a-debug.apk
          path: ./app/phone/build/outputs/apk/libre/debug/phone-libre-arm64-v8a-debug.apk
      - name: Upload artifact phone-libre-armeabi-v7a-debug.apk
        uses: actions/upload-artifact@v4
        with:
          name: phone-libre-armeabi-v7a-debug.apk
          path: ./app/phone/build/outputs/apk/libre/debug/phone-libre-armeabi-v7a-debug.apk
      - name: Upload artifact phone-libre-x86_64-debug.apk
        uses: actions/upload-artifact@v4
        with:
          name: phone-libre-x86_64-debug.apk
          path: ./app/phone/build/outputs/apk/libre/debug/phone-libre-x86_64-debug.apk
      - name: Upload artifact phone-libre-x86-debug.apk
        uses: actions/upload-artifact@v4
        with:
          name: phone-libre-x86-debug.apk
          path: ./app/phone/build/outputs/apk/libre/debug/phone-libre-x86-debug.apk
      - name: Upload artifact tv-libre-arm64-v8a-debug.apk
        uses: actions/upload-artifact@v4
        with:
          name: tv-libre-arm64-v8a-debug.apk
          path: ./app/tv/build/outputs/apk/libre/debug/tv-libre-arm64-v8a-debug.apk
      - name: Upload artifact tv-libre-armeabi-v7a-debug.apk
        uses: actions/upload-artifact@v4
        with:
          name: tv-libre-armeabi-v7a-debug.apk
          path: ./app/tv/build/outputs/apk/libre/debug/tv-libre-armeabi-v7a-debug.apk
      - name: Upload artifact tv-libre-x86_64-debug.apk
        uses: actions/upload-artifact@v4
        with:
          name: tv-libre-x86_64-debug.apk
          path: ./app/tv/build/outputs/apk/libre/debug/tv-libre-x86_64-debug.apk
      - name: Upload artifact tv-libre-x86-debug.apk
        uses: actions/upload-artifact@v4
        with:
          name: tv-libre-x86-debug.apk
          path: ./app/tv/build/outputs/apk/libre/debug/tv-libre-x86-debug.apk
