name: Release Workflow on: workflow_dispatch: inputs: version_type: description: "Type of version bump (major, minor, patch, premajor, preminor, prepatch, prerelease)" required: true default: "patch" type: choice options: - major - minor - patch - premajor - preminor - prepatch - prerelease ios_only: description: "iOS only: skip version bump + Android, build TestFlight from current ref" required: false default: false type: boolean jobs: # Job 1: Version Bumping and Android Build build_android: if: ${{ !inputs.ios_only }} runs-on: ubuntu-latest permissions: contents: 'write' # Allows workflow to checkout repository code id-token: 'write' # Required for Google Cloud Workload Identity Federation authentication (OIDC token generation) env: # Declared here rather than in android/gradle.properties: llama.rn's own # android/gradle.properties sets rnllamaBuildFromSource, and a subproject's # value beats the root project's, so only an environment property or -P wins. ORG_GRADLE_PROJECT_rnllamaBuildFromSource: 'true' # From-source builds ignore llama.rn's downloaded jniLibs, and this job # builds no iOS target, so the postinstall download has nothing to supply. # The DSP libraries under bin/ are tarball content and arrive regardless. RNLLAMA_SKIP_POSTINSTALL: '1' steps: # Step 1: Checkout the code - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 # Important for git history ssh-key: ${{ secrets.DEPLOY_KEY }} # Must precede setup-java and setup-node: /opt/hostedtoolcache is where # those install. The Hexagon SDK adds ~3.1 GB on top of a from-source build. - name: Maximize build space run: | df -h / sudo rm -rf /usr/share/dotnet /opt/ghc /opt/hostedtoolcache df -h / # Step 2: Set up JDK 17 - name: Set up JDK 17 uses: actions/setup-java@v3 with: distribution: 'temurin' java-version: '17' # Step 3: Set up Node.js - name: Set up Node.js uses: actions/setup-node@v3 with: node-version: '22.21.0' # Use the specified Node.js version cache: 'yarn' # Step 4: Install dependencies using Yarn - name: Install dependencies run: yarn install # Step 4b: The manifest that the payload gate enforces also decides which # rnllama variants are worth compiling — one declaration, both uses. - name: Derive the rnllama variant allowlist from the payload manifest run: | set -euo pipefail VARIANTS=$(node scripts/verify-android-payload.js --print-variants) echo "Declared allowlist: $VARIANTS" echo "ORG_GRADLE_PROJECT_rnllamaVariants=$VARIANTS" >> "$GITHUB_ENV" # Step 4c: The Hexagon SDK is what decides whether the NPU backend is # compiled in at all. Without it the build succeeds and ships without it. - name: Set up the Hexagon SDK uses: ./.github/actions/setup-hexagon-sdk # No ccache on the release path, deliberately. Its key is the commit # SHA, and a release builds a fresh version-bump commit, so the only way # it could ever hit is the `ccache-android-` prefix restore — which would # link objects of unreviewed provenance into the artifact that ships. # Keeping it would cost the shipped binary's provenance to save build # minutes on the least frequent workflow we run. # Step 5: Set up Ruby and Bundler - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: '3.2.3' # Specify a Ruby version bundler-cache: true # Step 6: Combined version bump - name: Bump versions working-directory: ${{ github.workspace }} run: bundle exec fastlane bump_version version_type:${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version_type || 'patch' }} # Step 7: Commit and push version changes - name: Commit and push version changes run: | VERSION=$(cat .version) echo "VERSION=$VERSION" >> $GITHUB_ENV git config user.name "GitHub Actions" git config user.email "actions@github.com" git add .version package.json android/app/build.gradle ios/PocketPal.xcodeproj/project.pbxproj git commit -m "chore(release): bump version to $VERSION" git push # Created here so it points at the bump commit, but pushed only once # the payload check has passed — see "Push the release tag" below. git tag "v$VERSION" # Step 8: Set up Android Keystore - name: Set up Android Keystore working-directory: android run: | echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 --decode > app/pocketpal-release-key.keystore # Step 9: Authenticate to Google Cloud - name: Authenticate to Google Cloud id: auth uses: google-github-actions/auth@v2 with: service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} create_credentials_file: true # Add this step before the Android build - name: Create .env file run: | cat > .env << 'EOL' FIREBASE_FUNCTIONS_URL=${{ vars.FIREBASE_FUNCTIONS_URL }} # PalsHub/Supabase Configuration SUPABASE_URL=${{ vars.SUPABASE_URL }} SUPABASE_ANON_KEY=${{ secrets.SUPABASE_ANON_KEY }} PALSHUB_API_BASE_URL=${{ vars.PALSHUB_API_BASE_URL }} # App Configuration APP_URL=pocketpal://app # Feature Flags (true/false) ENABLE_PALSHUB_INTEGRATION=true ENABLE_AUTHENTICATION=true ENABLE_OFFLINE_MODE=true # Google Sign-In Configuration GOOGLE_IOS_CLIENT_ID=${{ vars.GOOGLE_IOS_CLIENT_ID }} GOOGLE_WEB_CLIENT_ID=${{ vars.GOOGLE_WEB_CLIENT_ID }} EOL # Step 10a: Build the Android APK and Bundle. Building and uploading are # separate steps so the payload check below sits between them in the # workflow graph and the upload cannot outrun it. - name: Build Android app working-directory: android env: KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }} KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }} KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }} GRADLE_USER_HOME: ${{ runner.temp }}/.gradle GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }} run: | set -euo pipefail # Compared against "true" rather than merely checked for emptiness: # the payload gate cannot tell the modes apart (upstream's prebuilt # exports the same symbols), so this guard is the only thing holding # the declaration. if [ "${ORG_GRADLE_PROJECT_rnllamaBuildFromSource:-}" != "true" ]; then echo "::error::ORG_GRADLE_PROJECT_rnllamaBuildFromSource is '${ORG_GRADLE_PROJECT_rnllamaBuildFromSource:-}', expected 'true'. Building from prebuilts is the documented escape hatch, but it must be a deliberate edit to this workflow." exit 1 fi bundle exec fastlane build_android_release 2>&1 | tee android-build.log # COUPLING: the string grepped for below is upstream's, printed by # node_modules/llama.rn/android/build.gradle next to its rnllamaVariants # lookup. A llama.rn upgrade that rewords it fails this step. That is the # intended direction — it is the only live proof the environment reaches # gradle — but the fix is to update the literal, not to delete the check. - name: Verify the variant allowlist reached the llama.rn build run: | set -euo pipefail VARIANTS=$(node scripts/verify-android-payload.js --print-variants) if ! grep -qF "Building rnllama variants: $VARIANTS" android/android-build.log; then echo "::error::llama.rn did not report building the declared variant set." echo "Expected: $VARIANTS" echo "In the build log:" grep -F "rnllama variants" android/android-build.log || echo " (no such line at all)" echo "" echo "Two different causes look identical here. Either ORG_GRADLE_PROJECT_rnllamaVariants" echo "did not reach the llama.rn subproject, or upstream changed the wording of the line" echo "this step greps for (android/build.gradle, the println next to rnllamaVariants)." echo "Check the wording first — a llama.rn upgrade is the more common reason." exit 1 fi echo "OK: llama.rn reported the declared variant list (extras, if any, are permitted and are reported by the payload check)." # Step 10b: Both shipped forms are checked — the APK goes to the GitHub # Release, the AAB goes to Play, and they are packaged separately. - name: Verify the Android payload run: | node scripts/verify-android-payload.js \ --apk android/app/build/outputs/apk/prod/release/app-prod-release.apk \ --aab android/app/build/outputs/bundle/prodRelease/app-prod-release.aab \ --report payload-report.txt - name: Upload payload report if: always() uses: actions/upload-artifact@v4 with: name: payload-report path: payload-report.txt if-no-files-found: ignore # Step 10c: Upload the checked bundle to the Alpha track - name: Upload Android app to Alpha track working-directory: android env: # GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.auth.outputs.credentials_file_path }} # This is not supported by fastlane, we need to replace it with PLAY_STORE_JSON_KEY in the future. PLAY_STORE_JSON_KEY: ${{ secrets.PLAY_STORE_SERVICE_ACCOUNT_JSON }} run: | set -euo pipefail echo "$PLAY_STORE_JSON_KEY" > play-store-key.json bundle exec fastlane upload_android_alpha # Step 10d: A failed payload check now leaves no release tag on the # remote, so a re-run does not have to reuse or delete one. - name: Push the release tag run: git push origin "v$VERSION" # Step 11: Create GitHub Release with APK - name: Create GitHub Release uses: softprops/action-gh-release@v1 with: files: android/app/build/outputs/apk/prod/release/app-prod-release.apk tag_name: "v${{ env.VERSION }}" name: "Release v${{ env.VERSION }}" draft: false prerelease: false generate_release_notes: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Job 2: iOS Build and Upload (runs on macOS) build_ios: runs-on: macos-26 # macOS 26 includes an iOS 26-capable Xcode toolchain needs: build_android if: ${{ always() && (needs.build_android.result == 'success' || needs.build_android.result == 'skipped') }} env: NODE_OPTIONS: '--max-old-space-size=8192' steps: - name: Checkout code uses: actions/checkout@v4 with: ref: ${{ github.ref }} # This ensures we get the latest changes including the version bump fetch-depth: 0 # Step 1: Select the default Xcode shipped on macOS 26. # App Store Connect now requires uploads built with the iOS 26 SDK or later. - name: Setup Xcode run: | sudo xcode-select -s /Applications/Xcode.app xcodebuild -version - name: Ensure Metal toolchain run: | xcrun -sdk iphoneos metal -v || xcodebuild -downloadComponent MetalToolchain xcrun -sdk iphonesimulator metal -v # Step 2: Set up Node.js - name: Set up Node.js uses: actions/setup-node@v3 with: node-version: '22.21.0' cache: 'yarn' # Step 3: Install dependencies using Yarn - name: Install dependencies run: yarn install # Step 4: Set up Ruby and Bundler - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: '3.2.3' # Specify a Ruby version bundler-cache: true # Step 5: Install CocoaPods dependencies - name: Install CocoaPods dependencies working-directory: ios run: pod install # Step 6: Create Env.xcconfig - name: Create Env.xcconfig run: | cat > ios/Config/Env.xcconfig << 'EOL' // This file contains environment-specific build settings. GOOGLE_WEB_CLIENT_ID = ${{ vars.GOOGLE_WEB_CLIENT_ID }} REVERSED_GOOGLE_IOS_CLIENT_ID = ${{ vars.REVERSED_GOOGLE_IOS_CLIENT_ID }} EOL # Step 7: Create .env file - name: Create .env file run: | cat > .env << 'EOL' FIREBASE_FUNCTIONS_URL=${{ vars.FIREBASE_FUNCTIONS_URL }} # PalsHub/Supabase Configuration SUPABASE_URL=${{ vars.SUPABASE_URL }} SUPABASE_ANON_KEY=${{ secrets.SUPABASE_ANON_KEY }} PALSHUB_API_BASE_URL=${{ vars.PALSHUB_API_BASE_URL }} # App Configuration APP_URL=pocketpal://app # Feature Flags (true/false) ENABLE_PALSHUB_INTEGRATION=true ENABLE_AUTHENTICATION=true ENABLE_OFFLINE_MODE=true # Google Sign-In Configuration GOOGLE_IOS_CLIENT_ID=${{ vars.GOOGLE_IOS_CLIENT_ID }} GOOGLE_WEB_CLIENT_ID=${{ vars.GOOGLE_WEB_CLIENT_ID }} EOL # Step 8: Build and upload iOS app to TestFlight - name: Build and upload iOS app working-directory: ios env: MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }} MATCH_GIT_URL: ${{ secrets.MATCH_GIT_URL }} MATCH_GITHUB_TOKEN: ${{ secrets.MATCH_GITHUB_TOKEN }} APP_STORE_CONNECT_API_KEY_ID: ${{ secrets.APP_STORE_CONNECT_API_KEY_ID }} APP_STORE_CONNECT_API_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_API_ISSUER_ID }} APP_STORE_CONNECT_API_KEY_CONTENT: ${{ secrets.APP_STORE_CONNECT_API_KEY_CONTENT }} APP_STORE_CONNECT_USER_ID: ${{ secrets.APP_STORE_CONNECT_USER_ID }} GOOGLE_SERVICES_PLIST: ${{ secrets.GOOGLE_SERVICES_PLIST }} run: bundle exec fastlane release_ios_testflight # Step 9: Extract iOS version info for dSYM artifact naming - name: Extract iOS version info id: version if: always() run: | MARKETING_VERSION=$(cat .version | tr -d '[:space:]') BUILD_NUMBER=$(grep -m1 'CURRENT_PROJECT_VERSION' ios/PocketPal.xcodeproj/project.pbxproj | awk -F'= ' '{print $2}' | tr -d ' ;') echo "marketing_version=${MARKETING_VERSION}" >> "$GITHUB_OUTPUT" echo "build_number=${BUILD_NUMBER}" >> "$GITHUB_OUTPUT" echo "Extracted: v${MARKETING_VERSION} build ${BUILD_NUMBER}" # Step 10: Retain dSYM as a workflow artifact for crash symbolication (FOU-86) - name: Upload iOS dSYM if: always() uses: actions/upload-artifact@v4 with: name: ios-dsym-v${{ steps.version.outputs.marketing_version }}-build${{ steps.version.outputs.build_number }} path: ios/build/PocketPal.app.dSYM.zip retention-days: 90 if-no-files-found: warn