Skip to content

Commit

Permalink
First implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvc committed Aug 23, 2024
1 parent d57e200 commit 2301b82
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 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 Ivan Valdes Castillo

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: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,32 @@

# Dependencies

**TODO: adapt this section**

- `bash`, `curl`, `tar`, and [POSIX utilities](https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html).
- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x.

# Install

Plugin:

```shell
asdf plugin add woodpecker
asdf plugin add woodpecker-cli
# or
asdf plugin add woodpecker https://github.com/ivanvc/asdf-woodpecker.git
asdf plugin add woodpecker-cli https://github.com/ivanvc/asdf-woodpecker.git
```

woodpecker:

```shell
# Show all installable versions
asdf list-all woodpecker
asdf list-all woodpecker-cli

# Install specific version
asdf install woodpecker latest
asdf install woodpecker-cli latest

# Set a version globally (on your ~/.tool-versions file)
asdf global woodpecker latest
asdf global woodpecker-cli latest

# Now woodpecker commands are available
woodpecker --help
# Now woodpecker-cli commands are available
woodpecker-cli --help
```

Check [asdf](https://github.com/asdf-vm/asdf) readme for more instructions on how to
Expand Down
3 changes: 1 addition & 2 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,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"

# 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"
tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" || fail "Could not extract $release_file"

# Remove the tar.gz file since we don't need to keep it
rm "$release_file"
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 woodpecker https://github.com/ivanvc/asdf-woodpecker.git "woodpecker --help"
asdf plugin test woodpecker-cli https://github.com/ivanvc/asdf-woodpecker.git "woodpecker --help"
```

Tests are automatically run in GitHub Actions on push and PR.
39 changes: 28 additions & 11 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 woodpecker.
GH_REPO="https://github.com/woodpecker-ci/woodpecker"
TOOL_NAME="woodpecker"
TOOL_TEST="woodpecker --help"
TOOL_NAME="woodpecker-cli"
TOOL_TEST="woodpecker-cli --help"

fail() {
echo -e "asdf-$TOOL_NAME: $*"
Expand All @@ -14,7 +13,6 @@ fail() {

curl_opts=(-fsSL)

# NOTE: You might want to remove this if woodpecker 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,22 +25,42 @@ 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 woodpecker has other means of determining installable versions.
list_github_tags
}

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

# TODO: Adapt the release URL convention for woodpecker
url="$GH_REPO/archive/v${version}.tar.gz"
case "$(uname -s)" in
Linux)
os=linux
;;
Darwin)
os=darwin
;;
*)
fail "OS not supported $(uname -s)"
;;
esac
case "$(uname -m)" in
x86_64)
arch=amd64
;;
aarch64)
arch=arm64
;;
*)
fail "Architecture not supported $(uname -m)"
;;
esac

url="$GH_REPO/releases/download/v$version/woodpecker-cli_${os}_$arch.tar.gz"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand All @@ -61,7 +79,6 @@ install_version() {
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"

# TODO: Assert woodpecker 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 2301b82

Please sign in to comment.