# name: RN APK Build

# on:
#   push:
#     branches:
#       - main

# jobs:
#   build:
#     runs-on: ubuntu-latest   

#     steps:
#       - name: Checkout code
#         uses: actions/checkout@v4

#       # ---------------- NODE ----------------
#       - name: Setup Node
#         uses: actions/setup-node@v4
#         with:
#           node-version: 20
#           cache: npm

#       - name: Install dependencies
#         run: npm ci

#       # ---------------- JAVA ----------------
#       - name: Setup Java
#         uses: actions/setup-java@v4
#         with:
#           distribution: temurin
#           java-version: 17
#           cache: gradle

#       # ---------------- ANDROID ----------------
#       - name: Setup Android SDK
#         uses: android-actions/setup-android@v3

#       - name: Grant permission
#         run: chmod +x android/gradlew

#       # ---------------- BUILD APK ----------------
#       - name: Build Release APK
#         run: |
#           cd android
#           ./gradlew assembleRelease --stacktrace --info

#       # ---------------- VERIFY APK ----------------
#       - name: Check APK Output
#         run: ls -R android/app/build/outputs/apk

#       # ---------------- SAVE TO VM ----------------
#       - name: Save APK to VM folder
#         run: |
#           mkdir -p /home/pgadmin1/builds
#           cp android/app/build/outputs/apk/release/app-release.apk /home/pgadmin1/builds/app-release.apk

#       # ---------------- UPLOAD ARTIFACT ----------------
#       - name: Upload APK
#         uses: actions/upload-artifact@v3
#         with:
#           name: app-release
#           path: android/app/build/outputs/apk/release/app-release.apk




name: RN APK Build

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest   # ye same rahega (host mapping runner config me hai)

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      # ---------------- NODE ----------------
      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm

      - name: Install dependencies
        run: npm ci

      # ---------------- JAVA ----------------
      - name: Setup Java
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 17

      # ---------------- ANDROID ----------------
      - name: Setup Android SDK
        uses: android-actions/setup-android@v3

      - name: Grant permission
        run: chmod +x android/gradlew

      # ---------------- BUILD APK ----------------
      - name: Build Release APK
        run: |
          cd android
          ./gradlew assembleRelease --stacktrace --info

      # ---------------- VERIFY APK ----------------
      - name: Check APK Output
        run: |
          ls -R android/app/build/outputs/apk

      # ---------------- SAVE TO VM ----------------
      - name: Save APK to VM folder
        run: |
          mkdir -p /home/pgadmin1/builds
          cp android/app/build/outputs/apk/release/*.apk /home/pgadmin1/builds/

      # ---------------- VERIFY FINAL ----------------
      - name: Verify APK in VM
        run: |
          ls -l /home/pgadmin1/builds

      # ---------------- (OPTIONAL) ARTIFACT ----------------
      - name: Upload APK (optional)
        uses: actions/upload-artifact@v3
        with:
          name: app-release
          path: android/app/build/outputs/apk/release/*.apk