Skip to content

Commit faab498

Browse files
authored
Merge pull request #7 from cbandy/here-strings
Compatibility with ubuntu-18.04 runner
2 parents 8c1a637 + cc235e7 commit faab498

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

action.sh

+12-12
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ fi
1515
# Fetch all K3s versions usable for the specified partial version.
1616
# Even if the version is specific and complete, assume it is possibly partial.
1717
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')
2020

2121
echo "::group::All available K3s versions (unsorted)"
22-
cat /tmp/versions.txt
22+
echo "$versions"
2323
echo "::endgroup::"
2424

2525
# Sort the versions numerically, not lexographically:
@@ -28,7 +28,7 @@ echo "::endgroup::"
2828
# 2. Convert parts to numbers when possible ([1, 19, 4, 1]).
2929
# 3. Sort numerically instead of lexographically.
3030
# 4. Restore the original name of each version.
31-
jq --slurp '
31+
versions_sorted=$(jq --slurp <<< "$versions" '
3232
[ .[]
3333
| { original: .,
3434
numeric:
@@ -42,41 +42,41 @@ jq --slurp '
4242
| reverse
4343
| .[]
4444
| .original
45-
' </tmp/versions.txt >/tmp/sorted.txt
45+
')
4646

4747
echo "::group::All available K3s versions (newest on top)"
48-
cat /tmp/sorted.txt
48+
echo "$versions_sorted"
4949
echo "::endgroup::"
5050

5151
# The "latest" version is not directly exposed, but we hard-code its meaning.
5252
if [[ "${VERSION}" == "latest" ]]; then
53-
VERSION=$(head -n 1 /tmp/sorted.txt | jq -r)
53+
VERSION=$(jq --slurp <<< "$versions_sorted" --raw-output '.[0]')
5454
fi
5555

5656
# The select only those versions that match the requested one.
5757
# Do not rely on the parsed forms of the versions -- they may miss some parts.
5858
# Rely only on the actual name of the version.
5959
# 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}" '
6161
.[]
6262
| select((.|startswith($version + ".")) or
6363
(.|startswith($version + "-")) or
6464
(.|startswith($version + "+")) or
6565
(.==$version))
66-
' </tmp/sorted.txt >/tmp/matching.txt
66+
')
6767

6868
echo "::group::All matching K3s versions (newest on top)"
69-
cat /tmp/matching.txt
69+
echo "$versions_matching"
7070
echo "::endgroup::"
7171

7272
# 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
7474
echo "::error::No matching K3s versions were found."
7575
exit 1
7676
fi
7777

7878
# 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]')
8080
K8S=${K3S%%+*}
8181

8282
# Communicate back to GitHub Actions.

0 commit comments

Comments
 (0)