Skip to content

Commit

Permalink
Merge pull request #11 from Automattic/fix/inverted-logic-for-caching
Browse files Browse the repository at this point in the history
Update save_cache
  • Loading branch information
jkmassel authored Dec 7, 2021
2 parents f90b738 + ad7bb1c commit a65470a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
11 changes: 6 additions & 5 deletions bin/restore_cache
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ CACHE_KEY=$1
S3_BUCKET_NAME=${CACHE_BUCKET_NAME-}
if [ -z "$S3_BUCKET_NAME" ]; then
if [ -z "$BUILDKITE_PLUGIN_BASH_CACHE_BUCKET" ]; then
printenv | grep buildkite
echo "Reading bucket name from 'BUILDKITE_PLUGIN_BASH_CACHE_BUCKET'"
CACHE_BUCKET_NAME="$BUILDKITE_PLUGIN_BASH_CACHE_BUCKET"
else
echo "⛔Unable to restore file from cache – no \$CACHE_BUCKET_NAME is set"
exit 1
else
echo "Reading bucket name from 'BUILDKITE_PLUGIN_BASH_CACHE_BUCKET'"
S3_BUCKET_NAME="$BUILDKITE_PLUGIN_BASH_CACHE_BUCKET"
fi
fi

echo "Using $S3_BUCKET_NAME as cache bucket"

if aws s3api head-object --bucket "$S3_BUCKET_NAME" --key "$CACHE_KEY" > /dev/null 2>&1; then
echo "Restoring cache entry $CACHE_KEY"

echo " Downloading"
# If the bucket has transfer acceleration enabled, use it!
ACCELERATION_STATUS=$(aws s3api get-bucket-accelerate-configuration --bucket $S3_BUCKET_NAME | jq '.Status' -r || true)
ACCELERATION_STATUS=$(aws s3api get-bucket-accelerate-configuration --bucket "$S3_BUCKET_NAME" | jq '.Status' -r || true)

if [ "$ACCELERATION_STATUS" = "Enabled" ]; then
echo "Downloading with transfer acceleration"
Expand Down
9 changes: 4 additions & 5 deletions bin/save_cache
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ fi
S3_BUCKET_NAME=${CACHE_BUCKET_NAME-}
if [ -z "$S3_BUCKET_NAME" ]; then
if [ -z "$BUILDKITE_PLUGIN_BASH_CACHE_BUCKET" ]; then
printenv | grep buildkite
echo "Reading bucket name from 'BUILDKITE_PLUGIN_BASH_CACHE_BUCKET'"
CACHE_BUCKET_NAME="$BUILDKITE_PLUGIN_BASH_CACHE_BUCKET"
else
echo "⛔Unable to save file to cache – no \$CACHE_BUCKET_NAME is set"
exit 1
else
echo "Reading bucket name from 'BUILDKITE_PLUGIN_BASH_CACHE_BUCKET'"
S3_BUCKET_NAME="$BUILDKITE_PLUGIN_BASH_CACHE_BUCKET"
fi
fi

Expand All @@ -53,7 +52,7 @@ if ! aws s3api head-object --bucket "$S3_BUCKET_NAME" --key "$CACHE_KEY" > /dev/

echo " Uploading"
# If the bucket has transfer acceleration enabled, use it!
ACCELERATION_STATUS=$(aws s3api get-bucket-accelerate-configuration --bucket $S3_BUCKET_NAME | jq '.Status' -r || true)
ACCELERATION_STATUS=$(aws s3api get-bucket-accelerate-configuration --bucket "$S3_BUCKET_NAME" | jq '.Status' -r || true)

if [ "$ACCELERATION_STATUS" = "Enabled" ]; then
echo "Uploading with transfer acceleration"
Expand Down

0 comments on commit a65470a

Please sign in to comment.