rspec/ci/cirrus-cache.sh
Marco Borgeaud 997bd49f75 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.
2024-08-22 09:59:26 +02:00

44 lines
848 B
Bash

#! /bin/bash
set -euo pipefail
ACTION=${1}
CACHE_NAME=${2}
PATH_TO_CACHE=${3}
CACHE_URL="http://${CIRRUS_HTTP_CACHE_HOST}/${CACHE_NAME}"
TMP_PATH="/tmp/tmp-cache.tgz"
case "${ACTION}" in
download)
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}"
;;
upload)
echo "Upload cache to ${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}" >&2
exit 1
;;
esac
echo "Cache ${ACTION}ed succeeded."