name: Build AAB — WhatSMS Gateway

on:
  push:
    branches:
      - feat/whatsms-branding-ptpt
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: mingc/android-build-box:latest
      options: --network host

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Configurar JDK 17
        run: |
          export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
          echo "JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64" >> $GITHUB_ENV
          echo "/usr/lib/jvm/java-17-openjdk-amd64/bin" >> $GITHUB_PATH
          java -version

      - name: Injectar google-services.json
        run: echo '${{ secrets.GOOGLE_SERVICES_JSON }}' > app/google-services.json

      - name: Decode keystore
        run: echo '${{ secrets.KEYSTORE_BASE64 }}' | base64 -d > app/keystore.jks

      - name: Build AAB release
        env:
          SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
          SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
          SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
          JAVA_HOME: /usr/lib/jvm/java-17-openjdk-amd64
        run: |
          chmod +x gradlew
          ./gradlew bundleRelease --no-daemon --stacktrace

      - name: Upload AAB
        uses: actions/upload-artifact@v3
        with:
          name: whatsms-gateway-v3.2.0-release-aab
          path: app/build/outputs/bundle/release/*.aab
          retention-days: 30
