Skip to content

Commit ffe05e0

Browse files
committed
calculate-cache.sh: add descriptions and output examples to functions
Signed-off-by: Norio Nomura <[email protected]>
1 parent c860b17 commit ffe05e0

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

hack/calculate-cache.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ LIMA_HOME=$(mktemp -d)
2424
export LIMA_HOME
2525

2626
# parse the workflow file and print runs-on and template
27+
# e.g.
28+
# ```console
29+
# $ print_runs_on_template_from_workflow .github/workflows/test.yml
30+
# macos-12 templates/default.yaml
31+
# ubuntu-24.04 templates/alpine.yaml
32+
# ubuntu-24.04 templates/debian.yaml
33+
# ubuntu-24.04 templates/fedora.yaml
34+
# ubuntu-24.04 templates/archlinux.yaml
35+
# ubuntu-24.04 templates/opensuse.yaml
36+
# ubuntu-24.04 templates/experimental/net-user-v2.yaml
37+
# ubuntu-24.04 templates/experimental/9p.yaml
38+
# ubuntu-24.04 templates/docker.yaml
39+
# ubuntu-24.04 templates/../hack/test-templates/alpine-9p-writable.yaml
40+
# ubuntu-24.04 templates/../hack/test-templates/test-misc.yaml
41+
# macos-12 templates/vmnet.yaml
42+
# macos-12 https://raw.githubusercontent.com/lima-vm/lima/v0.15.1/examples/ubuntu-lts.yaml
43+
# macos-13 templates/experimental/vz.yaml
44+
# macos-13 templates/fedora.yaml
45+
# ```
2746
function print_runs_on_template_from_workflow() {
2847
yq -o=j "$1" | jq -r '
2948
"./.github/actions/setup_cache_for_template" as $action |
@@ -48,6 +67,14 @@ function print_runs_on_template_from_workflow() {
4867
'
4968
}
5069

70+
# returns the OS name from the runner equivalent to the expression `${{ runner.os }}` in the workflow
71+
# e.g.
72+
# ```console
73+
# $ runner_os_from_runner "macos-12"
74+
# macOS
75+
# $ runner_os_from_runner "ubuntu-24.04"
76+
# Linux
77+
# ```
5178
function runner_os_from_runner() {
5279
# shellcheck disable=SC2249
5380
case "$1" in
@@ -60,6 +87,13 @@ function runner_os_from_runner() {
6087
esac
6188
}
6289

90+
# check the remote location and return the http code and size.
91+
# The result is cached in .calculate-cache-response-cache.yaml
92+
# e.g.
93+
# ```console
94+
# $ check_location "https://cloud-images.ubuntu.com/releases/24.04/release-20240725/ubuntu-24.04-server-cloudimg-amd64.img"
95+
# 200 585498624
96+
# ```
6397
function check_location() {
6498
location="$1"
6599
readonly cache_file="./.calculate-cache-response-cache.yaml"
@@ -74,6 +108,12 @@ function check_location() {
74108
echo "${http_code_and_size}"
75109
}
76110

111+
# print image location, digest, size, hash, containerd, containerd_location, containerd_digest, containerd_size from the template
112+
# e.g.
113+
# ```console
114+
# $ print_location_digest_size_hash_from_template "templates/default.yaml"
115+
# https://cloud-images.ubuntu.com/releases/24.04/release-20240725/ubuntu-24.04-server-cloudimg-amd64.img sha256:d2377667ea95222330ca2287817403c85178dad397e9fed768a9b4aec79d2a7f 585498624 49aa50a4872ded07ebf657c0eaf9e44ecc0c174d033a97c537ecd270f35b462f true https://github.com/containerd/nerdctl/releases/download/v1.7.6/nerdctl-full-1.7.6-linux-amd64.tar.gz sha256:2c841e097fcfb5a1760bd354b3778cb695b44cd01f9f271c17507dc4a0b25606 237465717
116+
# ```
77117
function print_location_digest_size_hash_from_template() {
78118
readonly template=$1
79119
case "${template}" in
@@ -124,6 +164,11 @@ function print_location_digest_size_hash_from_template() {
124164
}
125165

126166
# format first column to MiB
167+
# e.g.
168+
# ```console
169+
# $ echo 585498624 | size_to_mib
170+
# 558.38 MiB
171+
# ```
127172
function size_to_mib() {
128173
awk '
129174
function mib(size) { return sprintf("%7.2f MiB", size / 1024 / 1024) }
@@ -135,6 +180,36 @@ function size_to_mib() {
135180
}
136181

137182
# actual_cache_sizes=$(gh cache list --json key,createdAt,sizeInBytes|jq '[.[]|{"key":.key,"value":.sizeInBytes}]|from_entries')
183+
# e.g.
184+
# ```console
185+
# $ echo "${actual_cache_sizes}"
186+
# {
187+
# "Linux-1c3b2791d52735d916dc44767c745c2319eb7cae74af71bbf45ddb268f42fc1d": 810758533,
188+
# "Linux-231c66957fc2cdb18ea10e63f60770049026e29051ecd6598fc390b60d6a4fa6": 633036717,
189+
# "Linux-3b906d46fa532e3bc348c35fc8e7ede6c69f0b27032046ee2cbb56d4022d1146": 574242367,
190+
# "Linux-69a547b760dbf1650007ed541408474237bc611704077214adcac292de556444": 70310855,
191+
# "Linux-7782f8b4ff8cd378377eb79f8d61c9559b94bbd0c11d19eb380ee7bda19af04e": 494141177,
192+
# "Linux-8812aedfe81b4456d421645928b493b1f2f88aff04b7f3171207492fd44cd189": 812730766,
193+
# "Linux-caa7d8af214d55ad8902e82d5918e61573f3d6795d2b5ad9a35305e26fa0e6a9": 754723892,
194+
# "Linux-colima-v0.6.5": 226350335,
195+
# "Linux-de83bce0608d787e3c68c7a31c5fab2b6d054320fd7bf633a031845e2ee03414": 810691197,
196+
# "Linux-eb88a19dfcf2fb98278e7c7e941c143737c6d7cd8950a88f58e04b4ee7cef1bc": 570625794,
197+
# "Linux-f88f0b3b678ff6432386a42bdd27661133c84a36ad29f393da407c871b0143eb": 68490954,
198+
# "golangci-lint.cache-Linux-2850-74615231540133417fd618c72e37be92c5d3b3ad": 2434144,
199+
# "macOS-231c66957fc2cdb18ea10e63f60770049026e29051ecd6598fc390b60d6a4fa6": 633020464,
200+
# "macOS-49aa50a4872ded07ebf657c0eaf9e44ecc0c174d033a97c537ecd270f35b462f": 813179462,
201+
# "macOS-8f37f663956af5f743f0f99ab973729b6a02f200ebfac7a3a036eff296550732": 810756770,
202+
# "macOS-ef5509b5d4495c8c3590442ee912ad1c9a33f872dc4a29421c524fc1e2103b59": 813179476,
203+
# "macOS-upgrade-v0.15.1": 1157814690,
204+
# "setup-go-Linux-ubuntu20-go-1.23.0-02756877dbcc9669bb904e42e894c63aa9801138db94426a90a2d554f2705c52": 1015518352,
205+
# "setup-go-Linux-ubuntu20-go-1.23.0-6bce2eefc6111ace836de8bb322432c072805737d5f3c5a3d47d2207a05f50df": 936433302,
206+
# "setup-go-Linux-ubuntu24-go-1.22.6-02756877dbcc9669bb904e42e894c63aa9801138db94426a90a2d554f2705c52": 1090001859,
207+
# "setup-go-Linux-ubuntu24-go-1.23.0-02756877dbcc9669bb904e42e894c63aa9801138db94426a90a2d554f2705c52": 526146768,
208+
# "setup-go-Windows-go-1.23.0-02756877dbcc9669bb904e42e894c63aa9801138db94426a90a2d554f2705c52": 1155374040,
209+
# "setup-go-Windows-go-1.23.0-6bce2eefc6111ace836de8bb322432c072805737d5f3c5a3d47d2207a05f50df": 1056433137,
210+
# "setup-go-macOS-go-1.23.0-02756877dbcc9669bb904e42e894c63aa9801138db94426a90a2d554f2705c52": 1060919942,
211+
# "setup-go-macOS-go-1.23.0-6bce2eefc6111ace836de8bb322432c072805737d5f3c5a3d47d2207a05f50df": 982139209
212+
# }
138213
actual_cache_sizes=$(
139214
gh cache list --json key,createdAt,sizeInBytes |
140215
jq 'sort_by(.createdAt)|reverse|unique_by(.key)|sort_by(.key)|map({"key":.key,"value":.sizeInBytes})|from_entries'

0 commit comments

Comments
 (0)