Skip to content

Commit d10eb88

Browse files
committed
feat: resolves latest version
1 parent caf2b12 commit d10eb88

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

src/asdf/install.sh

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ get_arch() {
1919
echo "$ARCH"
2020
}
2121

22+
get_latest_version() {
23+
# Get the latest version from GitHub API
24+
curl -fsSL https://api.github.com/repos/asdf-vm/asdf/releases/latest | \
25+
grep '"tag_name":' | \
26+
sed -E 's/.*"tag_name": "([^"]+)".*/\1/'
27+
}
28+
2229
check_version() {
2330
local VERSION="${1:-latest}"
2431
case "${VERSION}" in
2532
latest)
26-
# TODO: we should resolve it instead of harcoding it
27-
echo "v0.18.0"
33+
get_latest_version
2834
;;
2935
*)
3036
if [[ "$VERSION" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$ ]]; then
@@ -52,20 +58,23 @@ check_alpine_packages() {
5258

5359
install_asdf() {
5460
local GIVEN_VERSION="${1:-latest}"
55-
local ARCH="$(get_arch)"
56-
local VERSION="$(check_version "${GIVEN_VERSION}")"
57-
58-
echo "+ installing asdf version=$VERSION arch=$ARCH"
61+
local ARCH
62+
local VERSION
5963

60-
# install git and curl if does not exists
64+
# install needed deps
6165
if cat /etc/os-release | grep "ID_LIKE=.*alpine.*\|ID=.*alpine.*" ; then
6266
check_alpine_packages git bash curl ca-certificates bash-completion
6367
elif cat /etc/os-release | grep "ID_LIKE=.*debian.*\|ID=.*debian.*"; then
6468
check_packages git bash curl ca-certificates bash-completion
6569
fi
6670

67-
# asdf may be installed somewhere on the machine, but we need it to be accessible to the remote user
68-
# the code bellow will return 2 only when asdf is available, and 1 otherwise
71+
ARCH="$(get_arch)"
72+
VERSION="$(check_version "${GIVEN_VERSION}")"
73+
74+
echo "+ installing asdf version=$VERSION arch=$ARCH"
75+
76+
# check if asdf is installed and acessible for the remote user
77+
# the code bellow will return 2 only when asdf is available, and 1 otherwise
6978
set +e
7079
su - "$_REMOTE_USER" <<EOF
7180
if type asdf >/dev/null 2>&1; then
@@ -111,5 +120,5 @@ updaterc() {
111120
}
112121

113122
# main
114-
echo "+ installing asdf"
115-
install_asdf $ASDF_VERSION
123+
echo "+ installing asdf (version ${ASDF_VERSION})"
124+
install_asdf $ASDF_VERSION || exit 1

0 commit comments

Comments
 (0)