From f309e1f17926a7dc27c854dda26981946f38c241 Mon Sep 17 00:00:00 2001 From: Jason Garber Date: Thu, 29 Feb 2024 14:42:50 +0000 Subject: [PATCH 01/10] Add ShellCheck feature --- .shellcheckrc | 5 +++ src/shellcheck/README.md | 15 ++++++++ src/shellcheck/devcontainer-feature.json | 10 +++++ src/shellcheck/install.sh | 11 ++++++ test/shellcheck/test.sh | 47 ++++++++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 .shellcheckrc create mode 100644 src/shellcheck/README.md create mode 100644 src/shellcheck/devcontainer-feature.json create mode 100755 src/shellcheck/install.sh create mode 100755 test/shellcheck/test.sh diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000..6087444 --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,5 @@ +# Enable all optional checks +enable=all + +# Follow source statements even when the file is not specified as input +external-sources=true diff --git a/src/shellcheck/README.md b/src/shellcheck/README.md new file mode 100644 index 0000000..dd33274 --- /dev/null +++ b/src/shellcheck/README.md @@ -0,0 +1,15 @@ +# shellcheck + +Install [ShellCheck](https://www.shellcheck.net), a static analysis tool for shell scripts. + +## Usage + +```json +"features": { + "ghcr.io/CargoSense/devcontainer-features/shellcheck:1": {} +} +``` + +## OS Support + +This Feature should work on recent versions of Debian/Ubuntu and Linux distributions using the [apt](https://wiki.debian.org/AptCLI) management tool. diff --git a/src/shellcheck/devcontainer-feature.json b/src/shellcheck/devcontainer-feature.json new file mode 100644 index 0000000..bb1cf80 --- /dev/null +++ b/src/shellcheck/devcontainer-feature.json @@ -0,0 +1,10 @@ +{ + "name": "ShellCheck", + "id": "shellcheck", + "version": "1.0.0", + "description": "Install ShellCheck, a static analysis tool for shell scripts.", + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] + } + \ No newline at end of file diff --git a/src/shellcheck/install.sh b/src/shellcheck/install.sh new file mode 100755 index 0000000..28ec4de --- /dev/null +++ b/src/shellcheck/install.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +set -e + +if [ "$(id -u)" -ne 0 ]; then + printf 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +apt update --yes +apt install --no-install-recommends --yes shellcheck diff --git a/test/shellcheck/test.sh b/test/shellcheck/test.sh new file mode 100755 index 0000000..1a6d5f2 --- /dev/null +++ b/test/shellcheck/test.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +# This test file will be executed against an auto-generated devcontainer.json that +# includes the 'shellcheck' Feature with no options. +# +# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md +# +# Eg: +# { +# "image": "<..some-base-image...>", +# "features": { +# "shellcheck": {} +# }, +# "remoteUser": "root" +# } +# +# Thus, the value of all options will fall back to the default value in the +# Feature's 'devcontainer-feature.json'. +# +# These scripts are run as 'root' by default. Although that can be changed +# with the '--remote-user' flag. +# +# This test can be run with the following command: +# +# devcontainer features test \ +# --features shellcheck \ +# --remote-user root \ +# --skip-scenarios \ +# --base-image mcr.microsoft.com/devcontainers/base:ubuntu \ +# /path/to/this/repo + +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