Skip to content

Commit

Permalink
update download
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Brocker committed Jul 19, 2023
1 parent f73c093 commit a67b056
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@v1
with:
command: cloud_sql_proxy --version
command: echo "cloud-sql-proxy is installed"
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

# Dependencies

**TODO: adapt this section**

- `bash`, `curl`, `tar`: generic POSIX utilities.
- `brew`, `install`, `go`: Golang
- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x.

# Install
Expand Down
6 changes: 3 additions & 3 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,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"
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME"

# 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" --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"
# rm "$release_file"
39 changes: 32 additions & 7 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail

# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for cloud-sql-proxy.
GH_REPO="https://github.com/GoogleCloudPlatform/cloud-sql-proxy"
TOOL_NAME="cloud-sql-proxy"
TOOL_NAME="cloud_sql_proxy"
TOOL_TEST="cloud_sql_proxy --version"

fail() {
Expand All @@ -15,9 +15,9 @@ fail() {
curl_opts=(-fsSL)

# NOTE: You might want to remove this if cloud-sql-proxy is not hosted on GitHub releases.
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
fi
# 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/ /' |
Expand All @@ -36,13 +36,37 @@ list_all_versions() {
list_github_tags
}

get_platform() {
local os=$(uname)
if [[ "${os}" == "Darwin" ]]; then
echo "darwin"
elif [[ "${os}" == "Linux" ]]; then
echo "linux"
else
echo >&2 "unsupported os: ${os}" && exit 1
fi
}

get_arch() {
local os=$(uname)
local arch=$(uname -m)
if [[ "${os}" == "Darwin" && "${arch}" == "arm64" ]]; then
echo "arm64"
elif [[ "${os}" == "Linux" && "${arch}" == "aarch64" ]]; then
echo "aarch_64"
elif [[ ("${os}" == "Linux" || "${os}" == "Darwin") && "${arch}" == "x86_64" ]]; then
echo "amd64"
else
echo "${arch}"
fi
}

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

# TODO: Adapt the release URL convention for cloud-sql-proxy
url="$GH_REPO/archive/v${version}.tar.gz"
url="https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v${version}/cloud-sql-proxy.$(get_platform).$(get_arch)"

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

(
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"
cp "$ASDF_DOWNLOAD_PATH/$TOOL_NAME" "$install_path/$TOOL_NAME"
chmod +x "$install_path/$TOOL_NAME"

# TODO: Assert cloud-sql-proxy executable exists.
local tool_cmd
Expand Down

0 comments on commit a67b056

Please sign in to comment.