Skip to content

Commit

Permalink
tidies up project
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanrayboss committed Jul 23, 2023
1 parent d6023b6 commit 1c8b4ed
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 85 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
- [Contributing](#contributing)
- [License](#license)

# Dependencies

This plugin depends on common POSIX utilities (awk, grep, sed, etc.), Bash, Git, and Go. If you have a Go toolchain installed and selected via asdf (asdf current golang), it will be used to retrieve and build oapi-codegen. Otherwise, asdf will be used to retrieve the latest Go version and that will be used for the build.

# Install

Plugin:

```shell
asdf plugin add oapi-codegen
# or
asdf plugin add oapi-codegen https://github.com/dylanrayboss/asdf-oapi-codegen.git
```

Expand Down
26 changes: 4 additions & 22 deletions bin/download
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
#!/usr/bin/env bash
#!/bin/sh

set -euo pipefail

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

# shellcheck source=../lib/utils.bash
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"

# 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"
# oapi-codegen does not make binary releases. The install script runs `go install`
# to retrieve the tool's source, build it, and install it; there is no discrete
# "download" step.
3 changes: 3 additions & 0 deletions bin/help.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

echo "go"
2 changes: 1 addition & 1 deletion bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ plugin_dir=$(dirname "$(dirname "$current_script_path")")
# shellcheck source=../lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

install_version "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
install_version "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
29 changes: 0 additions & 29 deletions bin/latest-stable

This file was deleted.

2 changes: 1 addition & 1 deletion bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ plugin_dir=$(dirname "$(dirname "$current_script_path")")
# shellcheck source=../lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

list_all_versions | sort_versions | xargs echo
list_all_versions | sort_versions | xargs echo
39 changes: 9 additions & 30 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,29 @@
set -euo pipefail

# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for oapi-codegen.
GO_INSTALL="github.com/deepmap/oapi-codegen/cmd/oapi-codegen"
GO_PACKAGE="github.com/deepmap/oapi-codegen/cmd/oapi-codegen"
GH_REPO="https://github.com/deepmap/oapi-codegen"
TOOL_NAME="oapi-codegen"
TOOL_TEST="oapi-codegen --version"

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

curl_opts=(-fsSL)

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

sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}

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 oapi-codegen 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 oapi-codegen
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"
list_github_tags
}

install_version() {
Expand Down Expand Up @@ -82,7 +61,7 @@ install_version() {
# normal, except that we'll dump the binary into the install path instead
# of $GOPATH/bin.
export GOBIN="$install_path"
go install "$GO_INSTALL"@"$version" || fail "An error occurred while installing $TOOL_NAME $version."
go install "$GO_PACKAGE"@"$version" || fail "An error occurred while installing $TOOL_NAME $version."

local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
Expand All @@ -93,4 +72,4 @@ install_version() {
rm -rf "$install_path"
fail "An error occurred while installing $TOOL_NAME $version."
)
}
}
Empty file added version.txt
Empty file.

0 comments on commit 1c8b4ed

Please sign in to comment.