Skip to content

Commit

Permalink
Use zip files for prebuilt duckdb binary
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseStimpson committed Jun 15, 2023
1 parent d943dc5 commit d15f9d9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 15 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Test
on:
push:
branches:
- main
pull_request:

jobs:
plugin_test:
name: asdf plugin test
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@v2
with:
command: "duckdb --version"
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

# 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.
- `bash`, `curl`, `unzip`: generic POSIX utilities.

# Install

Expand Down
6 changes: 3 additions & 3 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ 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"
# duckdb provides zip files instead of tar.gz
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.zip"

# 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"
unzip "$release_file" -d "$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 duckdb https://github.com/JesseStimpson/asdf-duckdb.git "duckdb --version"
asdf plugin test duckdb https://github.com/JesseStimpson/asdf-duckdb.git --asdf-plugin-gitref main "duckdb --version"
```

Tests are automatically run in GitHub Actions on push and PR.
40 changes: 34 additions & 6 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -euo pipefail

# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for duckdb.
# This is the GitHub homepage where releases can be downloaded for duckdb.
GH_REPO="https://github.com/duckdb/duckdb"
TOOL_NAME="duckdb"
TOOL_TEST="duckdb --version"
Expand Down Expand Up @@ -31,7 +31,7 @@ list_github_tags() {
}

list_all_versions() {
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
# By default we simply list the tag names from GitHub releases.
# Change this function if duckdb has other means of determining installable versions.
list_github_tags
}
Expand All @@ -41,8 +41,7 @@ download_release() {
version="$1"
filename="$2"

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

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand All @@ -59,9 +58,8 @@ install_version() {

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

# TODO: Assert duckdb 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 All @@ -72,3 +70,33 @@ install_version() {
fail "An error occurred while installing $TOOL_NAME $version."
)
}

get_url() {
# duckdb provides:
# os: linux | osx | windows
# arch:
# linux: aarch64 | amd64 | i386
# osx: universal
# windows: amd64 | i386
local os arch
if [ "$(uname)" == "Linux" ]; then
os="linux"
if [ "$(uname -m)" == "x86_64" ]; then
arch="amd64"
elif [ "$(uname -m)" == "arm*"]; then
# Warning: untested
arch="aarch64"
elif [ "$(uname -m)" == "aarch*"]; then
# Warning: untested
arch="aarch64"
else
# Warning: untested
arch="i386"
fi
elif [ "$(uname)" == "Darwin" ]; then
os="osx"
arch="universal"
fi
# asdf-duckdb plugin does not support windows
echo "$GH_REPO/releases/download/v${version}/duckdb_cli-${os}-${arch}.zip"
}

0 comments on commit d15f9d9

Please sign in to comment.