Skip to content

Commit 64c1b2d

Browse files
committed
ci: fix homebrew cache logic for macos
Signed-off-by: IonutMuthi <[email protected]>
1 parent e91e363 commit 64c1b2d

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

ci/macOS/install_macos_deps.sh

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,38 @@ cleanup_old_caches() {
3737
}
3838

3939
setup_homebrew_cache() {
40-
if [ "${CACHING_ENABLED}" = "true" ]; then
40+
if [ "${CACHING_ENABLED}" == "true" ]; then
4141
echo "Setting up Homebrew cache..."
42-
mkdir -p "$HOMEBREW_CACHE_DIR"
42+
mkdir -p "$HOMEBREW_CACHE_DIR"
43+
44+
if [ "${HOMEBREW_PACKAGES_CACHE}" == "true" ]; then
45+
echo "Homebrew cache found, restoring cached packages"
46+
# Validate cache isn't corrupted
47+
if [ -d "$HOMEBREW_CACHE_DIR" ] && [ "$(ls -A $HOMEBREW_CACHE_DIR 2>/dev/null)" ]; then
48+
echo "Found cached Homebrew packages in $HOMEBREW_CACHE_DIR"
49+
export HOMEBREW_CACHE_ENABLED=true
50+
export HOMEBREW_NO_AUTO_UPDATE=1
51+
else
52+
echo "Homebrew cache directory empty or corrupted - clearing and rebuilding"
53+
rm -rf "$HOMEBREW_CACHE_DIR"
54+
mkdir -p "$HOMEBREW_CACHE_DIR"
55+
export HOMEBREW_CACHE_ENABLED=false
56+
fi
57+
else
58+
echo "No Homebrew cache - downloading fresh packages"
59+
export HOMEBREW_CACHE_ENABLED=false
60+
fi
4361

44-
export HOMEBREW_CACHE="$HOMEBREW_CACHE_DIR"
45-
#check if cache for homebrew exists
46-
if [ "${HOMEBREW_CACHE}" = "true" ]; then
47-
echo "Homebrew cache found, restoring cached packages"
48-
export HOMEBREW_NO_AUTO_UPDATE=1
49-
else
50-
echo "No Homebrew cache - downloading fresh packages"
51-
fi
62+
export HOMEBREW_CACHE="$HOMEBREW_CACHE_DIR"
5263
fi
5364
}
5465

5566
setup_git_cache() {
56-
if [ "${CACHING_ENABLED}" = "true" ]; then
67+
if [ "${CACHING_ENABLED}" == "true" ]; then
5768
echo "Setting up Git cache..."
5869
mkdir -p "$GIT_CACHE_DIR"
5970

60-
if [ "${GIT_REPOS_CACHE}" = "true" ]; then
71+
if [ "${GIT_REPOS_CACHE}" == "true" ]; then
6172
echo "Git repositories cache found, restoring cached repositories"
6273
# Validate cache isn't corrupted
6374
if [ -d "$GIT_CACHE_DIR" ] && [ "$(ls -A $GIT_CACHE_DIR 2>/dev/null)" ]; then
@@ -76,7 +87,7 @@ setup_git_cache() {
7687
}
7788

7889
setup_dependencies_cache() {
79-
if [ "${CACHING_ENABLED}" = "true" ] && [ "${BUILT_DEPS_CACHE}" = "true" ]; then
90+
if [ "${CACHING_ENABLED}" == "true" ] && [ "${BUILT_DEPS_CACHE}" == "true" ]; then
8091
echo "Built dependencies cache found, restoring cached dependencies"
8192
# Validate cache isn't corrupted
8293
if [ -d "$STAGING_AREA_DEPS" ] && [ "$(ls -A $STAGING_AREA_DEPS 2>/dev/null)" ]; then
@@ -118,7 +129,7 @@ install_packages() {
118129
major_version=$(echo "$macos_version" | cut -d '.' -f 1)
119130

120131
# Package installation based on cache status
121-
if [ "${CACHING_ENABLED}" = "true" ] && [ "${HOMEBREW_CACHE}" = "true" ]; then
132+
if [ "${CACHING_ENABLED}" = "true" ] && [ "${HOMEBREW_CACHE_ENABLED}" = "true" ]; then
122133
echo "Installing packages with cache optimization (skipping update/upgrade)..."
123134
export HOMEBREW_NO_AUTO_UPDATE=1
124135
else
@@ -166,7 +177,7 @@ clone() {
166177
mkdir -p $STAGING_AREA
167178
pushd $STAGING_AREA
168179

169-
if [ "${CACHING_ENABLED}" = "true" ] && [ "$GIT_CACHE_ENABLED" = "true" ]; then
180+
if [ "${CACHING_ENABLED}" == "true" ] && [ "$GIT_CACHE_ENABLED" == "true" ]; then
170181
echo "Using cached repositories..."
171182

172183
# If cache directory has content, use it

0 commit comments

Comments
 (0)