diff --git a/.github/workflows/ignore_paths.yml b/.github/workflows/ignore_paths.yml index 29a45f6..908da4d 100644 --- a/.github/workflows/ignore_paths.yml +++ b/.github/workflows/ignore_paths.yml @@ -1,6 +1,6 @@ -name: 'ignore_paths' +name: "ignore_paths" -on: +on: push: branches: ["master"] pull_request: @@ -15,24 +15,55 @@ jobs: - ubuntu-latest - macos-latest steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - - name: Run ShellCheck - uses: ./ - id: check - with: - ignore_paths: ignore + - name: Run ShellCheck + uses: ./ + id: check + with: + ignore_paths: ignore ./testfiles/ignore_some/duplicate_name.bash **/ignore_some/ignore.bash - - name: Verify check - run: | - expect="testfiles/test.bash" - notexpect="testfiles/ignore/ignore.bash" + - name: Verify check + run: | + fail=false - if [[ ! "${{ steps.check.outputs.files }}" =~ $expect ]];then - echo "::error:: Expected file $expect not found in ${{ steps.check.outputs.files }}" - exit 1 - elif [[ "${{ steps.check.outputs.files }}" =~ $notexpect ]];then - echo "::error:: Expected file $notexpect found in ${{ steps.check.outputs.files }}" - exit 1 - fi \ No newline at end of file + # verify a non-ignored path is not excluded + expect="testfiles/test.bash" + if [[ ! "${{ steps.check.outputs.files }}" =~ $expect ]];then + echo "::error:: Expected file $expect not found in ${{ steps.check.outputs.files }}" + fail=true + fi + + # verify a file with the same name as an ignored file but at a + # different path is not excluded + expect="testfiles/duplicate_name.bash" + if [[ ! "${{ steps.check.outputs.files }}" =~ $expect ]];then + echo "::error:: Expected file $expect not found in ${{ steps.check.outputs.files }}" + fail=true + fi + + # verify ignored full path excluded + notexpect="testfiles/ignore_some/duplicate_name.bash" + if [[ "${{ steps.check.outputs.files }}" =~ $notexpect ]];then + echo "::error:: Unexpected file $notexpect found in ${{ steps.check.outputs.files }}" + fail=true + fi + + # verify ignored directory excluded + notexpect="testfiles/ignore/ignore.bash" + if [[ "${{ steps.check.outputs.files }}" =~ $notexpect ]];then + echo "::error:: Unexpected file $notexpect found in ${{ steps.check.outputs.files }}" + fail=true + fi + + # verify ignored glob excluded + notexpect="testfiles/ignore_some/ignore.bash" + if [[ "${{ steps.check.outputs.files }}" =~ $notexpect ]];then + echo "::error:: Unexpected file $notexpect found in ${{ steps.check.outputs.files }}" + fail=true + fi + + if $fail;then + exit 1 + fi diff --git a/README.md b/README.md index a43b03c..caef23e 100644 --- a/README.md +++ b/README.md @@ -10,16 +10,16 @@ on: branches: - master -name: 'Trigger: Push action' +name: "Trigger: Push action" jobs: shellcheck: name: Shellcheck runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Run ShellCheck - uses: ludeeus/action-shellcheck@master + - uses: actions/checkout@v2 + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master ``` ## ShellCheck options @@ -28,8 +28,8 @@ You can pass any supported ShellCheck option or flag with the `SHELLCHECK_OPTS` Some examples include: -* To disable specific checks (eg: `-e SC2059 -e SC2034 -e SC1090`) -* To test against different shells (eg: `-s dash` or `-s ksh`) +- To disable specific checks (eg: `-e SC2059 -e SC2034 -e SC1090`) +- To test against different shells (eg: `-s dash` or `-s ksh`) example: @@ -66,6 +66,20 @@ example: This will skip `sample/directory/with/files/ignoreme/test.sh`, `sample/directory/with/files/ignoremetoo/test.sh` and `sample/directory/with/files/ignorable.sh`. +You can also ignore specific files using full paths or glob patterns with `ignore_paths`. + +example: + +```yaml + ... + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master + with: + ignore_paths: ./sample/directory/with/files/ignorable.sh **/ignoreme/test.sh +``` + +This will skip `sample/directory/with/files/ignorable.sh` and `sample/directory/with/files/ignoreme/test.sh`. + ## Minimum severity of errors to consider (error, warning, info, style) You can use the `severity` input to not fail until specified severity is met, for example fail only if there are errors in scripts but ignore styling, info and warnings. diff --git a/action.yaml b/action.yaml index a31ec82..3bb13cd 100644 --- a/action.yaml +++ b/action.yaml @@ -103,6 +103,8 @@ runs: id: exclude run: | declare -a excludes + set -f # temporarily disable globbing so that globs in input aren't + # expanded excludes+=("! -path \"*./.git/*\"") excludes+=("! -path \"*.go\"") excludes+=("! -path \"*/mvnw\"") @@ -112,12 +114,14 @@ runs: echo "::debug:: Adding "$path" to excludes" excludes+=("! -path \"*./$path/*\"") excludes+=("! -path \"*/$path/*\"") + excludes+=("! -path \"$path\"") done else for path in ${{ inputs.ignore_paths }}; do echo "::debug:: Adding "$path" to excludes" excludes+=("! -path \"*./$path/*\"") excludes+=("! -path \"*/$path/*\"") + excludes+=("! -path \"$path\"") done fi @@ -127,6 +131,8 @@ runs: done echo "::set-output name=excludes::${excludes[@]}" + set +f # re-enable globbing + - name: Gather additional files shell: bash id: additional diff --git a/testfiles/duplicate_name.bash b/testfiles/duplicate_name.bash new file mode 100644 index 0000000..c196c7c --- /dev/null +++ b/testfiles/duplicate_name.bash @@ -0,0 +1,3 @@ +#!/bin/bash +test="test" +echo "$test" diff --git a/testfiles/ignore/ignore.bash b/testfiles/ignore/ignore.bash new file mode 100644 index 0000000..c196c7c --- /dev/null +++ b/testfiles/ignore/ignore.bash @@ -0,0 +1,3 @@ +#!/bin/bash +test="test" +echo "$test" diff --git a/testfiles/ignore/ignore.sh b/testfiles/ignore/ignore.sh deleted file mode 100644 index 3c116a9..0000000 --- a/testfiles/ignore/ignore.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -echo $test $test - -echo $test2 \ No newline at end of file diff --git a/testfiles/ignore_some/do_not_ignore.bash b/testfiles/ignore_some/do_not_ignore.bash new file mode 100644 index 0000000..c196c7c --- /dev/null +++ b/testfiles/ignore_some/do_not_ignore.bash @@ -0,0 +1,3 @@ +#!/bin/bash +test="test" +echo "$test" diff --git a/testfiles/ignore_some/duplicate_name.bash b/testfiles/ignore_some/duplicate_name.bash new file mode 100644 index 0000000..c196c7c --- /dev/null +++ b/testfiles/ignore_some/duplicate_name.bash @@ -0,0 +1,3 @@ +#!/bin/bash +test="test" +echo "$test" diff --git a/testfiles/ignore_some/ignore.bash b/testfiles/ignore_some/ignore.bash new file mode 100644 index 0000000..c196c7c --- /dev/null +++ b/testfiles/ignore_some/ignore.bash @@ -0,0 +1,3 @@ +#!/bin/bash +test="test" +echo "$test"