@@ -98,35 +98,78 @@ jobs:
9898 exit 1
9999 fi
100100
101- - name : Check and restore cached APKs if Fingerprint is found
101+ - name : Restore APKs matching fingerprint from branch cache
102102 id : apk-cache-restore
103+ # This action automatically updates the cache at the end of the workflow
103104 uses : cirruslabs/cache@bba69c6578b863ad0398ad40567bd2ef70290fe0 # v4
104105 with :
105106 path : |
106107 ${{ steps.determine-target-paths.outputs.apk-target-path }}/${{ steps.determine-target-paths.outputs.artifact_name }}.apk
107108 ${{ steps.determine-target-paths.outputs.test-apk-target-path }}/${{ steps.determine-target-paths.outputs.artifact_name }}-androidTest.apk
108109 # Include Gradle properties in key to force rebuild when properties change
109110 # Keep the `hashFiles` call for Gradle config in-sync with these steps:
110- # - "Cache Gradle dependencies"
111- # - "Cache build artifacts"
112- key : android-apk-${{ inputs.build_type }}-${{ env.CACHE_GENERATION }}-${{ steps.generate-fingerprint.outputs.fingerprint }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
111+ # - "Restore APKs matching fingerprint from branch cache"
112+ # - "Restore APKs matching fingerprint from main cache"
113+ # - "Restore Gradle dependencies from branch cache"
114+ # - "Restore Gradle dependencies from main cache"
115+ key : android-apk-${{ github.ref_name }}-${{ inputs.build_type }}-${{ env.CACHE_GENERATION }}-${{ steps.generate-fingerprint.outputs.fingerprint }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
113116
114- - name : Cache Gradle dependencies
117+ - name : Restore APKs matching fingerprint from main cache
118+ if : ${{ steps.apk-cache-restore.outputs.cache-hit != 'true' && github.ref_name != 'main' }}
119+ id : apk-cache-restore-main
120+ # This will only restore the cache, not update it
121+ uses : cirruslabs/cache/restore@bba69c6578b863ad0398ad40567bd2ef70290fe0 # v4
122+ with :
123+ path : |
124+ ${{ steps.determine-target-paths.outputs.apk-target-path }}/${{ steps.determine-target-paths.outputs.artifact_name }}.apk
125+ ${{ steps.determine-target-paths.outputs.test-apk-target-path }}/${{ steps.determine-target-paths.outputs.artifact_name }}-androidTest.apk
126+ # Include Gradle properties in key to force rebuild when properties change
127+ # Keep the `hashFiles` call for Gradle config in-sync with these steps:
128+ # - "Restore APKs matching fingerprint from branch cache"
129+ # - "Restore APKs matching fingerprint from main cache"
130+ # - "Restore Gradle dependencies from branch cache"
131+ # - "Restore Gradle dependencies from main cache"
132+ key : android-apk-main-${{ inputs.build_type }}-${{ env.CACHE_GENERATION }}-${{ steps.generate-fingerprint.outputs.fingerprint }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
133+
134+ - name : Restore Gradle dependencies from branch cache
135+ id : gradle-cache-restore
136+ # This action automatically updates the cache at the end of the workflow
115137 uses : cirruslabs/cache@bba69c6578b863ad0398ad40567bd2ef70290fe0 # v4
116- if : ${{ steps.apk-cache-restore.outputs.cache-hit != 'true' }}
138+ if : ${{ steps.apk-cache-restore.outputs.cache-hit != 'true' && steps.apk-cache-restore-main.outputs.cache-hit != 'true' }}
139+ env :
140+ GRADLE_CACHE_VERSION : 1
141+ with :
142+ path : |
143+ ~/_work/.gradle/caches
144+ ~/_work/.gradle/wrapper
145+ # Include Gradle properties in key to force rebuild when properties change
146+ # Keep the `hashFiles` call for Gradle config in-sync with these steps:
147+ # - "Restore APKs matching fingerprint from branch cache"
148+ # - "Restore APKs matching fingerprint from main cache"
149+ # - "Restore Gradle dependencies from branch cache"
150+ # - "Restore Gradle dependencies from main cache"
151+ key : gradle-${{ github.ref_name }}-${{ env.GRADLE_CACHE_VERSION }}-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
152+
153+ - name : Restore Gradle dependencies from main cache
154+ # This will only restore the cache, not update it
155+ uses : cirruslabs/cache/restore@bba69c6578b863ad0398ad40567bd2ef70290fe0 # v4
156+ if : ${{ steps.apk-cache-restore.outputs.cache-hit != 'true' && steps.apk-cache-restore-main.outputs.cache-hit != 'true' && steps.gradle-cache-restore.outputs.cache-hit != 'true' && github.ref_name != 'main' }}
117157 env :
118158 GRADLE_CACHE_VERSION : 1
119159 with :
120160 path : |
121161 ~/_work/.gradle/caches
122162 ~/_work/.gradle/wrapper
163+ # Include Gradle properties in key to force rebuild when properties change
123164 # Keep the `hashFiles` call for Gradle config in-sync with these steps:
124- # - "Check and restore cached APKs if Fingerprint is found"
125- # - "Cache build artifacts"
126- key : gradle-${{ env.GRADLE_CACHE_VERSION }}-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
165+ # - "Restore APKs matching fingerprint from branch cache"
166+ # - "Restore APKs matching fingerprint from main cache"
167+ # - "Restore Gradle dependencies from branch cache"
168+ # - "Restore Gradle dependencies from main cache"
169+ key : gradle-main-${{ env.GRADLE_CACHE_VERSION }}-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
127170
128171 - name : Build Android E2E APKs
129- if : ${{ steps.apk-cache-restore.outputs.cache-hit != 'true' }}
172+ if : ${{ steps.apk-cache-restore.outputs.cache-hit != 'true' && steps.apk-cache-restore-main.outputs.cache-hit != 'true' }}
130173 run : |
131174 echo "🏗 Building Android E2E APKs..."
132175 export NODE_OPTIONS="--max-old-space-size=4096"
@@ -179,7 +222,7 @@ jobs:
179222 MM_PREDICT_GTM_MODAL_ENABLED : ' false'
180223
181224 - name : Repack APK with JS updates using @expo/repack-app
182- if : ${{ steps.apk-cache-restore.outputs.cache-hit == 'true' }}
225+ if : ${{ steps.apk-cache-restore.outputs.cache-hit == 'true' || steps.apk-cache-restore-main.outputs.cache-hit == 'true' }}
183226 run : |
184227 echo "📦 Repacking APK with updated JavaScript bundle using @expo/repack-app..."
185228 # Use the optimized repack script which uses @expo/repack-app
@@ -228,19 +271,6 @@ jobs:
228271 GOOGLE_SERVICES_B64_ANDROID : ${{ secrets.GOOGLE_SERVICES_B64_ANDROID }}
229272 MM_INFURA_PROJECT_ID : ${{ secrets.MM_INFURA_PROJECT_ID }}
230273
231- # Cache build artifacts with the pre-build fingerprint
232- - name : Cache build artifacts
233- if : ${{ steps.apk-cache-restore.outputs.cache-hit != 'true' }}
234- uses : cirruslabs/cache@bba69c6578b863ad0398ad40567bd2ef70290fe0 # v4
235- with :
236- path : |
237- ${{ steps.determine-target-paths.outputs.apk-target-path }}/${{ steps.determine-target-paths.outputs.artifact_name }}.apk
238- ${{ steps.determine-target-paths.outputs.test-apk-target-path }}/${{ steps.determine-target-paths.outputs.artifact_name }}-androidTest.apk
239- # Keep the `hashFiles` call for Gradle config in-sync with these steps:
240- # - "Check and restore cached APKs if Fingerprint is found"
241- # - "Cache Gradle dependencies"
242- key : android-apk-${{ inputs.build_type }}-${{ env.CACHE_GENERATION }}-${{ steps.generate-fingerprint.outputs.fingerprint }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
243-
244274 - name : Upload Android APK
245275 id : upload-apk
246276 uses : actions/upload-artifact@v4
0 commit comments