diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7a3a821..e6c5955 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,3 +20,4 @@ jobs: uses: asdf-vm/actions/plugin-test@v1 with: command: cloud_sql_proxy --version + version: 2.6.0 diff --git a/README.md b/README.md index 4aa6ae5..89b8698 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/download b/bin/download index b104db2..21e734b 100755 --- a/bin/download +++ b/bin/download @@ -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" diff --git a/lib/utils.bash b/lib/utils.bash index e50245e..7a50e68 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -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() { @@ -36,13 +36,36 @@ 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" + 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" @@ -59,7 +82,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