#!/usr/bin/env bash set -euo pipefail source "${GITHUB_WORKSPACE}/.github/scripts/ci/s3-cache-common.sh" if ! s3_cache_enabled; then echo "S3 Go module cache save 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 save skipped: CI_GO_MOD_HASH is empty" exit 0 fi download_cache="${GOMODCACHE}/cache/download" if [[ ! -d "${download_cache}" ]]; then echo "S3 Go module download cache save skipped: ${download_cache} does not exist" exit 0 fi rm -rf "${GITHUB_WORKSPACE}/.cache/go/build-cache" find "${download_cache}" -type f -name '*.lock' -delete tmp_root="$(mktemp -d)" tmp_tar="${tmp_root}/go-cache.tar" tmp_archive="${tmp_tar}.zst" trap 'rm -rf "${tmp_root}"' EXIT mkdir -p "${GITHUB_WORKSPACE}/.cache/go/pkg/mod/cache/download" tar \ --sort=name \ --mtime='UTC 1970-01-01' \ --owner=0 \ --group=0 \ --numeric-owner \ -C "${GITHUB_WORKSPACE}/.cache" \ -cf "${tmp_tar}" \ go/pkg/mod/cache/download zstd -T0 -3 -q "${tmp_tar}" -o "${tmp_archive}" cache_key="${RUNNER_S3_PREFIX}/go-download/hash/${RUNNER_OS:-Linux}/${CI_GO_MOD_HASH}.tar.zst" s3_cache_upload_if_missing "${cache_key}" "${tmp_archive}"