name: Build Android APK
on:    
  pull_request:

jobs:
  build-android:
    runs-on: macos-15
    steps:
      - name: 🛒 Checkout
        uses: actions/checkout@v4

      - name: 🖥 Setup Node 20
        uses: actions/setup-node@v4
        with:
          node-version: 20
      
      - name: 💎 Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
            ruby-version: '3.0'  # Match your local Ruby version
            bundler-cache: true

      - name: 💬 Echo package.json version to Github ENV
        run: echo VERSION_NUMBER=$(node -p -e "require('./package.json').version") >> $GITHUB_ENV
        
      - name: 🤖 Run yarn init-android
        run: yarn install --network-concurrency 1
      
      - name: 🚀 Run fastlane build
        run: yarn fastlane:android:build


      - name: 📦 Upload APK for testing
        uses: actions/upload-artifact@v4
        if: always()
        with:
          name: jellify-android-pr-${{ github.event.number }}-${{ env.VERSION_NUMBER }}
          path: |
            android/app/build/outputs/apk/release/*.apk
          retention-days: 7
          if-no-files-found: warn
