7
7
template :
8
8
description : template yaml file
9
9
required : true
10
- detect-containerd :
11
- description : detect containerd usage from template by using limactl validate
12
- required : false
13
- default : ' true'
14
10
runs :
15
11
using : " composite"
16
12
steps :
@@ -29,120 +25,35 @@ runs:
29
25
id : cache-params-from-template
30
26
run : |
31
27
set -eux
32
- arch="${{ inputs.arch }}"
33
- template="${{ inputs.template }}"
34
- detect_containerd="${{ inputs.detect-containerd }}"
35
- if [[ $detect_containerd == "true" ]] && ! command -v limactl &>/dev/null; then
36
- echo "containerd detection is disabled because limactl is not found" >&2
37
- detect_containerd="false"
38
- fi
39
- case "$template" in
40
- https://*)
41
- tmp_yaml=$(mktemp -d)/template.yaml
42
- curl -sSLf "$template" > "$tmp_yaml" || exit 1
43
- template=$tmp_yaml
44
- ;;
45
- *)
46
- test -f "$template" || exit 1
47
- ;;
48
- esac
49
-
50
- # detect arch from template if not provided
51
- arch="${arch:-$(yq '.arch // ""' "$template")}"
52
- arch="${arch:-$(uname -m)}"
53
- # normalize arch. amd64 -> x86_64, arm64 -> aarch64
54
- case "$arch" in
55
- amd64) arch=x86_64 ;;
56
- arm64) arch=aarch64 ;;
57
- esac
58
-
59
- # extract digest, location and size by parsing template using arch
60
- readonly yq_filter="
61
- [
62
- .images | map(select(.arch == \"${arch}\")) | [.[0,1].location, .[0,1].digest],
63
- .containerd|[.system or .user],
64
- .containerd.archives | map(select(.arch == \"${arch}\")) | [.[0].location, .[0].digest]
65
- ]|flatten|.[]
66
- "
67
- if [[ $detect_containerd == "true" ]]; then
68
- parsed=$(LIMA_HOME=$(mktemp -d) limactl validate "$template" --fill 2>/dev/null | yq eval "${yq_filter}")
69
- else
70
- parsed=$(yq eval "${yq_filter}" "$template")
71
- fi
72
- # macOS earlier than 15.0 uses bash 3.2.57, which does not support readarray -t
73
- # readarray -t arr <<<"$parsed"
74
- while IFS= read -r line; do arr+=("$line"); done <<<"${parsed}"
75
- readonly locations=("${arr[@]:0:2}") digests=("${arr[@]:2:2}")
76
- readonly containerd="${arr[4]}" containerd_location="${arr[5]}" containerd_digest="${arr[6]}"
77
- for ((i = 0; i < ${#locations[@]}; i++)); do
78
- [[ ${locations[i]} != "null" ]] || continue
79
- http_code=$(curl -sIL -w "%{http_code}" "${locations[i]}" -o /dev/null)
80
- if [[ ${http_code} -eq 200 ]]; then
81
- location=${locations[i]}
82
- digest=${digests[i]}
83
- break
84
- fi
85
- done
86
- if [[ -z ${location} ]]; then
87
- echo "Failed to get the image location for ${template}" >&2
88
- exit 1
89
- fi
90
-
91
- function location_to_sha256() {
92
- local location=$1
93
- if command -v sha256sum > /dev/null; then
94
- sha256="$(echo -n "$location" | sha256sum | cut -d' ' -f1)"
95
- elif command -v shasum > /dev/null; then
96
- sha256="$(echo -n "$location" | shasum -a 256 | cut -d' ' -f1)"
97
- else
98
- echo "sha256sum or shasum not found" >&2
99
- exit 1
100
- fi
101
- echo "$sha256"
102
- }
103
-
104
- function location_to_cache_path() {
105
- local location=$1
106
- sha256=$(location_to_sha256 "$location") && echo ".download/by-url-sha256/$sha256"
107
- }
108
-
109
- # path to cache
110
- image_cache_path=$(location_to_cache_path "$location")
111
- echo "path=$image_cache_path" >> "$GITHUB_OUTPUT"
28
+ source hack/cache-common-inc.sh
29
+ print_cache_informations_from_template "${{ inputs.template }}" "${{ inputs.arch }}" >> "$GITHUB_OUTPUT"
30
+ shell : bash
112
31
113
- # key for cache
114
- image_basename=$(basename "$location")
115
- if [[ "$digest" != "null" ]]; then
116
- key="image:$image_basename-$digest"
117
- else
118
- # use sha256 of location as key if digest is not available
119
- key="image:$image_basename-url-sha256:$(location_to_sha256 "$location")"
120
- fi
121
- echo "key=$key" >> "$GITHUB_OUTPUT"
32
+ - name : " Cache ${{ steps.cache-params-from-template.outputs.image-path }}"
33
+ if : ${{ steps.cache-params-from-template.outputs.image-key != '' }}
34
+ # avoid using `~` in path that will be expanded to platform specific home directory
35
+ uses : actions/cache@v4
36
+ with :
37
+ path : ${{ steps.cache-params-from-template.outputs.image-path }}
38
+ key : ${{ steps.cache-params-from-template.outputs.image-key }}
39
+ enableCrossOsArchive : true
122
40
123
- # containerd path and key for cache
124
- if [[ $containerd == "true" && "$containerd_location" != "null" ]]; then
125
- containerd_basename=$(basename "$containerd_location")
126
- if [[ ${containerd_digest} != "null" ]]; then
127
- containerd_key="containerd:$containerd_basename-$containerd_digest"
128
- else
129
- containerd_key="containerd:$containerd_basename-url-sha256:$(sha256 "$containerd_location")"
130
- fi
131
- echo "containerd-key=$containerd_key" >> "$GITHUB_OUTPUT"
132
- containerd_cache_path=$(location_to_cache_path "$containerd_location")
133
- echo "containerd-path=$containerd_cache_path" >> "$GITHUB_OUTPUT"
134
- else
135
- echo "containerd-key=" >> "$GITHUB_OUTPUT"
136
- echo "containerd-path=" >> "$GITHUB_OUTPUT"
137
- fi
138
- shell : bash
41
+ - name : " Cache ${{ steps.cache-params-from-template.outputs.kernel-path }}"
42
+ if : ${{ steps.cache-params-from-template.outputs.kernel-key != '' }}
43
+ # avoid using `~` in path that will be expanded to platform specific home directory
44
+ uses : actions/cache@v4
45
+ with :
46
+ path : ${{ steps.cache-params-from-template.outputs.kernel-path }}
47
+ key : ${{ steps.cache-params-from-template.outputs.kernel-key }}
48
+ enableCrossOsArchive : true
139
49
140
- - name : " Cache ${{ steps.cache-params-from-template.outputs.path }}"
50
+ - name : " Cache ${{ steps.cache-params-from-template.outputs.initrd-path }}"
51
+ if : ${{ steps.cache-params-from-template.outputs.initrd-key != '' }}
141
52
# avoid using `~` in path that will be expanded to platform specific home directory
142
53
uses : actions/cache@v4
143
54
with :
144
- path : ${{ steps.cache-params-from-template.outputs.path }}
145
- key : ${{ steps.cache-params-from-template.outputs.key }}
55
+ path : ${{ steps.cache-params-from-template.outputs.initrd- path }}
56
+ key : ${{ steps.cache-params-from-template.outputs.initrd- key }}
146
57
enableCrossOsArchive : true
147
58
148
59
- name : " Cache ${{ steps.cache-params-from-template.outputs.containerd-key }}"
0 commit comments