From 5b1d02e8e8f2209c98c3a54b3f82eb221d85d316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 24 Oct 2024 13:21:28 +0200 Subject: [PATCH 1/2] Add an option to check all executable scripts By default, this action only checks extension-less executable scripts if they have a known shebang such as `#!/usr/bin/env bash`. The new option `all_scripts: true` relaxes the shebang regex pattern so that any executable scripts are checked by shellcheck. This is suitable for repositories with scripts that have unusal shebangs. --- .github/workflows/scandir.yml | 16 ++++++++++++++++ action.yaml | 8 +++++++- testfiles/scandir/unknown-shebang | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 testfiles/scandir/unknown-shebang diff --git a/.github/workflows/scandir.yml b/.github/workflows/scandir.yml index c971c91..d6f5159 100644 --- a/.github/workflows/scandir.yml +++ b/.github/workflows/scandir.yml @@ -61,3 +61,19 @@ jobs: echo "::error:: Expected file $notexpect found in ${{ steps.two.outputs.files }}" exit 1 fi + + - name: Run ShellCheck + uses: ./ + id: three + with: + scandir: './testfiles/scandir' + all_scripts: true + + - name: Verify check + run: | + expect="testfiles/scandir/unknown-shebang" + + if [[ ! "${{ steps.two.outputs.files }}" =~ $expect ]];then + echo "::error:: Expected file $expect not found in ${{ steps.two.outputs.files }}" + exit 1 + fi diff --git a/action.yaml b/action.yaml index 130781e..b6417a0 100644 --- a/action.yaml +++ b/action.yaml @@ -6,6 +6,10 @@ inputs: description: "A space separated list of additional filename to check" required: false default: "" + all_scripts: + description: "Set to true to check all executable scripts. The default is to check only ones with known shebangs" + required: false + default: "" ignore: description: "Paths to ignore when running ShellCheck" required: false @@ -147,6 +151,7 @@ runs: shell: bash id: check env: + INPUT_ALL_SCRIPTS: ${{ inputs.all_scripts }} INPUT_SCANDIR: ${{ inputs.scandir }} INPUT_CHECK_TOGETHER: ${{ inputs.check_together }} INPUT_EXCLUDE_ARGS: ${{ steps.exclude.outputs.excludes }} @@ -155,7 +160,8 @@ runs: run: | statuscode=0 declare -a filepaths - shebangregex="^#! */[^ ]*/(env *)?[abk]*sh" + shebangregex="^#!" + [ "$INPUT_ALL_SCRIPTS" = "true" ] || shebangregex="^#! */[^ ]*/(env *)?[abk]*sh" set -f # temporarily disable globbing so that globs in inputs aren't expanded diff --git a/testfiles/scandir/unknown-shebang b/testfiles/scandir/unknown-shebang new file mode 100755 index 0000000..05ec3e9 --- /dev/null +++ b/testfiles/scandir/unknown-shebang @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv bashio + +echo "hi" \ No newline at end of file From 03e95a94e01823e69bf9db9a33d2aaaad87a38c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 24 Oct 2024 18:13:49 +0200 Subject: [PATCH 2/2] Fix shebang test --- .github/workflows/scandir.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scandir.yml b/.github/workflows/scandir.yml index d6f5159..bc337b1 100644 --- a/.github/workflows/scandir.yml +++ b/.github/workflows/scandir.yml @@ -73,7 +73,7 @@ jobs: run: | expect="testfiles/scandir/unknown-shebang" - if [[ ! "${{ steps.two.outputs.files }}" =~ $expect ]];then - echo "::error:: Expected file $expect not found in ${{ steps.two.outputs.files }}" + if [[ ! "${{ steps.three.outputs.files }}" =~ $expect ]];then + echo "::error:: Expected file $expect not found in ${{ steps.three.outputs.files }}" exit 1 fi