Last active
March 25, 2024 15:55
-
-
Save osipxd/2ed1ee0878acddc399da2152b69ea7a2 to your computer and use it in GitHub Desktop.
Script preparing Android project cache for GitLab CI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu | |
BUILD_CACHE_THRESHOLD=5000 | |
function get_gradle_slug() { | |
local dist | |
dist=$(source gradle/wrapper/gradle-wrapper.properties && echo "${distributionUrl?:}") | |
dist=${dist##*gradle-} | |
echo "${dist%.zip}" | |
} | |
# Delete outdated Gradle wrappers | |
shopt -s extglob | |
gradle_slug=$(get_gradle_slug) | |
rm -rf .gradle/wrapper/dists/gradle-!("$gradle_slug") | |
# Delete dependencies lock file and plugin resolution | |
rm -f .gradle/caches/modules-2/modules-2.lock | |
rm -rf .gradle/caches/*/plugin-resolution/ | |
# Drop build cache if it contains too many files | |
build_cache_count=$(find .gradle/caches/build-cache-1/ -type f | wc -l) | |
if [[ $build_cache_count -gt $BUILD_CACHE_THRESHOLD ]]; then | |
echo "Build cache contains $build_cache_count files. Cleaning..." | |
rm -rf .gradle/caches/build-cache-1/ | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run it after your script in
.gitlab-ci.yml