From 10434c25985fcc342c4ae1363f2246cf4ccd00a6 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Sat, 3 Sep 2022 10:31:50 +0200 Subject: [PATCH] Fix warnings reported by shellcheck (#61) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Joakim Sørensen --- .github/workflows/scandir.yml | 12 +++---- action.yaml | 65 +++++++++++++++++------------------ testfiles/scandir/run me.bash | 3 ++ 3 files changed, 41 insertions(+), 39 deletions(-) create mode 100644 testfiles/scandir/run me.bash diff --git a/.github/workflows/scandir.yml b/.github/workflows/scandir.yml index c4d6041..4f1371f 100644 --- a/.github/workflows/scandir.yml +++ b/.github/workflows/scandir.yml @@ -1,6 +1,6 @@ name: 'scandir' -on: +on: push: branches: ["master"] pull_request: @@ -25,8 +25,8 @@ jobs: scandir: testfiles/scandir - name: Verify check - run: | - expect="testfiles/scandir/test.bash" + run: | + expect="testfiles/scandir/run[[:space:]]me.bash" notexpect="testfiles/test.bash" if [[ ! "${{ steps.one.outputs.files }}" =~ $expect ]];then @@ -35,7 +35,7 @@ jobs: elif [[ "${{ steps.one.outputs.files }}" =~ $notexpect ]];then echo "::error:: Expected file $notexpect found in ${{ steps.one.outputs.files }}" exit 1 - fi + fi - name: Run ShellCheck uses: ./ @@ -45,7 +45,7 @@ jobs: ignore_paths: ignore - name: Verify check - run: | + run: | expect="testfiles/scandir/test.bash" notexpect="testfiles/test.bash" @@ -55,4 +55,4 @@ jobs: elif [[ "${{ steps.two.outputs.files }}" =~ $notexpect ]];then echo "::error:: Expected file $notexpect found in ${{ steps.two.outputs.files }}" exit 1 - fi \ No newline at end of file + fi diff --git a/action.yaml b/action.yaml index 3bb13cd..74611ae 100644 --- a/action.yaml +++ b/action.yaml @@ -45,7 +45,7 @@ inputs: outputs: files: description: A list of files with issues - value: ${{ steps.filepaths.outputs.filepaths }} + value: ${{ steps.check.outputs.filepaths }} options: description: The options used value: ${{ steps.options.outputs.options }} @@ -111,14 +111,14 @@ runs: 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" + 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" + echo "::debug:: Adding '$path' to excludes" excludes+=("! -path \"*./$path/*\"") excludes+=("! -path \"*/$path/*\"") excludes+=("! -path \"$path\"") @@ -126,7 +126,7 @@ runs: fi for name in ${{ inputs.ignore_names }}; do - echo "::debug:: Adding "$name" to excludes" + echo "::debug:: Adding '$name' to excludes" excludes+=("! -name $name") done echo "::set-output name=excludes::${excludes[@]}" @@ -139,20 +139,24 @@ runs: run: | declare -a files for file in ${{ inputs.additional_files }}; do - echo "::debug:: Adding "$file" to excludes" + echo "::debug:: Adding '$file' to excludes" files+=("-o -name \"*$file\"") done echo "::set-output name=files::${files[@]}" - - name: Gather base file paths + - name: Run the check shell: bash - id: filepaths + id: check run: | + statuscode=0 declare -a filepaths shebangregex="^#! */[^ ]*/(env *)?[abk]*sh" - for path in $(find "${{ inputs.scandir }}" \ - -type f -type f ${{ steps.exclude.outputs.excludes }} \ + while IFS= read -r -d '' file; do + filepaths+=("$file") + done < <(find "${{ inputs.scandir }}" \ + ${{ steps.exclude.outputs.excludes }} \ + -type f \ '(' \ -name '*.bash' \ -o -name '.bashrc' \ @@ -181,44 +185,39 @@ runs: -o -path '*/profile' \ -o -name '*.shlib' \ ${{ steps.additional.outputs.files }} \ - ')'\ - -print); do - filepaths+=("$path"); - done + ')' \ + -print0) - for file in $(find "${{ inputs.scandir }}" ${{ steps.exclude.outputs.excludes }} -type f ! -name '*.*' -perm /111 -print); do + while IFS= read -r -d '' file; do head -n1 "$file" | grep -Eqs "$shebangregex" || continue - filepaths+=("$file"); - done - echo "::set-output name=filepaths::${filepaths[@]}" - - - name: Run the file check - id: check - shell: bash - run: | - statuscode=0 + filepaths+=("$file") + done < <(find "${{ inputs.scandir }}" \ + ${{ steps.exclude.outputs.excludes }} \ + -type f ! -name '*.*' -perm /111 \ + -print0) if [[ -n "${{ inputs.check_together }}" ]]; then - "${{ github.action_path }}/shellcheck" \ - ${{ steps.options.outputs.options }} \ - ${{ steps.filepaths.outputs.filepaths }} || statuscode=$? - else - for file in ${{ steps.filepaths.outputs.filepaths }}; do - echo "::debug::Checking $file" - "${{ github.action_path }}/shellcheck" \ + "${{ github.action_path }}/shellcheck" \ ${{ steps.options.outputs.options }} \ - "$file" || statuscode=$?; + "${filepaths[@]}" || statuscode=$? + else + for file in "${filepaths[@]}"; do + echo "::debug::Checking '$file'" + "${{ github.action_path }}/shellcheck" \ + ${{ steps.options.outputs.options }} \ + "$file" || statuscode=$? done fi + echo "::set-output name=filepaths::${filepaths[@]}" echo "::set-output name=statuscode::$statuscode" - name: Print information shell: bash run: | - echo "Files: ${{steps.filepaths.outputs.filepaths}}" + echo "Files: ${{ steps.check.outputs.filepaths }}" echo "Excluded: ${{ steps.exclude.outputs.excludes }}" echo "Options: ${{ steps.options.outputs.options }}" - echo "Status code: ${{steps.check.outputs.statuscode}}" + echo "Status code: ${{ steps.check.outputs.statuscode }}" exit ${{steps.check.outputs.statuscode}} diff --git a/testfiles/scandir/run me.bash b/testfiles/scandir/run me.bash new file mode 100644 index 0000000..77ab8c6 --- /dev/null +++ b/testfiles/scandir/run me.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo "I love spaces"