Skip to content

Commit

Permalink
fix(script): make disk conditions simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavovalverde committed Dec 6, 2023
1 parent e839b49 commit 6457786
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions .github/workflows/scripts/gcp-get-cached-disks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# and finally checks other branches if needed. The selected image is used for
# setting up the environment in a CI/CD pipeline.

set -exuo pipefail
set -euo pipefail

# Function to find and report a cached disk image
find_cached_disk_image() {
Expand All @@ -18,9 +18,9 @@ find_cached_disk_image() {

# Use >&2 to redirect to stderr and avoid sending wrong assignments to stdout
if [[ -n "${disk_name}" ]]; then
echo "Found ${git_source} Disk: ${disk_name}" >&2
disk_description=$(gcloud compute images describe "${disk_name}" --format="value(DESCRIPTION)")
echo "Description: ${disk_description}" >&2
# echo "Found ${git_source} Disk: ${disk_name}" >&2
# disk_description=$(gcloud compute images describe "${disk_name}" --format="value(DESCRIPTION)")
# echo "Description: ${disk_description}" >&2
echo "${disk_name}" # This is the actual return value when a disk is found
else
echo "No ${git_source} disk found." >&2
Expand All @@ -43,17 +43,16 @@ fi

# Find the most suitable cached disk image
echo "Finding the most suitable cached disk image..."
COMMIT_DISK_PREFIX="${DISK_PREFIX}-.+-${GITHUB_SHA_SHORT}-v${LOCAL_STATE_VERSION}-${NETWORK}-${DISK_SUFFIX}"
CACHED_DISK_NAME=$(find_cached_disk_image "${COMMIT_DISK_PREFIX}" "commit")

if [[ -z "${CACHED_DISK_NAME}" && "${PREFER_MAIN_CACHED_STATE}" == "true" ]]; then
MAIN_DISK_PREFIX="${DISK_PREFIX}-main-[0-9a-f]+-v${LOCAL_STATE_VERSION}-${NETWORK}-${DISK_SUFFIX}"
CACHED_DISK_NAME=$(find_cached_disk_image "${MAIN_DISK_PREFIX}" "main branch")
fi

if [[ -z "${CACHED_DISK_NAME}" ]]; then
ANY_DISK_PREFIX="${DISK_PREFIX}-.+-[0-9a-f]+-v${LOCAL_STATE_VERSION}-${NETWORK}-${DISK_SUFFIX}"
CACHED_DISK_NAME=$(find_cached_disk_image "${ANY_DISK_PREFIX}" "any branch")
COMMIT_DISK_PREFIX="${DISK_PREFIX}-.+-${GITHUB_SHA_SHORT}-v${LOCAL_STATE_VERSION}-${NETWORK}-${DISK_SUFFIX}"
CACHED_DISK_NAME=$(find_cached_disk_image "${COMMIT_DISK_PREFIX}" "commit")
if [[ "${PREFER_MAIN_CACHED_STATE}" == "true" ]]; then
MAIN_DISK_PREFIX="${DISK_PREFIX}-main-[0-9a-f]+-v${LOCAL_STATE_VERSION}-${NETWORK}-${DISK_SUFFIX}"
CACHED_DISK_NAME=$(find_cached_disk_image "${MAIN_DISK_PREFIX}" "main branch")
elif [[ "${PREFER_MAIN_CACHED_STATE}" == "false" ]]; then
ANY_DISK_PREFIX="${DISK_PREFIX}-.+-[0-9a-f]+-v${LOCAL_STATE_VERSION}-${NETWORK}-${DISK_SUFFIX}"
CACHED_DISK_NAME=$(find_cached_disk_image "${ANY_DISK_PREFIX}" "any branch")
fi
fi

# Handle case where no suitable disk image is found
Expand Down

0 comments on commit 6457786

Please sign in to comment.