Skip to content

Commit

Permalink
Exact path matching ignore path (#59)
Browse files Browse the repository at this point in the history
* support exact path matching and glob matching for ignore_path

* newlines

* update readme

* Trigger CI

Co-authored-by: ludeeus <[email protected]>
  • Loading branch information
bi1yeu and ludeeus authored Sep 3, 2022
1 parent 203a3fd commit 6096f68
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 34 deletions.
77 changes: 54 additions & 23 deletions .github/workflows/ignore_paths.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'ignore_paths'
name: "ignore_paths"

on:
on:
push:
branches: ["master"]
pull_request:
Expand All @@ -15,24 +15,55 @@ jobs:
- ubuntu-latest
- macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Run ShellCheck
uses: ./
id: check
with:
ignore_paths: ignore

- name: Verify check
run: |
expect="testfiles/test.bash"
notexpect="testfiles/ignore/ignore.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 }}"
exit 1
fi
- name: Checkout
uses: actions/checkout@v2

- name: Run ShellCheck
uses: ./
id: check
with:
ignore_paths: ignore ./testfiles/ignore_some/duplicate_name.bash **/ignore_some/ignore.bash

- name: Verify check
run: |
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 }}"
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
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:

Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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\"")
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions testfiles/duplicate_name.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"
3 changes: 3 additions & 0 deletions testfiles/ignore/ignore.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"
5 changes: 0 additions & 5 deletions testfiles/ignore/ignore.sh

This file was deleted.

3 changes: 3 additions & 0 deletions testfiles/ignore_some/do_not_ignore.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"
3 changes: 3 additions & 0 deletions testfiles/ignore_some/duplicate_name.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"
3 changes: 3 additions & 0 deletions testfiles/ignore_some/ignore.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"

0 comments on commit 6096f68

Please sign in to comment.