mirror of
https://github.com/ludeeus/action-shellcheck.git
synced 2025-01-18 17:41:58 +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:
|
on:
|
||||||
push:
|
push:
|
||||||
@ -22,17 +22,48 @@ jobs:
|
|||||||
uses: ./
|
uses: ./
|
||||||
id: check
|
id: check
|
||||||
with:
|
with:
|
||||||
ignore_paths: ignore
|
ignore_paths: ignore ./testfiles/ignore_some/duplicate_name.bash **/ignore_some/ignore.bash
|
||||||
|
|
||||||
- name: Verify check
|
- name: Verify check
|
||||||
run: |
|
run: |
|
||||||
expect="testfiles/test.bash"
|
fail=false
|
||||||
notexpect="testfiles/ignore/ignore.bash"
|
|
||||||
|
|
||||||
|
# verify a non-ignored path is not excluded
|
||||||
|
expect="testfiles/test.bash"
|
||||||
if [[ ! "${{ steps.check.outputs.files }}" =~ $expect ]];then
|
if [[ ! "${{ steps.check.outputs.files }}" =~ $expect ]];then
|
||||||
echo "::error:: Expected file $expect not found in ${{ steps.check.outputs.files }}"
|
echo "::error:: Expected file $expect not found in ${{ steps.check.outputs.files }}"
|
||||||
exit 1
|
fail=true
|
||||||
elif [[ "${{ steps.check.outputs.files }}" =~ $notexpect ]];then
|
fi
|
||||||
echo "::error:: Expected file $notexpect found in ${{ steps.check.outputs.files }}"
|
|
||||||
|
# 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
|
exit 1
|
||||||
fi
|
fi
|
20
README.md
20
README.md
@ -10,7 +10,7 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
name: 'Trigger: Push action'
|
name: "Trigger: Push action"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
shellcheck:
|
shellcheck:
|
||||||
@ -28,8 +28,8 @@ You can pass any supported ShellCheck option or flag with the `SHELLCHECK_OPTS`
|
|||||||
|
|
||||||
Some examples include:
|
Some examples include:
|
||||||
|
|
||||||
* To disable specific checks (eg: `-e SC2059 -e SC2034 -e SC1090`)
|
- To disable specific checks (eg: `-e SC2059 -e SC2034 -e SC1090`)
|
||||||
* To test against different shells (eg: `-s dash` or `-s ksh`)
|
- To test against different shells (eg: `-s dash` or `-s ksh`)
|
||||||
|
|
||||||
example:
|
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`.
|
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)
|
## 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.
|
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
|
id: exclude
|
||||||
run: |
|
run: |
|
||||||
declare -a excludes
|
declare -a excludes
|
||||||
|
set -f # temporarily disable globbing so that globs in input aren't
|
||||||
|
# expanded
|
||||||
excludes+=("! -path \"*./.git/*\"")
|
excludes+=("! -path \"*./.git/*\"")
|
||||||
excludes+=("! -path \"*.go\"")
|
excludes+=("! -path \"*.go\"")
|
||||||
excludes+=("! -path \"*/mvnw\"")
|
excludes+=("! -path \"*/mvnw\"")
|
||||||
@ -112,12 +114,14 @@ runs:
|
|||||||
echo "::debug:: Adding "$path" to excludes"
|
echo "::debug:: Adding "$path" to excludes"
|
||||||
excludes+=("! -path \"*./$path/*\"")
|
excludes+=("! -path \"*./$path/*\"")
|
||||||
excludes+=("! -path \"*/$path/*\"")
|
excludes+=("! -path \"*/$path/*\"")
|
||||||
|
excludes+=("! -path \"$path\"")
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
for path in ${{ inputs.ignore_paths }}; do
|
for path in ${{ inputs.ignore_paths }}; do
|
||||||
echo "::debug:: Adding "$path" to excludes"
|
echo "::debug:: Adding "$path" to excludes"
|
||||||
excludes+=("! -path \"*./$path/*\"")
|
excludes+=("! -path \"*./$path/*\"")
|
||||||
excludes+=("! -path \"*/$path/*\"")
|
excludes+=("! -path \"*/$path/*\"")
|
||||||
|
excludes+=("! -path \"$path\"")
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -127,6 +131,8 @@ runs:
|
|||||||
done
|
done
|
||||||
echo "::set-output name=excludes::${excludes[@]}"
|
echo "::set-output name=excludes::${excludes[@]}"
|
||||||
|
|
||||||
|
set +f # re-enable globbing
|
||||||
|
|
||||||
- name: Gather additional files
|
- name: Gather additional files
|
||||||
shell: bash
|
shell: bash
|
||||||
id: additional
|
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