Skip to content

Commit b24727a

Browse files
authored
Merge pull request #8 from cbandy/native-sort
Use sort --version-sort to sort versions
2 parents faab498 + 624c3c4 commit b24727a

File tree

1 file changed

+1
-26
lines changed

1 file changed

+1
-26
lines changed

action.sh

+1-26
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,7 @@ fi
1717
url="${GITHUB_API_URL}/repos/${REPO}/releases?per_page=999"
1818
releases=$(curl --silent --fail --location "${authz[@]-}" "$url")
1919
versions=$(jq <<< "$releases" '.[] | select(.prerelease==false) | .tag_name')
20-
21-
echo "::group::All available K3s versions (unsorted)"
22-
echo "$versions"
23-
echo "::endgroup::"
24-
25-
# Sort the versions numerically, not lexographically:
26-
# 0. Preserve the original name of the version.
27-
# 1. Split the version nmame ("v1.19.4+k3s1") into parts (["1", "19", "4", "1"]).
28-
# 2. Convert parts to numbers when possible ([1, 19, 4, 1]).
29-
# 3. Sort numerically instead of lexographically.
30-
# 4. Restore the original name of each version.
31-
versions_sorted=$(jq --slurp <<< "$versions" '
32-
[ .[]
33-
| { original: .,
34-
numeric:
35-
.
36-
| ltrimstr("v")
37-
| split("(-|\\.|\\+k3s)"; "")
38-
| [ .[] | (tonumber? // .) ]
39-
}
40-
]
41-
| sort_by(.numeric)
42-
| reverse
43-
| .[]
44-
| .original
45-
')
20+
versions_sorted=$(sort <<< "$versions" --field-separator=- --key=1,1rV --key=2,2rV)
4621

4722
echo "::group::All available K3s versions (newest on top)"
4823
echo "$versions_sorted"

0 commit comments

Comments
 (0)