Files
xinfra/.github/scripts/ci/restore-go-cache.sh
T

29 lines
923 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
source "${GITHUB_WORKSPACE}/.github/scripts/ci/s3-cache-common.sh"
mkdir -p "${GOMODCACHE}/cache/download" "${GOPATH}/bin" "${GOCACHE}" "${GITHUB_WORKSPACE}/.cache"
rm -rf "${GITHUB_WORKSPACE}/.cache/go/build-cache"
if ! s3_cache_enabled; then
echo "S3 Go module cache restore skipped: missing RUNNER_S3_AK/RUNNER_S3_SK or rclone"
exit 0
fi
if [[ -z "${CI_GO_MOD_HASH:-}" ]]; then
echo "S3 Go module cache restore skipped: CI_GO_MOD_HASH is empty"
exit 0
fi
cache_key="${RUNNER_S3_PREFIX}/go-download/hash/${RUNNER_OS:-Linux}/${CI_GO_MOD_HASH}.tar.zst"
archive_path="$(mktemp)"
trap 'rm -f "${archive_path}"' EXIT
if s3_cache_get "${cache_key}" "${archive_path}"; then
zstd -dc "${archive_path}" | tar -C "${GITHUB_WORKSPACE}/.cache" -xf -
echo "Restored S3 Go module download cache: ${cache_key}"
else
echo "S3 Go module download cache not found: ${cache_key}"
fi