15
15
# Fetch all K3s versions usable for the specified partial version.
16
16
# Even if the version is specific and complete, assume it is possibly partial.
17
17
url=" ${GITHUB_API_URL} /repos/${REPO} /releases?per_page=999"
18
- curl --silent --fail --location " ${authz[@]} " " $url " | \
19
- jq ' .[] | select(.prerelease==false) | .tag_name' > /tmp/versions.txt
18
+ releases= $( curl --silent --fail --location " ${authz[@]- } " " $url " )
19
+ versions= $( jq <<< " $releases " ' .[] | select(.prerelease==false) | .tag_name' )
20
20
21
21
echo " ::group::All available K3s versions (unsorted)"
22
- cat /tmp/ versions.txt
22
+ echo " $ versions"
23
23
echo " ::endgroup::"
24
24
25
25
# Sort the versions numerically, not lexographically:
@@ -28,7 +28,7 @@ echo "::endgroup::"
28
28
# 2. Convert parts to numbers when possible ([1, 19, 4, 1]).
29
29
# 3. Sort numerically instead of lexographically.
30
30
# 4. Restore the original name of each version.
31
- jq --slurp '
31
+ versions_sorted= $( jq --slurp <<< " $versions " '
32
32
[ .[]
33
33
| { original: .,
34
34
numeric:
@@ -42,41 +42,41 @@ jq --slurp '
42
42
| reverse
43
43
| .[]
44
44
| .original
45
- ' < /tmp/versions.txt > /tmp/sorted.txt
45
+ ' )
46
46
47
47
echo " ::group::All available K3s versions (newest on top)"
48
- cat /tmp/sorted.txt
48
+ echo " $versions_sorted "
49
49
echo " ::endgroup::"
50
50
51
51
# The "latest" version is not directly exposed, but we hard-code its meaning.
52
52
if [[ " ${VERSION} " == " latest" ]]; then
53
- VERSION=$( head -n 1 /tmp/sorted.txt | jq -r )
53
+ VERSION=$( jq --slurp <<< " $versions_sorted " --raw-output ' .[0] ' )
54
54
fi
55
55
56
56
# The select only those versions that match the requested one.
57
57
# Do not rely on the parsed forms of the versions -- they may miss some parts.
58
58
# Rely only on the actual name of the version.
59
59
# TODO: LATER: Handle release candidates: v1.18.2-rc3+k3s1 must be before v1.18.2+k3s1.
60
- jq --slurp --arg version " ${VERSION} " '
60
+ versions_matching= $( jq --slurp <<< " $versions_sorted " --arg version " ${VERSION} " '
61
61
.[]
62
62
| select((.|startswith($version + ".")) or
63
63
(.|startswith($version + "-")) or
64
64
(.|startswith($version + "+")) or
65
65
(.==$version))
66
- ' < /tmp/sorted.txt > /tmp/matching.txt
66
+ ' )
67
67
68
68
echo " ::group::All matching K3s versions (newest on top)"
69
- cat /tmp/matching.txt
69
+ echo " $versions_matching "
70
70
echo " ::endgroup::"
71
71
72
72
# Validate that we could identify the version (even a very specific one).
73
- if [[ ! -s /tmp/matching.txt ]]; then
73
+ if [[ -z " $versions_matching " ]]; then
74
74
echo " ::error::No matching K3s versions were found."
75
75
exit 1
76
76
fi
77
77
78
78
# Get the best possible (i.e. the latest) version of K3s/K8s.
79
- K3S=$( head -n 1 /tmp/matching.txt | jq -r )
79
+ K3S=$( jq --slurp <<< " $versions_matching " --raw-output ' .[0] ' )
80
80
K8S=${K3S%% +* }
81
81
82
82
# Communicate back to GitHub Actions.
0 commit comments