diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9070303..d914379 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -34,6 +34,7 @@ jobs: - github.com-cli - helix-editor.com - jj-vcs.dev + - jnsahaj-lumen - lazygit - jq - k9scli.io @@ -97,6 +98,7 @@ jobs: - github.com-cli - helix-editor.com - jj-vcs.dev + - jnsahaj-lumen - lazygit - jq - k9scli.io diff --git a/src/jnsahaj-lumen/devcontainer-feature.json b/src/jnsahaj-lumen/devcontainer-feature.json new file mode 100644 index 0000000..822ec3d --- /dev/null +++ b/src/jnsahaj-lumen/devcontainer-feature.json @@ -0,0 +1,17 @@ +{ + "name": "jnsahaj/lumen", + "id": "jnsahaj-lumen", + "version": "1.0.0", + "description": "Install \"lumen\" binary - AI-powered git diff viewer and commit message generator", + "documentationURL": "https://github.com/devcontainer-community/devcontainer-features/tree/main/src/jnsahaj-lumen", + "options": { + "version": { + "type": "string", + "default": "latest", + "proposals": [ + "latest" + ], + "description": "Version of \"lumen\" to install." + } + } +} diff --git a/src/jnsahaj-lumen/install.sh b/src/jnsahaj-lumen/install.sh new file mode 100755 index 0000000..81c4587 --- /dev/null +++ b/src/jnsahaj-lumen/install.sh @@ -0,0 +1,62 @@ +#!/bin/bash +set -o errexit +set -o pipefail +set -o noclobber +set -o nounset +set -o allexport +readonly cratesPackage='lumen' +readonly binaryName='lumen' +readonly binaryTargetFolder='/usr/local/bin' +readonly name='lumen' +apt_get_update() { + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} +apt_get_checkinstall() { + if ! dpkg -s "$@" >/dev/null 2>&1; then + apt_get_update + DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends --no-install-suggests --option 'Debug::pkgProblemResolver=true' --option 'Debug::pkgAcquire::Worker=1' "$@" + fi +} +apt_get_cleanup() { + apt-get clean + rm -rf /var/lib/apt/lists/* +} +echo_banner() { + local text="$1" + echo -e "\e[1m\e[97m\e[41m$text\e[0m" +} +utils_check_version() { + local version=$1 + if ! [[ "${version:-}" =~ ^(latest|[0-9]+\.[0-9]+\.[0-9]+)$ ]]; then + printf >&2 '=== [ERROR] Option "version" (value: "%s") is not "latest" or valid semantic version format "X.Y.Z" !\n' \ + "$version" + exit 1 + fi +} +install() { + utils_check_version "$VERSION" + apt_get_checkinstall curl ca-certificates build-essential + export RUSTUP_HOME=/usr/local/rustup + export CARGO_HOME=/usr/local/cargo + if ! command -v cargo >/dev/null 2>&1; then + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ + sh -s -- -y --no-modify-path --default-toolchain stable + fi + export PATH=/usr/local/cargo/bin:$PATH + if [ "$VERSION" == 'latest' ] || [ -z "$VERSION" ]; then + cargo install "$cratesPackage" + else + cargo install "$cratesPackage" --version "$VERSION" + fi + readonly binaryTargetPath="${binaryTargetFolder}/${binaryName}" + ln -sf /usr/local/cargo/bin/"$binaryName" "$binaryTargetPath" + chmod 755 "$binaryTargetPath" + apt_get_cleanup +} +echo_banner "devcontainer.community" +echo "Installing $name..." +install "$@" +echo "(*) Done!" diff --git a/test/jnsahaj-lumen/test.sh b/test/jnsahaj-lumen/test.sh new file mode 100755 index 0000000..fbf64d2 --- /dev/null +++ b/test/jnsahaj-lumen/test.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +# Feature-specific tests +check "execute command" bash -c "lumen --version" + +# Report results +reportResults