name: Build iOS IPA
on:    
  pull_request:

jobs:
  build-ios:
    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: 💬 Echo package.json version to Github ENV
        run: echo VERSION_NUMBER=$(node -p -e "require('./package.json').version") >> $GITHUB_ENV
        
      - name: 🍎 Run yarn init-ios:new-arch
        run: yarn init-ios:new-arch
      
      - name: 🚀 Run fastlane build
        run: yarn fastlane:ios:build
        env:
          # FASTLANE_PASSWORD: ${{ secrets.FASTLANE_PASSWORD }}
          APPSTORE_CONNECT_API_KEY_JSON: ${{ secrets.APPSTORE_CONNECT_API_KEY_JSON }}
          FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD: ${{ secrets.FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD }}
          MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
          MATCH_REPO_PAT: "anultravioletaurora:${{ secrets.SIGNING_REPO_PAT }}"


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