Exact path matching ignore path (#59)

* support exact path matching and glob matching for ignore_path

* newlines

* update readme

* Trigger CI

Co-authored-by: ludeeus <ludeeus@ludeeus.dev>
This commit is contained in:
bi1yeu 2022-09-03 01:29:32 -07:00 committed by GitHub
parent 203a3fd018
commit 6096f68baf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 92 additions and 31 deletions

View File

@ -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
# 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

View File

@ -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.

View File

@ -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

View File

@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"

View File

@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"

View File

@ -1,5 +0,0 @@
#!/bin/sh
echo $test $test
echo $test2

View File

@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"

View File

@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"

View File

@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"