Skip to content

Commit

Permalink
feat: initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
airtonix committed Oct 12, 2022
1 parent 2e2c8d2 commit 9d5dad4
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v2
- uses: GoogleCloudPlatform/release-please-action@v3
with:
release-type: simple
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

## 1.0.0 (2022-10-12)


### Features

* initial implementation ([7f3b84e](https://github.com/airtonix/asdf-patat/commit/7f3b84eb139c4ab0ebcd20c4ac8f8a57969c6f36))

## 1.0.0 (2022-10-12)


### Features

* initial implementation ([c4932a6](https://www.github.com/airtonix/asdf-patat/commit/c4932a6164852cbe0a7d9a73b5065151978972db))
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

MIT License

Copyright (c) [year] [fullname]
Copyright (c) 2022 Zenobius Jiricek

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
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
- [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.

# Install

Plugin:
Expand Down
1 change: 0 additions & 1 deletion bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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
Expand Down
66 changes: 43 additions & 23 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

set -euo pipefail

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

fail() {
echo -e "asdf-$TOOL_NAME: $*"
echo -e "asdf-${TOOL_NAME}: $*"
exit 1
}

curl_opts=(-fsSL)

# NOTE: You might want to remove this if patat is not hosted on GitHub releases.
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
curl_opts=("${curl_opts[@]}" -H "Authorization: token ${GITHUB_API_TOKEN}")
fi

sort_versions() {
Expand All @@ -25,50 +24,71 @@ sort_versions() {
}

list_github_tags() {
git ls-remote --tags --refs "$GH_REPO" |
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
}

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

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

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

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
processor=$(get_machine_processor)
os=$(get_machine_os)
extension=$(get_release_archive_extension)

[ -f "${filename}" ] || {
url="${GH_REPO}/releases/download/v${version}/${TOOL_NAME}-v${version}-${os}-${processor}.${extension}"
echo "* Downloading ${TOOL_NAME} release ${version} (${os}-${processor})..."
curl "${curl_opts[@]}" -o "${filename}" -C - "${url}" || fail "Could not download ${url}"
}
}

install_version() {
local install_type="$1"
local version="$2"
local install_path="${3%/bin}/bin"

if [ "$install_type" != "version" ]; then
fail "asdf-$TOOL_NAME supports release installs only"
if [ "${install_type}" != "version" ]; then
fail "asdf-${TOOL_NAME} supports release installs only"
fi

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

# TODO: Assert patat executable exists.
mkdir -p "${install_path}"
cp -r "${ASDF_DOWNLOAD_PATH}"/* "${install_path}"
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."
tool_cmd="$(echo "${TOOL_TEST}" | cut -d' ' -f1)"
test -x "${install_path}/${tool_cmd}" || fail "Expected ${install_path}/${tool_cmd} to be executable."

echo "$TOOL_NAME $version installation was successful!"
echo "${TOOL_NAME} ${version} installation was successful!"
) || (
rm -rf "$install_path"
fail "An error occurred while installing $TOOL_NAME $version."
rm -rf "${install_path}"
fail "An error occurred while installing ${TOOL_NAME} ${version}."
)
}

get_machine_os() {
case "${OSTYPE}" in
darwin*) echo "darwin" ;;
linux*) echo "linux" ;;
*) echo "${OSTYPE}" ;;
esac
}

get_machine_processor() {
uname -m
}

get_release_archive_extension() {
os=$(get_machine_os)
processor=$(get_machine_processor)

case "${os}_${processor}" in
darwin*) echo "zip" ;;
*) echo "tar.gz" ;;
esac
}
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0

0 comments on commit 9d5dad4

Please sign in to comment.