diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 917f196..74ffe84 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -14,6 +14,7 @@ jobs: matrix: features: - chezmoi + - gum - k3d - k9s - kustomize diff --git a/src/gum/devcontainer-feature.json b/src/gum/devcontainer-feature.json new file mode 100644 index 0000000..1675b19 --- /dev/null +++ b/src/gum/devcontainer-feature.json @@ -0,0 +1,13 @@ +{ + "name": "gum", + "id": "gum", + "version": "1.0.0", + "description": "A tool for glamorous shell scripts.", + "options": { + "version": { + "type": "string", + "default": "latest", + "description": "Version of gum to install. Accepts versions with or without the 'v' prefix." + } + } +} diff --git a/src/gum/install.sh b/src/gum/install.sh new file mode 100755 index 0000000..6cde683 --- /dev/null +++ b/src/gum/install.sh @@ -0,0 +1,73 @@ +#!/bin/sh +set -e + +# grab the version +readonly GUM_VERSION="${VERSION:-latest}" + +# apt-get configuration +export DEBIAN_FRONTEND=noninteractive + + +preflight () { + if command -v wget > /dev/null; then + return + fi + + if [ -e /etc/os-release ]; then + . /etc/os-release + fi + + case "${ID}" in + 'debian' | 'ubuntu') + apt-get update + apt-get install -y --no-install-recommends \ + wget \ + ca-certificates + ;; + 'fedora') + dnf -y install wget + ;; + *) echo "The ${ID} distribution is not supported."; exit 1 ;; + esac +} + +main () { + preflight + + local ARCH="$(uname -m)" + case "${ARCH}" in + "aarch64") ARCH="arm64" ;; + "x86_64") ARCH="x86_64" ;; + *) echo "The current architecture (${ARCH}) is not supported."; exit 1 ;; + esac + + if [ "${GUM_VERSION}" != "latest" ] ; then + GUM_CHECKSUMS_URL="https://github.com/charmbracelet/gum/releases/download/v${GUM_VERSION#[vV]}/checksums.txt" + GUM_URL="https://github.com/charmbracelet/gum/releases/download/v${GUM_VERSION#[vV]}/gum_${GUM_VERSION#[vV]}_Linux_${ARCH}.tar.gz" + else + local RELEASES_RESPONSE="$(wget -qO- --tries=3 https://api.github.com/repos/charmbracelet/gum/releases)" + GUM_CHECKSUMS_URL="$(echo "${RELEASES_RESPONSE}" | grep "browser_download_url.*checksums.txt" | head -n 1 | cut -d '"' -f 4)" + GUM_URL="$(echo "${RELEASES_RESPONSE}" | grep "browser_download_url.*Linux_${ARCH}.tar.gz" | head -n 1 | cut -d '"' -f 4)" + fi + + echo "Installing gum ${GUM_VERSION} for ${ARCH} ..." + + echo "Downloading checksums ${GUM_CHECKSUMS_URL} ..." + wget --no-verbose -O /tmp/checksums.txt "${GUM_CHECKSUMS_URL}" + local GUM_SHA="$(grep Linux_${ARCH}.tar.gz$ /tmp/checksums.txt | cut -d ' ' -f 1)" + + echo "Downloading ${GUM_URL} ..." + wget --no-verbose -O /tmp/gum.tar.gz "${GUM_URL}" + + echo "Verifying checksum ${GUM_SHA} ..." + echo "${GUM_SHA} /tmp/gum.tar.gz" | sha256sum -c - + + echo "Extracting..." + tar xf /tmp/gum.tar.gz --directory=/usr/local/bin --strip-components=1 --wildcards gum_*_Linux_${ARCH}/gum + chmod +x /usr/local/bin/gum + rm /tmp/gum.tar.gz + + echo "gum ${GUM_VERSION} for ${ARCH} installed at $(command -v gum)." +} + +main "$@" diff --git a/test/_global/all-tools.sh b/test/_global/all-tools.sh index 7ba88b1..0791b4c 100644 --- a/test/_global/all-tools.sh +++ b/test/_global/all-tools.sh @@ -9,6 +9,7 @@ source dev-container-features-test-lib # The 'check' command comes from the dev-container-features-test-lib. check "skaffold" skaffold version check "chezmoi" chezmoi --version +check "gum" gum --version check "kustomize" kustomize version check "k9s" k9s version check "k3d" k3d version diff --git a/test/_global/scenarios.json b/test/_global/scenarios.json index e8dfe43..2a8e89f 100644 --- a/test/_global/scenarios.json +++ b/test/_global/scenarios.json @@ -4,6 +4,7 @@ "features": { "chezmoi": {}, "skaffold": {}, + "gum": {}, "k9s": {}, "k3d": {}, "kustomize": {}, diff --git a/test/gum/gum-specific-version-with-prefix.sh b/test/gum/gum-specific-version-with-prefix.sh new file mode 100644 index 0000000..21e2c50 --- /dev/null +++ b/test/gum/gum-specific-version-with-prefix.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. +check "gum specific version v0.16.1" /bin/bash -c "gum --version | grep 'v0.16.1'" + +# Report result +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults \ No newline at end of file diff --git a/test/gum/gum-specific-version-without-prefix.sh b/test/gum/gum-specific-version-without-prefix.sh new file mode 100644 index 0000000..e36c58f --- /dev/null +++ b/test/gum/gum-specific-version-without-prefix.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. +check "gum specific version .16.1" /bin/bash -c "gum --version | grep 'v0.16.1'" + +# Report result +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults \ No newline at end of file diff --git a/test/gum/scenarios.json b/test/gum/scenarios.json new file mode 100644 index 0000000..d2deb07 --- /dev/null +++ b/test/gum/scenarios.json @@ -0,0 +1,18 @@ +{ + "gum-specific-version-without-prefix": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "gum": { + "version": "0.16.1" + } + } + }, + "gum-specific-version-with-prefix": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "gum": { + "version": "v0.16.1" + } + } + } +} \ No newline at end of file diff --git a/test/gum/test.sh b/test/gum/test.sh new file mode 100644 index 0000000..a295099 --- /dev/null +++ b/test/gum/test.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. +check "gum" gum --version + +# Report result +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults \ No newline at end of file