Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Heroku CLI #67

Merged
merged 13 commits into from
Nov 5, 2024
6 changes: 3 additions & 3 deletions src/heroku-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "Heroku CLI (via cli-assets.heroku.com)",
"id": "heroku-cli",
"version": "1.0.2",
"description": "Heroku CLI allows you to interact with the Heroku API via the command line",
"version": "1.0.3",
"description": "Heroku CLI allows you to interact with the Heroku API via the command line (version 8 and above)",
"documentationURL": "https://github.com/devcontainers-extra/features/tree/main/src/heroku-cli",
"options": {
"version": {
"type": "string",
"proposals": [
"latest",
"7.60.1"
"9.3.2"
],
"default": "latest",
"description": "Select the Heroku CLI version you would like to install"
Expand Down
17 changes: 13 additions & 4 deletions src/heroku-cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ if [ "$ARCH" == "x86_64" ]; then
ARCH=x64
elif [[ "$ARCH" == aarch* ]]; then
ARCH=arm
elif [[ "$ARCH" == "arm64" ]]; then
ARCH=arm64
else
echo -e "unsupported arch: $ARCH"
exit 1
Expand All @@ -39,7 +41,7 @@ check_packages() {
}

# make sure we have curl
check_packages ca-certificates curl
check_packages ca-certificates curl jq

# make sure /usr/local/lib exists
mkdir -p /usr/local/lib
Expand All @@ -50,11 +52,18 @@ rm -rf ~/.local/share/heroku/client
rm -f $(command -v heroku) || true
rm -f /usr/local/bin/heroku

# resolve download url based on version, this is not documented and prune to break if heroku change their naming convensions
# resolve heroku download url with asset JSON: https://github.com/heroku/cli/issues/2477
# works with version 8 and up
if [ "${HEROKU_CLI_VERSION}" == "latest" ]; then
DOWNLOAD_URL=https://cli-assets.heroku.com/heroku-linux-$ARCH.tar.gz
DOWNLOAD_URL=https://cli-assets.heroku.com/channels/stable/heroku-linux-$ARCH.tar.gz
else
DOWNLOAD_URL=https://cli-assets.heroku.com/heroku-v${HEROKU_CLI_VERSION}/heroku-v${HEROKU_CLI_VERSION}-linux-${ARCH}.tar.gz
ASSET_PATH_URL=https://cli-assets.heroku.com/versions/heroku-linux-${ARCH}-tar-gz.json
DOWNLOAD_URL=$(curl -sSL $ASSET_PATH_URL | jq -r ".[\"$HEROKU_CLI_VERSION\"] | select(.)")

if [ -z "$DOWNLOAD_URL" ]; then
echo "Invalid version and arch: $HEROKU_CLI_VERSION, $ARCH"
exit 1
fi
fi

# download binary, untar and ln into /usr/local/bin
Expand Down
8 changes: 8 additions & 0 deletions test/heroku-cli/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
"features": {
"heroku-cli": {}
}
},
"test_non_latest_version": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"heroku-cli": {
"version": "9.3.1"
}
}
}
}
2 changes: 1 addition & 1 deletion test/heroku-cli/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ set -e

source dev-container-features-test-lib

check "heroku existance" heroku version
check "heroku existence" heroku version

reportResults
10 changes: 10 additions & 0 deletions test/heroku-cli/test_non_latest_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

source dev-container-features-test-lib

check "heroku existence" heroku version
check "heroku CLI version is equal to 9.3.1" sh -c "heroku version | grep '9.3.1'"

reportResults
Loading