diff --git a/.github/workflows/additional_files.yml b/.github/workflows/additional_files.yml index dd22f4c..44d73f7 100644 --- a/.github/workflows/additional_files.yml +++ b/.github/workflows/additional_files.yml @@ -1,6 +1,6 @@ name: 'additional_files' -on: +on: push: branches: - "master" @@ -32,7 +32,7 @@ jobs: scandir: testfiles - name: Verify check - run: | + run: | expect="testfiles/scandir/run" if [[ ! "${{ steps.check.outputs.files }}" =~ testfiles/scandir/run ]];then @@ -44,4 +44,4 @@ jobs: elif [[ ! "${{ steps.check.outputs.files }}" =~ testfiles/scandir/discovery ]];then echo "::error:: Expected file testfiles/scandir/discovery not found in ${{ steps.check.outputs.files }}" exit 1 - fi \ No newline at end of file + fi diff --git a/.github/workflows/check_together.yml b/.github/workflows/check_together.yml index f90b346..56e7dc8 100644 --- a/.github/workflows/check_together.yml +++ b/.github/workflows/check_together.yml @@ -1,6 +1,6 @@ name: 'check_together' -on: +on: push: branches: - "master" @@ -31,7 +31,7 @@ jobs: check_together: true - name: Verify check - run: | + run: | expect="testfiles/test.bash" notexpect="testfiles/ignore/ignore.bash" @@ -41,4 +41,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 diff --git a/.github/workflows/ignore_names.yml b/.github/workflows/ignore_names.yml index 31ca8a6..4980826 100644 --- a/.github/workflows/ignore_names.yml +++ b/.github/workflows/ignore_names.yml @@ -1,6 +1,6 @@ name: 'ignore_names' -on: +on: push: branches: - "master" @@ -31,7 +31,7 @@ jobs: ignore_names: ignore_single_file.sh - name: Verify check - run: | + run: | expect="testfiles/test.bash" notexpect="testfiles/ignore_single_file.sh" @@ -39,6 +39,6 @@ jobs: 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 }}" + echo "::error:: Unexpected file $notexpect found in ${{ steps.check.outputs.files }}" exit 1 - fi + fi diff --git a/.github/workflows/ignore_symlinks.yml b/.github/workflows/ignore_symlinks.yml new file mode 100644 index 0000000..9687fe1 --- /dev/null +++ b/.github/workflows/ignore_symlinks.yml @@ -0,0 +1,72 @@ +name: 'ignore_symlinks' + +on: + push: + branches: + - "master" + pull_request: + branches: + - "master" + +permissions: {} + +jobs: + ignore_symlinks: + name: ignore_symlinks + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Run ShellCheck (ignore symbolic links) + uses: ./ + id: check_symlinks_ignored + with: + ignore_paths: ignore + ignore_symlinks: true + additional_files: symlink.sh + + - name: Verify check (ignore symbolic links) + run: | + # Verify that symlink is not included + notexpect="testfiles/symlink.sh" + if [[ "${{ steps.check_symlinks_ignored.outputs.files }}" =~ $notexpect ]];then + echo "::error:: Unexpected file $notexpect found in ${{ steps.check_symlinks_ignored.outputs.files }}" + exit 1 + fi + + # Verify that ignored path is not included + notexpect="testfiles/ignore/symlink.sh" + if [[ "${{ steps.check_symlinks_ignored.outputs.files }}" =~ $notexpect ]];then + echo "::error:: Unexpected file $notexpect found in ${{ steps.check_symlinks_ignored.outputs.files }}" + exit 1 + fi + + - name: Run ShellCheck (include symbolic links) + uses: ./ + id: check_symlinks_included + with: + ignore_paths: ignore + ignore_symlinks: false + additional_files: symlink.sh + + - name: Verify check (include symbolic links) + run: | + # Verify that symlink is included + expect="testfiles/symlink.sh" + if [[ ! "${{ steps.check_symlinks_included.outputs.files }}" =~ $expect ]];then + echo "::error:: Expected file $expect not found in ${{ steps.check_symlinks_included.outputs.files }}" + exit 1 + fi + + # Verify that ignored path is not included + notexpect="testfiles/ignore/symlink.sh" + if [[ "${{ steps.check_symlinks_included.outputs.files }}" =~ $notexpect ]];then + echo "::error:: Unexpected file $notexpect found in ${{ steps.check_symlinks_included.outputs.files }}" + exit 1 + fi diff --git a/action.yaml b/action.yaml index 130781e..43df31c 100644 --- a/action.yaml +++ b/action.yaml @@ -19,6 +19,10 @@ inputs: description: "Names to ignore when running ShellCheck" required: false default: "" + ignore_symlinks: + description: "Ignore files that are symbolic links." + required: false + default: "true" severity: description: "Minimum severity of errors to consider. Options: [error, warning, info, style]" required: false @@ -86,6 +90,7 @@ runs: shell: bash id: options env: + INPUT_IGNORE_SYMLINKS: ${{ inputs.ignore_symlinks }} INPUT_SEVERITY: ${{ inputs.severity }} INPUT_FORMAT: ${{ inputs.format }} run: | @@ -93,6 +98,9 @@ runs: if [[ -n "${INPUT_SEVERITY}" ]]; then options+=("-S ${INPUT_SEVERITY}") fi + if [[ "${INPUT_IGNORE_SYMLINKS}" != "true" ]]; then + echo "file_options=-L" >> $GITHUB_OUTPUT + fi options+=("--format=${INPUT_FORMAT}") echo "options=${options[@]}" >> $GITHUB_OUTPUT @@ -148,7 +156,7 @@ runs: id: check env: INPUT_SCANDIR: ${{ inputs.scandir }} - INPUT_CHECK_TOGETHER: ${{ inputs.check_together }} + INPUT_FILE_OPTIONS: ${{ steps.options.outputs.file_options }} INPUT_EXCLUDE_ARGS: ${{ steps.exclude.outputs.excludes }} INPUT_ADDITIONAL_FILE_ARGS: ${{ steps.additional.outputs.files }} INPUT_SHELLCHECK_OPTIONS: ${{ steps.options.outputs.options }} @@ -161,7 +169,9 @@ runs: while IFS= read -r -d '' file; do filepaths+=("$file") - done < <(find "${INPUT_SCANDIR}" \ + done < <(find \ + ${INPUT_FILE_OPTIONS} \ + "${INPUT_SCANDIR}" \ ${INPUT_EXCLUDE_ARGS} \ -type f \ '(' \ @@ -198,7 +208,9 @@ runs: while IFS= read -r -d '' file; do head -n1 "$file" | grep -Eqs "$shebangregex" || continue filepaths+=("$file") - done < <(find "${INPUT_SCANDIR}" \ + done < <(find \ + ${INPUT_FILE_OPTIONS} \ + "${INPUT_SCANDIR}" \ ${INPUT_EXCLUDE_ARGS} \ -type f ! -name '*.*' -perm /111 \ -print0) diff --git a/testfiles/ignore/symlink.sh b/testfiles/ignore/symlink.sh new file mode 100644 index 0000000..8f0ffb0 --- /dev/null +++ b/testfiles/ignore/symlink.sh @@ -0,0 +1,3 @@ +#!/bin/sh +test="test" +echo "$test" diff --git a/testfiles/symlink.sh b/testfiles/symlink.sh new file mode 120000 index 0000000..978f35e --- /dev/null +++ b/testfiles/symlink.sh @@ -0,0 +1 @@ +ignore/symlink.sh \ No newline at end of file