Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Run ShellCheck
uses: azohra/shell-linter@latest
```
Expand Down Expand Up @@ -69,14 +70,17 @@ Note that `exclude-paths` only accepts paths relative to your project's root dir

To exclude a folder and it's content recursively just provide the path of the folder **without** a `/` at the end. In the example above, the entire folder at the path `tests/unit_tests` will be excluded from linting.

#### Run static analysis for all the shell scripts and only report issue with error severity:
#### Run static analysis for all the shell scripts and only report issues with error severity while excluding specific issues:
```yml
- name: Run ShellCheck
uses: azohra/shell-linter@latest
with:
path: "src/*.sh"
severity: "error"
exclude-issues: "SC1068,SC1066"
```
Note that `exclude-issues` contains a list of issues to ignore (example: "SC1068") comma-separated without any spaces.

#### Run analysis by using a specific version of Shell Linter:
```yml
- name: Run ShellCheck
Expand All @@ -85,12 +89,15 @@ To exclude a folder and it's content recursively just provide the path of the fo

# Input

### `path`
Optional. Execute lint check on a specific file or folder. Default: `.`
### `exclude-issues`
Optional. Specify shellcheck issues to exclude during scan. For more information refer to [Checks](https://github.com/koalaman/shellcheck/wiki/Checks). Default: scan all issues.

### `exclude-paths`
Optional. Exclude files and folders from ShellCheck scan.

### `path`
Optional. Execute lint check on a specific file or folder. Default: `.`

### `severity`
Optional. Specify minimum severity of errors to consider [style, info, warning, error]. Default: `style`

Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ inputs:
description: 'Specify files or folders to exclude during scan.'
required: false
default: ''

exclude-issues:
description: 'Specify shellcheck issues to exclude during scan.'
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.path }}
- ${{ inputs.severity }}
- ${{ inputs.exclude-paths}}
- ${{ inputs.exclude-issues }}
branding:
icon: 'check-circle'
color: 'green'
Expand Down
10 changes: 8 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
input_paths="$1"
severity_mode="$2"
exclude_paths="$3"
execution_mode="$4"
exclude_issues="$4"
execution_mode="$5"
my_dir=$(pwd)
status_code="0"
find_path_clauses=(! -path "${my_dir}/.git/*")
Expand All @@ -31,6 +32,11 @@ process_input(){
done
fi

optional_params=""
if [[ ! -z "$exclude_issues" ]]; then
optional_params="--exclude $exclude_issues"
fi

if [[ -n "$input_paths" && "$input_paths" != "." ]]; then
for path in $(echo "$input_paths" | tr "," "\n"); do
if [ -d "$path" ]; then
Expand Down Expand Up @@ -58,7 +64,7 @@ scan_file(){
echo "###############################################"
echo " Scanning $file"
echo "###############################################"
shellcheck -x "$file_path" --severity="$severity_mode"
shellcheck -x "$file_path" --severity="$severity_mode" $optional_params
local exit_code=$?
if [ $exit_code -eq 0 ] ; then
printf "%b" "Successfully scanned ${file_path} 🙌\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

var=World; echo "Hello "
echo "$(date)"

$foo=42
3 changes: 3 additions & 0 deletions test_data/exclude_issues/test_script_exclude_none.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

echo "Hello $name"
3 changes: 3 additions & 0 deletions test_data/exclude_issues/test_script_exclude_one_error.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
var = 42
echo -n 42
37 changes: 37 additions & 0 deletions tests/integration_tests/exclude_issues_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! /bin/bash

source ./entrypoint.sh "" "" "" "" "--test"

test_exclude_no_error(){
input_paths="./test_data/exclude_issues/test_script_exclude_none.sh"
severity_mode="style"
exclude_issues=""
local expected_error="SC2154"
local actual_message=$(process_input)

assertContains "Actual messages:$actual_message Did not find the message.\n" "$actual_message" "$expected_error"
}

test_exclude_one_error(){
input_paths="./test_data/exclude_issues/test_script_exclude_one_error.sh"
severity_mode="style"
exclude_issues="SC2283"
local expected_error="SC3037"
local not_expected_error="SC2283"
local actual_message=$(process_input)

assertContains "Actual messages:$actual_message Did not find the message.\n" "$actual_message" "$expected_error"
assertNotContains "Actual messages:$actual_message contains the message.\n" "$actual_message" "$not_expected_error"
}

test_exclude_multiple_errors(){
input_paths="./test_data/exclude_issues/test_script_exclude_multiple_errors.sh"
severity_mode="style"
exclude_issues="SC1017,SC2281,SC2034,SC2154,SC2005"
local expected_message="Successfully scanned"
local actual_message=$(process_input)

assertContains "Actual messages:$actual_message Did not find the message.\n" "$actual_message" "$expected_message"
}

source ./tests/shunit2
2 changes: 1 addition & 1 deletion tests/integration_tests/ignored_path_tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/bash
# shellcheck disable=SC2155

source ./entrypoint.sh "" "" "" "--test"
source ./entrypoint.sh "" "" "" "" "--test"

test_ignore_directories(){
local exclude_paths="test_dir,severity_mode"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/input_path_tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/bash
# shellcheck disable=SC2155

source ./entrypoint.sh "" "" "" "--test"
source ./entrypoint.sh "" "" "" "" "--test"

test_execution_mode(){
local expected_path=./test_data
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/severity_mode_tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/bash

source ./entrypoint.sh "" "" "" "--test"
source ./entrypoint.sh "" "" "" "" "--test"

test_severity_mode_invalid(){
input_paths="./test_data/severity_mode/test_script_warning.sh"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/scan_tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/bash
# shellcheck disable=SC2155

source ./entrypoint.sh "" "style" "" "--test"
source ./entrypoint.sh "" "style" "" "" "--test"

# scan_file tests
test_scan_valid_script_with_extension(){
Expand Down