Skip to content

Commit

Permalink
feat: Implement installation for MacOs and Linux (arm64 and x86)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlemaitre committed Sep 7, 2023
1 parent 3c4286c commit 5ed0750
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@

# Contents

- [asdf-scala-cli ](#asdf-scala-cli--)
- [Contents](#contents)
- [Dependencies](#dependencies)
- [Install](#install)
- [Contributing](#contributing)
- [License](#license)

# Dependencies

**TODO: adapt this section**

- `bash`, `curl`, `tar`: generic POSIX utilities.
- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x.
- `bash`, `curl`, `gzip`: generic POSIX utilities.

# Install

Expand Down
9 changes: 3 additions & 6 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ source "${plugin_dir}/lib/utils.bash"

mkdir -p "$ASDF_DOWNLOAD_PATH"

# TODO: Adapt this to proper extension and adapt extracting strategy.
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz"
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME.gz"

# Download tar.gz file to the download directory
download_release "$ASDF_INSTALL_VERSION" "$release_file"

# 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"

# Remove the tar.gz file since we don't need to keep it
rm "$release_file"
# tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file"
(pushd "$ASDF_DOWNLOAD_PATH" && gzip -d "$TOOL_NAME" && chmod +x "$TOOL_NAME" && popd )|| fail "Could not extract $release_file"
3 changes: 1 addition & 2 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Testing Locally:
```shell
asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <version>] [--asdf-plugin-gitref <git-ref>] [test-command*]

# TODO: adapt this
asdf plugin test scala-cli https://github.com/rlemaitre/asdf-scala-cli.git "scala-cli --help"
asdf plugin test scala-cli https://github.com/rlemaitre/asdf-scala-cli.git "scala-cli version"
```

Tests are automatically run in GitHub Actions on push and PR.
27 changes: 18 additions & 9 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

set -euo pipefail

# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for scala-cli.
GH_REPO="https://github.com/VirtusLab/scala-cli"
TOOL_NAME="scala-cli"
TOOL_TEST="scala-cli --help"
TOOL_TEST="scala-cli version"

fail() {
echo -e "asdf-$TOOL_NAME: $*"
Expand All @@ -31,18 +30,29 @@ list_github_tags() {
}

list_all_versions() {
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
# Change this function if scala-cli has other means of determining installable versions.
list_github_tags
}

download_release() {
local version filename url
local version filename url arch os
version="$1"
filename="$2"

# TODO: Adapt the release URL convention for scala-cli
url="$GH_REPO/archive/v${version}.tar.gz"
arch="$(uname -m)"
if [[ "$arch" == 'arm64' ]]; then
arch='aarch64'
else
arch='x86_64'
fi
os="$(uname -s)"
case $os in
'Linux')
url="$GH_REPO/releases/download/v${version}/scala-cli-$arch-pc-linux.gz"
;;
'Darwin')
url="$GH_REPO/releases/download/v${version}/scala-cli-$arch-apple-darwin.gz"
;;
*) ;;
esac

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand All @@ -61,7 +71,6 @@ install_version() {
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"

# TODO: Assert scala-cli 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."
Expand Down

0 comments on commit 5ed0750

Please sign in to comment.