Skip to content

Commit

Permalink
Gradle: Echo directory variables for debugging purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
ParaskP7 committed Dec 20, 2024
1 parent 9ba0769 commit cb9972a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions bin/restore_cache
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@ if aws s3api head-object --bucket "$S3_BUCKET_NAME" --key "$CACHE_KEY" > /dev/nu
aws s3 cp "s3://$S3_BUCKET_NAME/$CACHE_KEY" "$CACHE_KEY" --quiet
fi

echo "Current directory is: $(pwd)"
echo "Directory contents are (BEFORE): $(ls -la)"
COMPRESSED_CACHE_SIZE=$(wc -c < "$CACHE_KEY")
echo " Decompressing"
tar -xf "$CACHE_KEY"
if [ -n "$CACHE_FILE" ]; then
UNCOMPRESSED_CACHE_SIZE=$(du -sb "$CACHE_FILE" | awk '{print $1}')
fi
echo "Directory contents are (AFTER): $(ls -la)"
echo "Directory contents of 'dependency-cache': $(ls -la dependency-cache)"
if [ -d "modules-2" ]; then
echo "Directory contents of 'modules-2': $(ls -la modules-2)"
else
echo "Directory 'modules-2' does not exist"
fi

echo " Cleaning Up"
rm "$CACHE_KEY"
Expand Down
14 changes: 13 additions & 1 deletion bin/restore_gradle_dependency_cache
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@ GRADLE_DEPENDENCY_CACHE_KEY="${BUILDKITE_PIPELINE_SLUG}_GRADLE_DEPENDENCY_CACHE_

echo "Restoring Gradle dependency cache..."

GRADLE_DEP_CACHE="$GRADLE_HOME/caches/modules-2"
GRADLE_DEP_CACHE="$GRADLE_HOME/dependency-cache"

echo "GRADLE_DEP_CACHE: $GRADLE_DEP_CACHE"
DEP_CACHE_BASE_FOLDER=$(dirname "$GRADLE_DEP_CACHE")
DEP_CACHE_FOLDER_NAME=$(basename "$GRADLE_DEP_CACHE")

# `save_cache` & `restore_cache` scripts only work if they are called from the same directory
echo "DEP_CACHE_BASE_FOLDER: $DEP_CACHE_BASE_FOLDER"
pushd "$DEP_CACHE_BASE_FOLDER"
echo "DEP_CACHE_FOLDER_NAME: $DEP_CACHE_FOLDER_NAME"
restore_cache "$GRADLE_DEPENDENCY_CACHE_KEY" "$DEP_CACHE_FOLDER_NAME"
if [ -d "modules-2" ]; then
mv "$DEP_CACHE_FOLDER_NAME/modules-2/"* modules-2/
else
mv "$DEP_CACHE_FOLDER_NAME/modules-2/" modules-2/
fi
echo "Directory contents of 'dependency-cache': $(ls -la dependency-cache)"
echo "Directory contents of 'modules-2': $(ls -la modules-2)"
rm -r "$DEP_CACHE_FOLDER_NAME"
echo "Directory contents are (FINAL): $(ls -la)"
popd

echo "---"
3 changes: 3 additions & 0 deletions bin/save_cache
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ if ! aws s3api head-object --bucket "$S3_BUCKET_NAME" --key "$CACHE_KEY" > /dev/
SECONDS=0
echo "No existing cache entry for $CACHE_KEY – storing in cache"

echo "Current directory is: $(pwd)"
echo "Directory contents are (BEFORE): $(ls -la)"
UNCOMPRESSED_CACHE_SIZE=$(du -sb "$CACHE_FILE" | awk '{print $1}')
echo " Compressing"
TAR_CONFIG=${4-}
Expand All @@ -67,6 +69,7 @@ if ! aws s3api head-object --bucket "$S3_BUCKET_NAME" --key "$CACHE_KEY" > /dev/
tar -czf "$CACHE_KEY" "$CACHE_FILE"
fi
COMPRESSED_CACHE_SIZE=$(wc -c < "$CACHE_KEY")
echo "Directory contents are (AFTER): $(ls -la)"

echo " Uploading"
# If the bucket has transfer acceleration enabled, use it!
Expand Down
3 changes: 3 additions & 0 deletions bin/save_gradle_dependency_cache
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ echo "Saving Gradle dependency cache..."

GRADLE_DEP_CACHE="$GRADLE_HOME/dependency-cache"

echo "GRADLE_DEP_CACHE: $GRADLE_DEP_CACHE"
mkdir -p "$GRADLE_DEP_CACHE"

# https://docs.gradle.org/current/userguide/dependency_resolution.html#sub:cache_copy
Expand All @@ -19,8 +20,10 @@ DEP_CACHE_BASE_FOLDER=$(dirname "$GRADLE_DEP_CACHE")
DEP_CACHE_FOLDER_NAME=$(basename "$GRADLE_DEP_CACHE")

# `save_cache` & `restore_cache` scripts only work if they are called from the same directory
echo "DEP_CACHE_BASE_FOLDER: $DEP_CACHE_BASE_FOLDER"
pushd "$DEP_CACHE_BASE_FOLDER"
# For now we are using a single key - we might expand on this later by using dependency catalog version
echo "DEP_CACHE_FOLDER_NAME: $DEP_CACHE_FOLDER_NAME"
save_cache "$DEP_CACHE_FOLDER_NAME" "$GRADLE_DEPENDENCY_CACHE_KEY" --force
popd

Expand Down

0 comments on commit cb9972a

Please sign in to comment.