Skip to content

Commit

Permalink
Merge pull request #5 from robzr/customize
Browse files Browse the repository at this point in the history
feat: add customizations for scie-pants
  • Loading branch information
robzr committed Feb 9, 2024
2 parents da2fe27 + f0a99a4 commit 65fcb11
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ jobs:
- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@v2
with:
command: scie-pants --help
command: |
echo -e '[GLOBAL]\npants_version = "2.19.0"' > pants.toml
scie-pants help
45 changes: 38 additions & 7 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@

set -euo pipefail

# shellcheck disable=SC2317
function fail() {
echo -e "asdf-$TOOL_NAME: $*" >&2
exit 1
}

function calculate_arch() {
local arch

arch="$(uname -m)"
if [[ "${arch}" =~ x86[_-]64 ]]; then
echo x86_64
elif [[ "${arch}" =~ arm64|aarch64 ]]; then
echo aarch64
else
fail "Pants is not supported for this chip architecture (${arch})."
fi
}

function calculate_os() {
local os

os="$(uname -s)"
if [[ "${os}" =~ [Ll]inux ]]; then
echo linux
elif [[ "${os}" =~ [Dd]arwin ]]; then
echo macos
else
fail "Pants is not supported on this operating system (${os})."
fi
}

current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

Expand All @@ -10,14 +42,13 @@ 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"
ARCH=$(calculate_arch)
OS=$(calculate_os)

release_file="$ASDF_DOWNLOAD_PATH/scie-pants-${OS}-${ARCH}"

# 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"
release_file_target="$ASDF_DOWNLOAD_PATH/scie-pants"

# Remove the tar.gz file since we don't need to keep it
rm "$release_file"
mv "$release_file" "$release_file_target"
10 changes: 3 additions & 7 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

set -euo pipefail

# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for scie-pants.
GH_REPO="https://github.com/pantsbuild/scie-pants"
TOOL_NAME="scie-pants"
TOOL_TEST="scie-pants --help"
Expand All @@ -14,7 +13,6 @@ fail() {

curl_opts=(-fsSL)

# NOTE: You might want to remove this if scie-pants is not hosted on GitHub releases.
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
fi
Expand All @@ -27,12 +25,10 @@ sort_versions() {
list_github_tags() {
git ls-remote --tags --refs "$GH_REPO" |
grep -o 'refs/tags/.*' | cut -d/ -f3- |
sed 's/^v//' # NOTE: You might want to adapt this sed to remove non-version strings from tags
sed 's/^v//'
}

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

Expand All @@ -41,11 +37,11 @@ download_release() {
version="$1"
filename="$2"

# TODO: Adapt the release URL convention for scie-pants
url="$GH_REPO/archive/v${version}.tar.gz"
url="${GH_REPO}/releases/download/v${version}/${filename##*/}"

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

install_version() {
Expand Down

0 comments on commit 65fcb11

Please sign in to comment.