Skip to content

Commit

Permalink
feat(deno.com): Add feature. (#7)
Browse files Browse the repository at this point in the history
* feat(`deno.com`): Add feature.

* feat(`deno.com`): Fix `curl` dep.

* feat(`deno.com`): Fix `curl` dep.

* feat(`deno.com`): Fix test.
  • Loading branch information
sebst authored Oct 12, 2024
1 parent 8802d4f commit cb0991e
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
features:
- atuin.sh
- btop
- deno.com
- smallstep.com
- starship.rs
baseImage:
Expand All @@ -38,6 +39,7 @@ jobs:
features:
- atuin.sh
- btop
- deno.com
- smallstep.com
- starship.rs
steps:
Expand Down
17 changes: 17 additions & 0 deletions src/deno.com/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "deno.com",
"id": "deno.com",
"version": "1.0.0",
"description": "Install \"deno\" binary",
"documentationURL": "https://github.com/devcontainer-community/devcontainer-features/tree/main/src/deno.com",
"options": {
"version": {
"type": "string",
"default": "latest",
"proposals": [
"latest"
],
"description": "Version of \"deno\" to install."
}
}
}
55 changes: 55 additions & 0 deletions src/deno.com/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
set -o errexit
set -o pipefail
set -o noclobber
set -o nounset
set -o allexport
readonly name="deno"
apt_get_cleanup() {
apt-get clean
rm -rf /var/lib/apt/lists/*
}
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
}
check_curl_installed() {
declare -a requiredAptPackagesMissing=()
if ! [ -r '/etc/ssl/certs/ca-certificates.crt' ]; then
requiredAptPackagesMissing+=('ca-certificates')
fi
if ! command -v curl >/dev/null 2>&1; then
requiredAptPackagesMissing+=('curl')
fi
declare -i requiredAptPackagesMissingCount=${#requiredAptPackagesMissing[@]}
if [ $requiredAptPackagesMissingCount -gt 0 ]; then
apt_get_checkinstall "${requiredAptPackagesMissing[@]}"
apt_get_cleanup
fi
}
echo_banner() {
local text="$1"
echo -e "\e[1m\e[97m\e[41m$text\e[0m"
}
install() {
check_curl_installed
if [ "$VERSION" == "latest" ]; then
VERSION="$(curl -s https://dl.deno.land/release-latest.txt)"
fi
apt_get_checkinstall unzip
export DENO_INSTALL="/usr/local"
curl -fsSL https://deno.land/install.sh | sh -s -- -y $VERSION
apt_get_cleanup
}
echo_banner "devcontainer.community"
echo "Installing $name..."
install "$@"
echo "(*) Done!"
18 changes: 18 additions & 0 deletions test/deno.com/deno.com-debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash


set -e

# Optional: Import test library bundled with the devcontainer CLI
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
# Provides the 'check' and 'reportResults' commands.
source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
# check <LABEL> <cmd> [args...]
check "execute command" bash -c "deno --version | grep 'deno'"

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
9 changes: 9 additions & 0 deletions test/deno.com/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"deno.com-debian": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"deno.com": {
}
}
}
}
18 changes: 18 additions & 0 deletions test/deno.com/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash


set -e

# Optional: Import test library bundled with the devcontainer CLI
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
# Provides the 'check' and 'reportResults' commands.
source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
# check <LABEL> <cmd> [args...]
check "execute command" bash -c "deno --version | grep 'deno'"

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults

0 comments on commit cb0991e

Please sign in to comment.