22
33set -euo pipefail
44
5- # TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for codon .
6- GH_REPO=" https://github.com/3w36zj6 /codon"
5+ # Codon upstream repository .
6+ GH_REPO=" https://github.com/exaloop /codon"
77TOOL_NAME=" codon"
88TOOL_TEST=" codon --help"
99
@@ -24,47 +24,135 @@ sort_versions() {
2424 LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk ' {print $2}'
2525}
2626
27- list_github_tags () {
28- git ls-remote --tags --refs " $GH_REPO " |
29- grep -o ' refs/tags/.*' | cut -d/ -f3- |
30- sed ' s/^v//' # NOTE: You might want to adapt this sed to remove non-version strings from tags
27+ resolve_version () {
28+ local version
29+ version=" $1 "
30+ if [[ " $version " == " latest" ]]; then
31+ version=" $( list_all_versions | sort_versions | tail -n1 | xargs echo) "
32+ if [ -z " $version " ]; then
33+ fail " Could not determine the latest $TOOL_NAME version."
34+ fi
35+ fi
36+ printf " %s\n" " $version "
37+ }
38+
39+ get_os () {
40+ local os
41+ os=" $( uname -s | awk ' {print tolower($0)}' ) "
42+ case " $os " in
43+ linux | darwin)
44+ printf " %s\n" " $os "
45+ ;;
46+ * )
47+ fail " Pre-built binaries only exist for Linux and macOS. Detected OS: $os "
48+ ;;
49+ esac
50+ }
51+
52+ get_arch () {
53+ local arch
54+ arch=" $( uname -m) "
55+ case " $arch " in
56+ x86_64 | aarch64)
57+ printf " %s\n" " $arch "
58+ ;;
59+ amd64)
60+ printf " %s\n" " x86_64"
61+ ;;
62+ arm64)
63+ printf " %s\n" " aarch64"
64+ ;;
65+ * )
66+ fail " Unsupported architecture for pre-built Codon binaries: $arch "
67+ ;;
68+ esac
69+ }
70+
71+ determine_asset_arch () {
72+ local os arch
73+ os=" $1 "
74+ arch=" $2 "
75+ if [[ " $os " == " darwin" && " $arch " == " aarch64" ]]; then
76+ printf " arm64\n"
77+ else
78+ printf " %s\n" " $arch "
79+ fi
80+ }
81+
82+ normalize_tag () {
83+ local version
84+ version=" $1 "
85+ if [[ " $version " == v* ]]; then
86+ printf " %s\n" " $version "
87+ else
88+ printf " v%s\n" " $version "
89+ fi
90+ }
91+
92+ list_github_releases () {
93+ local page url
94+ page=1
95+ while : ; do
96+ url=" https://api.github.com/repos/exaloop/codon/releases?per_page=100&page=$page "
97+
98+ # Extract tag_name values without requiring jq.
99+ # Example: "tag_name": "v0.18.0"
100+ local tags
101+ tags=" $( curl " ${curl_opts[@]} " " $url " |
102+ grep -oE ' "tag_name"[[:space:]]*:[[:space:]]*"[^"]+"' |
103+ sed -E ' s/.*"tag_name"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/' || true) "
104+
105+ if [ -z " $tags " ]; then
106+ break
107+ fi
108+
109+ printf " %s\n" " $tags "
110+ page=$(( page + 1 ))
111+ done
31112}
32113
33114list_all_versions () {
34- # TODO: Adapt this. By default we simply list the tag names from GitHub releases.
35- # Change this function if codon has other means of determining installable versions.
36- list_github_tags
115+ # Codon versions are published as GitHub Releases.
116+ # Output versions without the leading "v" (asdf convention).
117+ list_github_releases |
118+ sed ' s/^v//' |
119+ grep -E ' ^[0-9]'
37120}
38121
39122download_release () {
40- local version filename url
123+ local version filename url resolved_version
41124 version=" $1 "
42125 filename=" $2 "
43-
44- # TODO: Adapt the release URL convention for codon
45- url=" $GH_REPO /archive/v${version} .tar.gz"
46-
47- echo " * Downloading $TOOL_NAME release $version ..."
126+ local os arch tag asset
127+ resolved_version=" $( resolve_version " $version " ) "
128+ os=" $( get_os) "
129+ arch=" $( get_arch) "
130+ tag=" $( normalize_tag " $resolved_version " ) "
131+ local asset_arch
132+ asset_arch=" $( determine_asset_arch " $os " " $arch " ) "
133+ asset=" codon-$os -$asset_arch .tar.gz"
134+ url=" $GH_REPO /releases/download/$tag /$asset "
135+
136+ echo " * Downloading $TOOL_NAME release $resolved_version ..."
48137 curl " ${curl_opts[@]} " -o " $filename " -C - " $url " || fail " Could not download $url "
49138}
50139
51140install_version () {
52141 local install_type=" $1 "
53142 local version=" $2 "
54- local install_path=" ${3 %/ bin} /bin "
143+ local install_path=" $3 "
55144
56145 if [ " $install_type " != " version" ]; then
57146 fail " asdf-$TOOL_NAME supports release installs only"
58147 fi
59148
60149 (
61150 mkdir -p " $install_path "
62- cp -r " $ASDF_DOWNLOAD_PATH " /* " $install_path "
151+ cp -r " $ASDF_DOWNLOAD_PATH " /* " $install_path / "
63152
64- # TODO: Assert codon executable exists.
65153 local tool_cmd
66154 tool_cmd=" $( echo " $TOOL_TEST " | cut -d' ' -f1) "
67- test -x " $install_path /$tool_cmd " || fail " Expected $install_path /$tool_cmd to be executable."
155+ test -x " $install_path /bin/ $tool_cmd " || fail " Expected $install_path /bin /$tool_cmd to be executable."
68156
69157 echo " $TOOL_NAME $version installation was successful!"
70158 ) || (
0 commit comments