From 997bd49f75f08e9365f7e920604f3c5d7c183426 Mon Sep 17 00:00:00 2001 From: Marco Borgeaud Date: Wed, 14 Aug 2024 09:08:55 +0200 Subject: [PATCH] Improve cirrus-cache.sh Print md5 as part of cache scripts. Address spellcheck issues (quote variables). Remove dead variables. Improve output in general and pipe errors to stderr. Fully spell out curl options for better readability. Always show error with curl. --- .cirrus.yml | 6 +++--- ci/cirrus-cache.sh | 36 ++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 87a70375d9..0027f82a21 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -25,7 +25,7 @@ container_definition: &CONTAINER_DEFINITION setup_sonar_scanner: &SETUP_SONAR_SCANNER setup_sonar_scanner_script: - - apt update -y && apt upgrade -y && apt update -y && apt install -y unzip + - apt update -y && apt upgrade -y && apt update -y && apt install -y unzip - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ @@ -117,12 +117,12 @@ validate_links_task: LINK_CACHE_PATH: /root/link-probing-history.cache cache_download_script: - bash ci/cirrus-cache.sh download ${LINK_CACHE_NAME} ${LINK_CACHE_PATH} - tests_script: - md5sum /root/link-probing-history.cache/link_probes.history || true + tests_script: - ./ci/validate_links.sh ${LINK_CACHE_PATH} - - md5sum /root/link-probing-history.cache/link_probes.history always: cache_upload_script: + - md5sum /root/link-probing-history.cache/link_probes.history || true - bash ci/cirrus-cache.sh upload ${LINK_CACHE_NAME} ${LINK_CACHE_PATH} validate_file_extensions_task: diff --git a/ci/cirrus-cache.sh b/ci/cirrus-cache.sh index 2c48ff58cc..361516f4a4 100644 --- a/ci/cirrus-cache.sh +++ b/ci/cirrus-cache.sh @@ -6,38 +6,38 @@ ACTION=${1} CACHE_NAME=${2} PATH_TO_CACHE=${3} -CACHE_KEY=${CACHE_NAME} -DEFAULT_CACHE_KEY=${CACHE_NAME} +CACHE_URL="http://${CIRRUS_HTTP_CACHE_HOST}/${CACHE_NAME}" -CACHE_URL=http://${CIRRUS_HTTP_CACHE_HOST}/${CACHE_KEY} - -TMP_PATH=/tmp/tmp-cache.tgz +TMP_PATH="/tmp/tmp-cache.tgz" case "${ACTION}" in download) - echo "Download cache with key ${CACHE_KEY}" - - echo " -> try ${CACHE_URL}" - curl -sfSL -o ${TMP_PATH} ${CACHE_URL} || { - echo "Cache download failed"; - exit 0; + echo "Download cache with key ${CACHE_NAME} from ${CACHE_URL}" + curl --silent --show-error --fail --location --output "${TMP_PATH}" "${CACHE_URL}" || { + echo "Cache download failed" >&2 + exit 0 } - du -hs ${TMP_PATH} - tar -Pxzf ${TMP_PATH} - rm ${TMP_PATH} + du -hs "${TMP_PATH}" + tar -Pxzf "${TMP_PATH}" + rm "${TMP_PATH}" ;; upload) echo "Upload cache to ${CACHE_URL}" - tar -Pczf ${TMP_PATH} ${PATH_TO_CACHE} - du -hs ${TMP_PATH} - curl -s -X POST --data-binary @${TMP_PATH} ${CACHE_URL} + tar -Pczf "${TMP_PATH}" "${PATH_TO_CACHE}" + du -hs "${TMP_PATH}" + curl --silent --show-error -X POST --data-binary "@${TMP_PATH}" "${CACHE_URL}" || { + echo "Cache upload failed" >&2 + exit 0 + } ;; *) - echo "Unexpected cache ACTION: ${ACTION}" + echo "Unexpected cache ACTION: ${ACTION}" >&2 exit 1 ;; esac + +echo "Cache ${ACTION}ed succeeded."