BlueGit

ict rusty-teams

Files

rusty-teams / packaging / kvt / ci-cache.sh

ci-cache.sh

ci-cache.sh 1.8 KiB Download Raw
1#!/usr/bin/env bash
2# Pack or unpack a Cargo/rustup (and optional cargo-xwin) cache as one tarball.
3# BlueGit `cache.paths` copies only files, not directories, so a directory
4# such as cargo-home/ would otherwise be skipped (see bluegit runner saveCache).
5# Does not cache target/: too large for the runner's job-cache budget.
6set -euo pipefail
7
8usage() {
9 echo "usage: $0 restore|save linux|windows" >&2
10 exit 2
11}
12
13cmd="${1:-}"
14kind="${2:-}"
15[[ "$cmd" == restore || "$cmd" == save ]] || usage
16[[ "$kind" == linux || "$kind" == windows ]] || usage
17
18archive=".ci-cache/cargo-${kind}.tar.gz"
19
20# Locations in the job workspace (set by the CI job / ci-setup.sh).
21cargo_home="${CARGO_HOME:-$PWD/cargo-home}"
22rustup_home="${RUSTUP_HOME:-$PWD/rustup-home}"
23xwin_cache="${XWIN_CACHE_DIR:-$PWD/xwin-cache}"
24
25relpath() {
26 local abs="$1"
27 case "$abs" in
28 "$PWD"/*) printf '%s\n' "${abs#"$PWD"/}" ;;
29 /*) printf '%s\n' "$abs" ;;
30 *) printf '%s\n' "$abs" ;;
31 esac
32}
33
34if [[ "$cmd" == restore ]]; then
35 if [[ -f "$archive" ]]; then
36 tar -xzf "$archive"
37 echo "CI-cache hersteld ($archive)."
38 else
39 echo "Geen CI-cache ($archive)."
40 fi
41 exit 0
42fi
43
44mkdir -p .ci-cache
45parts=()
46add_if_dir() {
47 local p="$1"
48 [[ -d "$p" ]] || return 0
49 parts+=("$(relpath "$p")")
50}
51
52# Registry and git checkouts, not registry/src (that is rebuilt from .crate files).
53add_if_dir "$cargo_home/bin"
54add_if_dir "$cargo_home/registry/index"
55add_if_dir "$cargo_home/registry/cache"
56add_if_dir "$cargo_home/git/db"
57add_if_dir "$rustup_home"
58if [[ "$kind" == windows ]]; then
59 add_if_dir "$xwin_cache"
60fi
61
62if [[ ${#parts[@]} -eq 0 ]]; then
63 echo "Niets te cachen."
64 exit 0
65fi
66
67# gzip -1: kleiner bestand voor de 10 GB-jobcache, weinig CPU.
68tar -c --use-compress-program='gzip -1' -f "$archive" "${parts[@]}"
69echo "CI-cache opgeslagen ($archive): ${parts[*]}"
70ls -lh "$archive"