install-stackit-cli/action.yml
Maximilian Jugl f1cd1be14d
Some checks failed
Test action / Test on registry.onstackit.cloud/devex-images/alpine:latest (push) Failing after 3s
Test action / Test on registry.onstackit.cloud/devex-images/ubuntu:act-latest (push) Successful in 34s
feat: initial
2026-04-22 09:36:58 +02:00

143 lines
4.8 KiB
YAML

name: "Install STACKIT CLI"
description: "Installs the STACKIT CLI application."
inputs:
version:
description: "Version of STACKIT CLI to install, e.g. v0.59.0. If left empty, the latest version will be installed."
required: false
default: ""
runs:
using: "composite"
steps:
- name: Install requirements
shell: sh # alpine may not have bash pre-installed
run: |
set -e
if command -v curl >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then
echo "curl and jq are already installed, skipping installation."
else
if command -v apt-get >/dev/null 2>&1; then
apt-get -y update
apt-get -y install curl jq
elif command -v apk >/dev/null 2>&1; then
apk add --no-cache curl jq bash
else
echo "::error::No supported package manager (apt-get, apk) found."
exit 1
fi
fi
- name: Install STACKIT CLI
shell: bash
env:
STACKIT_CLI_VERSION: ${{ inputs.version }}
run: |
set -eo pipefail
REPO="stackitcloud/stackit-cli"
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
if [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then
ARCH="amd64"
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
ARCH="arm64"
fi
CACHE_BASE="${RUNNER_TOOL_CACHE:-/opt/hostedtoolcache}/stackit-cli"
# try to load stackit cli from hosted tools cache
if [ -n "$STACKIT_CLI_VERSION" ]; then
TOOL_CACHE_FILE="$CACHE_BASE/$STACKIT_CLI_VERSION/$ARCH/stackit"
# if file exists in hosted tools cache, symlink it
if [ -x "$TOOL_CACHE_FILE" ]; then
echo "::group::Linking from hosted tool cache"
ln -sf "$TOOL_CACHE_FILE" /usr/local/bin/stackit
echo "::endgroup::"
exit 0
fi
fi
echo "::group::Determining STACKIT CLI version"
# if no version is provided, use latest
if [ -z "$STACKIT_CLI_VERSION" ]; then
API_URL="https://api.github.com/repos/$REPO/releases/latest"
else
API_URL="https://api.github.com/repos/$REPO/releases/tags/$STACKIT_CLI_VERSION"
fi
RELEASES_JSON="$(curl -s "$API_URL")"
VERSION="$(echo "$RELEASES_JSON" | jq -r '.tag_name')"
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
echo "Failed to fetch release information. Please check if the version exists."
exit 1
fi
echo "Installing STACKIT CLI $VERSION"
echo "::endgroup::"
# check if latest binary is already present on this runner
TOOL_CACHE_DIR="$CACHE_BASE/$VERSION/$ARCH"
TOOL_CACHE_FILE="$TOOL_CACHE_DIR/stackit"
if [ -x "$TOOL_CACHE_FILE" ]; then
echo "::group::Linking from hosted tool cache"
ln -sf "$TOOL_CACHE_FILE" /usr/local/bin/stackit
echo "::endgroup::"
exit 0
fi
# prepare binary download
DOWNLOAD_DIR="$(mktemp -d)"
# always delete download dir when script exits
trap 'rm -rf "$DOWNLOAD_DIR"' EXIT
cd "$DOWNLOAD_DIR"
RELEASE_ASSET="$(echo "$RELEASES_JSON" | jq -r --arg os "$OS" --arg arch "$ARCH" \
'.assets[] | select(.name | endswith($os + "_" + $arch + ".tar.gz"))')"
if [ -z "$RELEASE_ASSET" ] || [ "$RELEASE_ASSET" = "null" ]; then
echo "No matching release found for OS=$OS, ARCH=$ARCH."
exit 1
fi
ARCHIVE_NAME="$(echo "$RELEASE_ASSET" | jq -r '.name')"
ARCHIVE_DOWNLOAD_URL="$(echo "$RELEASE_ASSET" | jq -r '.browser_download_url')"
CHECKSUMS_DOWNLOAD_URL="$(echo "$RELEASES_JSON" | jq -r '.assets[] | select(.name | contains("checksums.txt")) | .browser_download_url')"
CHECKSUMS="checksums.txt"
if [ -z "$CHECKSUMS_DOWNLOAD_URL" ] || [ "$CHECKSUMS_DOWNLOAD_URL" = "null" ]; then
echo "No checksum file available in release assets."
exit 1
fi
echo "::group::Downloading assets and verifying integrity"
# download binary and checksums (-f for fail fast)
curl -fLO "$ARCHIVE_DOWNLOAD_URL"
curl -fLo "$CHECKSUMS" "$CHECKSUMS_DOWNLOAD_URL"
grep "$ARCHIVE_NAME" "$CHECKSUMS" | sha256sum -c -
echo "::endgroup::"
echo "::group::Installing into hosted tool cache"
mkdir stackit-cli
tar -xzvf "$ARCHIVE_NAME" -C stackit-cli
# save to tool cache
mkdir -p "$TOOL_CACHE_DIR"
mv ./stackit-cli/stackit "$TOOL_CACHE_FILE"
# symlink
ln -sf "$TOOL_CACHE_FILE" /usr/local/bin/stackit
echo "::endgroup::"
cd "$GITHUB_WORKSPACE"
- name: Print version
shell: sh
run: stackit --version