From 1f57bbc60280185183e6368cf3baf54ff86b43f5 Mon Sep 17 00:00:00 2001 From: "Nurul Huda (Apon)" Date: Sun, 7 Jul 2024 14:37:41 +0600 Subject: [PATCH] fix: update download and install script --- .gitignore | 1 + bin/download | 9 +++++---- contributing.md | 6 ++++++ lib/utils.bash | 35 ++++++++++++++++++++++++++++++++--- 4 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53c37a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist \ No newline at end of file diff --git a/bin/download b/bin/download index c11ee53..71eb6ee 100755 --- a/bin/download +++ b/bin/download @@ -10,14 +10,15 @@ source "${plugin_dir}/lib/utils.bash" mkdir -p "$ASDF_DOWNLOAD_PATH" -# TODO: Adapt this to proper extension and adapt extracting strategy. +platform=$( get_platform ) release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz" # Download tar.gz file to the download directory -download_release "$ASDF_INSTALL_VERSION" "$release_file" +download_release "$ASDF_INSTALL_VERSION" "$release_file" "$platform" # Extract contents of tar.gz file into the download directory -tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file" +tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" || fail "Could not extract $release_file" +echo "Extracted $release_file to $ASDF_DOWNLOAD_PATH" # Remove the tar.gz file since we don't need to keep it -rm "$release_file" +rm "$release_file" \ No newline at end of file diff --git a/contributing.md b/contributing.md index de473c1..4769ab2 100644 --- a/contributing.md +++ b/contributing.md @@ -7,6 +7,12 @@ asdf plugin test [--asdf-tool-version ] [--a # TODO: adapt this asdf plugin test sst https://github.com/nurulhudaapon/asdf-sst.git "sst version" + +# Local Test Download +ASDF_DOWNLOAD_PATH="./dist" ASDF_INSTALL_VERSION=0.0.489 bash bin/download + +# Local Test Install +ASDF_DOWNLOAD_PATH="./dist" ASDF_INSTALL_VERSION=0.0.489 ASDF_INSTALL_PATH="./dist" ASDF_INSTALL_TYPE="version" bash bin/install ``` Tests are automatically run in GitHub Actions on push and PR. diff --git a/lib/utils.bash b/lib/utils.bash index ff0f965..cc0d017 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -40,9 +40,9 @@ download_release() { local version filename url version="$1" filename="$2" + platform="$3" - # TODO: Adapt the release URL convention for sst - url="$GH_REPO/archive/v${version}.tar.gz" + url="$GH_REPO/releases/download/v${version}/${platform}.tar.gz" echo "* Downloading $TOOL_NAME release $version..." curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url" @@ -64,7 +64,7 @@ install_version() { # TODO: Assert sst executable exists. local tool_cmd tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)" - # test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable." + test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable." echo "$TOOL_NAME $version installation was successful!" ) || ( @@ -72,3 +72,32 @@ install_version() { fail "An error occurred while installing $TOOL_NAME $version." ) } + +get_platform() { + os=$(uname -s | tr '[:upper:]' '[:lower:]') + if [[ "$os" == "darwin" ]]; then + os="mac" + fi + arch=$(uname -m) + + if [[ "$arch" == "aarch64" ]]; then + arch="arm64" + fi + + platform="$TOOL_NAME-$os-$arch" + + case "$platform" in + *"-linux-"*) + [[ "$arch" == "x86_64" || "$arch" == "arm64" || "$arch" == "i386" ]] || exit 1 + ;; + *"-mac-"*) + [[ "$arch" == "x86_64" || "$arch" == "arm64" ]] || exit 1 + ;; + *) + echo "${RED}Unsupported OS/Arch: $os/$arch${NC}" + exit 1 + ;; + esac + + echo "$platform" +} \ No newline at end of file