Skip to content

Commit

Permalink
fix: update download and install script
Browse files Browse the repository at this point in the history
  • Loading branch information
nurulhudaapon committed Jul 7, 2024
1 parent d8de179 commit 1f57bbc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
9 changes: 5 additions & 4 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 6 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <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.
35 changes: 32 additions & 3 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -64,11 +64,40 @@ 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!"
) || (
rm -rf "$install_path"
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"
}

0 comments on commit 1f57bbc

Please sign in to comment.