mirror of
https://github.com/ludeeus/action-shellcheck.git
synced 2025-01-18 09:31:57 +01:00
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:
parent
203a3fd018
commit
6096f68baf
45
.github/workflows/ignore_paths.yml
vendored
45
.github/workflows/ignore_paths.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: 'ignore_paths'
|
||||
name: "ignore_paths"
|
||||
|
||||
on:
|
||||
push:
|
||||
@ -22,17 +22,48 @@ jobs:
|
||||
uses: ./
|
||||
id: check
|
||||
with:
|
||||
ignore_paths: ignore
|
||||
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"
|
||||
fail=false
|
||||
|
||||
# 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 }}"
|
||||
exit 1
|
||||
elif [[ "${{ steps.check.outputs.files }}" =~ $notexpect ]];then
|
||||
echo "::error:: Expected file $notexpect 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
|
20
README.md
20
README.md
@ -10,7 +10,7 @@ on:
|
||||
branches:
|
||||
- master
|
||||
|
||||
name: 'Trigger: Push action'
|
||||
name: "Trigger: Push action"
|
||||
|
||||
jobs:
|
||||
shellcheck:
|
||||
@ -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.
|
||||
|
@ -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
|
||||
|
3
testfiles/duplicate_name.bash
Normal file
3
testfiles/duplicate_name.bash
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
test="test"
|
||||
echo "$test"
|
3
testfiles/ignore/ignore.bash
Normal file
3
testfiles/ignore/ignore.bash
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
test="test"
|
||||
echo "$test"
|
@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo $test $test
|
||||
|
||||
echo $test2
|
3
testfiles/ignore_some/do_not_ignore.bash
Normal file
3
testfiles/ignore_some/do_not_ignore.bash
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
test="test"
|
||||
echo "$test"
|
3
testfiles/ignore_some/duplicate_name.bash
Normal file
3
testfiles/ignore_some/duplicate_name.bash
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
test="test"
|
||||
echo "$test"
|
3
testfiles/ignore_some/ignore.bash
Normal file
3
testfiles/ignore_some/ignore.bash
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
test="test"
|
||||
echo "$test"
|
Loading…
x
Reference in New Issue
Block a user