Skip to content

Commit

Permalink
Initial creation of plugin for spruce
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill ONeill authored and woneill committed May 7, 2021
1 parent fe6fb1c commit a01e87a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@v1
with:
command: spruce --help
command: spruce --version
2 changes: 0 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:
uses: actions/checkout@v2
- name: asdf_install
uses: asdf-vm/actions/install@v1
with:
before_install: bash -c '${ASDF_DATA_DIR:=$HOME/.asdf}/plugins/nodejs/bin/import-release-team-keyring'
- name: Shellcheck
run: shellcheck -x bin/* -P lib/
- name: Shell Format - List files to check
Expand Down
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shellcheck 0.7.1
shfmt 3.2.2
10 changes: 2 additions & 8 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ source "$(dirname "$0")/../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"

# Download tar.gz file to the download directory
# Download 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"
22 changes: 10 additions & 12 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 spruce.
GH_REPO="https://github.com/geofffranks/spruce"
TOOL_NAME="spruce"
TOOL_TEST="spruce --help"
TOOL_TEST="--version"

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

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

download_release() {
local version filename url
version="$1"
filename="$2"
platform="$(uname | tr '[:upper:]' '[:lower:]')"

# TODO: Adapt the release URL convention for spruce
url="$GH_REPO/archive/v${version}.tar.gz"
# Adapt the release URL convention for spruce
# https://github.com/geofffranks/spruce/releases/download/v1.27.0/spruce-darwin-amd64
url="$GH_REPO/releases/download/v${version}/${TOOL_NAME}-${platform}-amd64"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
chmod a+x "$filename"
}

install_version() {
Expand All @@ -58,13 +58,11 @@ install_version() {
fi

(
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"
mkdir -p "$install_path"/bin
cp -pr "$ASDF_DOWNLOAD_PATH"/* "$install_path"/bin/

# TODO: Asert spruce executable exists.
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/bin/$tool_cmd" || fail "Expected $install_path/bin/$tool_cmd to be executable."
test -x "$install_path/bin/$TOOL_NAME" || fail "Expected $install_path/bin/$TOOL_NAME to be executable."
tool_version=$("$install_path"/bin/$TOOL_NAME $TOOL_TEST) && test "${tool_version##*\ }" = "$version" || fail "Expected $install_path/bin/$TOOL_NAME to be version $version but got ${tool_version##*\ }."

echo "$TOOL_NAME $version installation was successful!"
) || (
Expand Down

0 comments on commit a01e87a

Please sign in to comment.