diff --git a/.github/workflows/additional_files.yml b/.github/workflows/additional_files.yml index a03f61b..5459a30 100644 --- a/.github/workflows/additional_files.yml +++ b/.github/workflows/additional_files.yml @@ -23,7 +23,7 @@ jobs: id: check with: additional_files: run finish discovery - ignore: ignore + ignore_paths: ignore scandir: testfiles - name: Verify check diff --git a/.github/workflows/check_together.yml b/.github/workflows/check_together.yml index 9b18c88..ce5a5d0 100644 --- a/.github/workflows/check_together.yml +++ b/.github/workflows/check_together.yml @@ -22,7 +22,7 @@ jobs: uses: ./ id: check with: - ignore: ignore + ignore_paths: ignore check_together: true - name: Verify check diff --git a/.github/workflows/ignore_names.yml b/.github/workflows/ignore_names.yml new file mode 100644 index 0000000..8e03775 --- /dev/null +++ b/.github/workflows/ignore_names.yml @@ -0,0 +1,41 @@ +name: 'ignore_names' + +on: + push: + branches: ["master"] + pull_request: + +jobs: + ignore_names: + name: ignore_names + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Run ShellCheck + uses: ./ + id: check + with: + ignore_paths: ignore + ignore_names: ignore_single_file.sh + + - name: Verify check + run: | + expect="testfiles/test.bash" + notexpect="testfiles/ignore_single_file.sh" + + 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 + + diff --git a/.github/workflows/base.yml b/.github/workflows/ignore_paths.yml similarity index 89% rename from .github/workflows/base.yml rename to .github/workflows/ignore_paths.yml index f144c4d..29a45f6 100644 --- a/.github/workflows/base.yml +++ b/.github/workflows/ignore_paths.yml @@ -1,4 +1,4 @@ -name: 'base' +name: 'ignore_paths' on: push: @@ -6,8 +6,8 @@ on: pull_request: jobs: - base: - name: base + ignore_paths: + name: ignore_paths runs-on: ${{ matrix.os }} strategy: matrix: @@ -22,7 +22,7 @@ jobs: uses: ./ id: check with: - ignore: ignore + ignore_paths: ignore - name: Verify check run: | @@ -35,4 +35,4 @@ jobs: 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 + fi \ No newline at end of file diff --git a/.github/workflows/scandir.yml b/.github/workflows/scandir.yml index a457b66..c4d6041 100644 --- a/.github/workflows/scandir.yml +++ b/.github/workflows/scandir.yml @@ -42,7 +42,7 @@ jobs: id: two with: scandir: './testfiles/scandir' - ignore: ignore + ignore_paths: ignore - name: Verify check run: | diff --git a/README.md b/README.md index e0545e4..a43b03c 100644 --- a/README.md +++ b/README.md @@ -41,15 +41,16 @@ example: SHELLCHECK_OPTS: -e SC2059 -e SC2034 -e SC1090 ``` -## Ignore paths +## Ignore paths and names -You can use the `ignore` input to disable specific directories. +You can use the `ignore_paths` and `ignore_names` input to disable specific directories and files. ```text sample structure: sample/directory/with/files/ignoreme/test.sh sample/directory/with/files/ignoremetoo/test.sh sample/directory/with/files/test.sh +sample/directory/with/files/ignorable.sh ``` example: @@ -59,10 +60,11 @@ example: - name: Run ShellCheck uses: ludeeus/action-shellcheck@master with: - ignore: ignoreme ignoremetoo + ignore_paths: ignoreme ignoremetoo + ignore_names: ignorable.sh ``` -This will skip `sample/directory/with/files/ignoreme/test.sh` and `sample/directory/with/files/ignoremetoo/test.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`. ## Minimum severity of errors to consider (error, warning, info, style) diff --git a/action.yaml b/action.yaml index 0bc86f9..a31ec82 100644 --- a/action.yaml +++ b/action.yaml @@ -10,6 +10,14 @@ inputs: description: "Paths to ignore when running ShellCheck" required: false default: "" + ignore_paths: + description: "Paths to ignore when running ShellCheck" + required: false + default: "" + ignore_names: + description: "Names to ignore when running ShellCheck" + required: false + default: "" severity: description: "Minimum severity of errors to consider. Options: [error, warning, info, style]" required: false @@ -98,10 +106,24 @@ runs: excludes+=("! -path \"*./.git/*\"") excludes+=("! -path \"*.go\"") excludes+=("! -path \"*/mvnw\"") - for path in ${{ inputs.ignore }}; do - echo "::debug:: Adding "$path" to excludes" - excludes+=("! -path \"*./$path/*\"") - excludes+=("! -path \"*/$path/*\"") + if [[ -n "${{ inputs.ignore }}" ]]; then + echo "::warning::ignore is deprecated. Please use ignore_paths instead" + for path in ${{ inputs.ignore }}; do + echo "::debug:: Adding "$path" to excludes" + 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/*\"") + done + fi + + for name in ${{ inputs.ignore_names }}; do + echo "::debug:: Adding "$name" to excludes" + excludes+=("! -name $name") done echo "::set-output name=excludes::${excludes[@]}" diff --git a/testfiles/ignore_single_file.sh b/testfiles/ignore_single_file.sh new file mode 100644 index 0000000..cfb414c --- /dev/null +++ b/testfiles/ignore_single_file.sh @@ -0,0 +1,4 @@ +#!/usr/bin/sh + +test="test" +echo "$test" \ No newline at end of file