Skip to content

Commit

Permalink
feat: creates asdf-yamlscript plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
FeryET committed Mar 14, 2024
1 parent 2075247 commit 5d656b6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 27 deletions.
4 changes: 1 addition & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
TODO: INSERT YOUR NAME COPYRIGHT YEAR (if applicable to your license)

MIT License

Copyright (c) [year] [fullname]
Copyright (c) 2024 Farhood Etaati

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
17 changes: 9 additions & 8 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.
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"
for tool_name in 'libyamlscript' 'ys'; do
filename="$(get_archive_name "$ASDF_INSTALL_VERSION" "$tool_name")"
release_file="$ASDF_DOWNLOAD_PATH/$filename"
download_release "$ASDF_INSTALL_VERSION" "$filename" "$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"
# Extract contents of tar.gz file into the download directory
tar -xf "$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"
# Remove the tar.gz file since we don't need to keep it
rm "$release_file"
done
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 <YOUR TOOL> https://github.com/<YOUR GITHUB USERNAME>/asdf-<YOUR TOOL>.git "<TOOL CHECK>"
asdf plugin test asdf https://github.com/<YOUR GITHUB USERNAME>/asdf-<YOUR TOOL>.git "<TOOL CHECK>"
```

Tests are automatically run in GitHub Actions on push and PR.
55 changes: 41 additions & 14 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 <YOUR TOOL>.
GH_REPO="<TOOL REPO>"
TOOL_NAME="<YOUR TOOL>"
TOOL_TEST="<TOOL CHECK>"
GH_REPO="https://github.com/yaml/yamlscript"
TOOL_NAME="yamlscript"
TOOL_TEST="ys --version"

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

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

get_os() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
if [ "$os" == "darwin" ]; then
os=macos
fi
echo "$os"
}

get_arch() {
arch=$(uname -m | tr '[:upper:]' '[:lower:]')
case $arch in
x86_64)
echo "x64"
;;
aarch64 | arm64)
echo "aarch64"
;;
*)
exit 1
;;
esac
}

get_archive_name() {
local version pkg_name
version="$1"
pkg_name="$2"
echo "$pkg_name-$version-$(get_os)-$(get_arch).tar.xz"
}

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

# TODO: Adapt the release URL convention for <YOUR TOOL>
url="$GH_REPO/archive/v${version}.tar.gz"

filepath="$3"
url="$GH_REPO/releases/download/$version/$filename"
if [[ -n $DEBUG ]]; then
echo "Filename is: $filename"
echo "Downloading from $url"
fi
echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
curl "${curl_opts[@]}" -o "$filepath" -C - "$url" || fail "Could not download $url"
}

install_version() {
Expand All @@ -60,8 +89,6 @@ install_version() {
(
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"

# TODO: Assert <YOUR TOOL> 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 5d656b6

Please sign in to comment.