Skip to content

Commit

Permalink
Add ShellCheck feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarber623-cargosense committed Feb 29, 2024
1 parent 40a439e commit f309e1f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions src/shellcheck/README.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 10 additions & 0 deletions src/shellcheck/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

11 changes: 11 additions & 0 deletions src/shellcheck/install.sh
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions test/shellcheck/test.sh
Original file line number Diff line number Diff line change
@@ -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 <LABEL> <cmd> [args...]
check "version" shellcheck --version
check "which shellcheck" bash -c "which shellcheck | grep /usr/bin/shellcheck"

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

0 comments on commit f309e1f

Please sign in to comment.