Skip to content

Commit cd861b6

Browse files
committed
Refactored Semaphore CI caching strategy and separated checksums
1 parent 0c7473d commit cd861b6

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

.semaphore/semaphore.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,22 @@ global_job_config:
4646
- sudo rm -rf ~/.rbenv ~/.phpbrew
4747
- checkout
4848
# init environment variables
49-
- export SUM=$(checksum build.gradle.kts)-$(checksum FlowCrypt/build.gradle.kts)-$(checksum ./script/ci-install-android-sdk.sh)
50-
- export APP_GRADLE_CACHE=gradle-cache-$SUM # per conf files hash
51-
- export ANDROID_SDK_CACHE=android-sdk-$SUM # per conf files hash
52-
- export BUILD_CXX_CACHE=build-cxx-cache-$SEMAPHORE_GIT_BRANCH-$SUM # per branch and conf files hash
53-
- export BUILD_NATIVE_CACHE=build-native-cache-$SEMAPHORE_GIT_BRANCH-$SUM # per branch and conf files hash
54-
- export BUILD_CACHE=build-cache-$SEMAPHORE_GIT_BRANCH-$SUM # per branch and conf files hash
49+
- export GRADLE_SUM=$(checksum build.gradle.kts)-$(checksum FlowCrypt/build.gradle.kts)
50+
- export SDK_SUM=$(checksum ./script/ci-install-android-sdk.sh)
51+
- export APP_GRADLE_CACHE=project-gradle-cache-$GRADLE_SUM # project .gradle cache, per Gradle config hash
52+
- export ANDROID_SDK_CACHE=android-sdk-$SDK_SUM # Android SDK cache, per SDK installer hash
53+
- export BUILD_CXX_CACHE=build-cxx-cache-$SEMAPHORE_GIT_BRANCH-$GRADLE_SUM # per branch and Gradle config hash
54+
- export BUILD_NATIVE_CACHE=build-native-cache-$SEMAPHORE_GIT_BRANCH-$GRADLE_SUM # per branch and Gradle config hash
5555
# restore app caches
5656
- cache restore $APP_GRADLE_CACHE
5757
- cache restore $BUILD_CXX_CACHE
5858
- cache restore $BUILD_NATIVE_CACHE
59-
- cache restore $BUILD_CACHE
6059
# restore global caches
6160
- cache restore $ANDROID_SDK_CACHE
6261
- cache restore gradle-wrapper
62+
- cache restore gradle-cache-$GRADLE_SUM
6363
- cache restore gradle-cache
64+
- cache restore android-build-cache-$GRADLE_SUM
6465
- cache restore android-build-cache
6566
# Install Android dependencies if needed
6667
- ./script/ci-install-android-sdk.sh
@@ -88,18 +89,14 @@ blocks:
8889
- cache has_key $APP_GRADLE_CACHE || cache store $APP_GRADLE_CACHE .gradle
8990
- cache has_key $BUILD_CXX_CACHE || cache store $BUILD_CXX_CACHE FlowCrypt/.cxx
9091
- cache has_key $BUILD_NATIVE_CACHE || cache store $BUILD_NATIVE_CACHE FlowCrypt/.externalNativeBuild
91-
- cache has_key $BUILD_CACHE || cache store $BUILD_CACHE FlowCrypt/build
9292

9393
# clean and store global cache
9494
- echo "Store the global cache"
9595
- find ~/.gradle/caches/ -name "*.lock" -type f -delete # https://medium.com/cirruslabs/mastering-gradle-caching-and-incremental-builds-37eb1af7fcde
9696
- cache has_key $ANDROID_SDK_CACHE || cache store $ANDROID_SDK_CACHE $ANDROID_HOME
97-
- cache delete gradle-wrapper
98-
- cache delete gradle-cache
99-
- cache delete android-build-cache
100-
- cache store gradle-wrapper ~/.gradle/wrapper
101-
- cache store gradle-cache ~/.gradle/caches
102-
- cache store android-build-cache ~/.android/build-cache
97+
- cache has_key gradle-wrapper || cache store gradle-wrapper ~/.gradle/wrapper
98+
- cache has_key gradle-cache-$GRADLE_SUM || cache store gradle-cache-$GRADLE_SUM ~/.gradle/caches
99+
- cache has_key android-build-cache-$GRADLE_SUM || cache store android-build-cache-$GRADLE_SUM ~/.android/build-cache
103100

104101
- name: 'Testing'
105102
task:

0 commit comments

Comments
 (0)