From 18c29dd450b4a9aba94e1c5fb55acf0e2e6aa8c8 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Sat, 30 May 2020 11:44:01 +0200 Subject: [PATCH 1/7] Add exclude and testfiles --- .gitattributes | 1 + .github/workflows/push.yml | 6 ++++-- Dockerfile | 10 +--------- action.yaml | 14 ++++++++++++++ runaction.sh | 26 ++++++++++++++++++-------- testfiles/ignore/ignore.sh | 3 +++ testfiles/test | 4 ++++ testfiles/test.bash | 3 +++ testfiles/test.sh | 4 ++++ 9 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 .gitattributes create mode 100644 action.yaml create mode 100644 testfiles/ignore/ignore.sh create mode 100644 testfiles/test create mode 100644 testfiles/test.bash create mode 100644 testfiles/test.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..94f480d --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf \ No newline at end of file diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 107bbc6..8e77b5b 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -6,5 +6,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - - name: Shellcheck - uses: ludeeus/action-shellcheck@master + - name: Run Shellcheck + uses: ${GITHUB_REPOSITORY}@${GITHUB_SHA} + with: + ignore: "ignore" diff --git a/Dockerfile b/Dockerfile index 49165ef..eddf64c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,4 @@ FROM alpine:3.11.6 RUN apk add --no-cache shellcheck bash COPY runaction.sh /action/runaction.sh -ENTRYPOINT ["bash", "/action/runaction.sh"] - -LABEL "name"="ShellCheck" -LABEL "maintainer"="Ludeeus " -LABEL "version"="0.1.0" -LABEL "com.github.actions.name"="ShellCheck" -LABEL "com.github.actions.description"="GitHub action for ShellCheck." -LABEL "com.github.actions.icon"="terminal" -LABEL "com.github.actions.color"="black" +ENTRYPOINT ["bash", "/action/runaction.sh"] \ No newline at end of file diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..5009b95 --- /dev/null +++ b/action.yaml @@ -0,0 +1,14 @@ +name: "ShellCheck" +author: "Ludeeus " +description: "GitHub action for ShellCheck." +inputs: + ignore: + description: 'Paths to ignore when running ShellCheck' + required: false + default: '' +runs: + using: 'docker' + image: 'Dockerfile' +branding: + icon: 'terminal' + color: 'gray-dark' \ No newline at end of file diff --git a/runaction.sh b/runaction.sh index 9f1aefe..3450120 100755 --- a/runaction.sh +++ b/runaction.sh @@ -2,13 +2,23 @@ cd "$GITHUB_WORKSPACE" || exit 1 -declare err +declare statuscode declare -a filepaths +declare -a excludes declare -a tmp -err=0 +statuscode=0 -readarray -d '' filepaths < <(find . '(' \ +excludes+=( ! -path *./.git/* ) +for path in ${INPUT_IGNORE}; do + [[ ${path#./*} != "$path" ]] || path=./${path} + + echo "::debug:: Adding '${path}' to excludes" + excludes+=(! -path *"${path}"* ) +done + +readarray -d '' filepaths < <(find . "${excludes[@]}" \ + '(' \ \ -name '*.bash' \ -o -path '*/.bash*' \ @@ -37,19 +47,19 @@ readarray -d '' filepaths < <(find . '(' \ -print0) -readarray -d '' tmp < <(find . -type f ! -name '*.*' -perm /111 -print0) +readarray -d '' tmp < <(find . "${excludes[@]}" -type f ! -name '*.*' -perm /111 -print0) for file in "${tmp[@]}"; do head -n1 "$file" | grep -Eqs "^#! */[^ ]*/[abkz]*sh" || continue filepaths+=("$file") done -if find . -path '*bin/*/*' -type f -perm /111 -print | +if find . "${excludes[@]}" -path '*bin/*/*' -type f -perm /111 -print | grep . then echo >&2 "::warning:: subdirectories of bin directories are not usable via PATH" fi -if find . -path '*bin/*' -name '*.*' -type f -perm /111 -perm /444 -print | +if find . "${excludes[@]}" -path '*bin/*' -name '*.*' -type f -perm /111 -perm /444 -print | grep . then echo >&2 "::warning:: programs in PATH should not have a filename suffix" @@ -57,7 +67,7 @@ fi for file in "${filepaths[@]}"; do echo "::debug:: Checking $file" - shellcheck "$file" || err=$? + shellcheck "$file" || statuscode=$? done -exit "$err" \ No newline at end of file +exit "$statuscode" \ No newline at end of file diff --git a/testfiles/ignore/ignore.sh b/testfiles/ignore/ignore.sh new file mode 100644 index 0000000..a77dd19 --- /dev/null +++ b/testfiles/ignore/ignore.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo $test \ No newline at end of file diff --git a/testfiles/test b/testfiles/test new file mode 100644 index 0000000..9470e18 --- /dev/null +++ b/testfiles/test @@ -0,0 +1,4 @@ +#!/bin/bash + +test="test" +echo "$test" \ No newline at end of file diff --git a/testfiles/test.bash b/testfiles/test.bash new file mode 100644 index 0000000..3ea25c6 --- /dev/null +++ b/testfiles/test.bash @@ -0,0 +1,3 @@ +#!/bin/bash +test="test" +echo "$test" \ No newline at end of file diff --git a/testfiles/test.sh b/testfiles/test.sh new file mode 100644 index 0000000..cfb414c --- /dev/null +++ b/testfiles/test.sh @@ -0,0 +1,4 @@ +#!/usr/bin/sh + +test="test" +echo "$test" \ No newline at end of file From fa3cc6ede4a65e2f9aae4b28371a7f6d1d46bb47 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Sat, 30 May 2020 11:46:07 +0200 Subject: [PATCH 2/7] Use self --- .github/workflows/push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 8e77b5b..f76d663 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -7,6 +7,6 @@ jobs: steps: - uses: actions/checkout@master - name: Run Shellcheck - uses: ${GITHUB_REPOSITORY}@${GITHUB_SHA} + uses: ./ with: ignore: "ignore" From 21696cbf1a596ca7bd2be50122a5b12fad608a6c Mon Sep 17 00:00:00 2001 From: ludeeus Date: Sat, 30 May 2020 11:55:03 +0200 Subject: [PATCH 3/7] simplify --- .github/workflows/push.yml | 3 ++- runaction.sh | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index f76d663..a85e862 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -5,7 +5,8 @@ jobs: name: Shellcheck runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - name: Checkout + uses: actions/checkout@master - name: Run Shellcheck uses: ./ with: diff --git a/runaction.sh b/runaction.sh index 3450120..27eaef1 100755 --- a/runaction.sh +++ b/runaction.sh @@ -11,10 +11,8 @@ statuscode=0 excludes+=( ! -path *./.git/* ) for path in ${INPUT_IGNORE}; do - [[ ${path#./*} != "$path" ]] || path=./${path} - echo "::debug:: Adding '${path}' to excludes" - excludes+=(! -path *"${path}"* ) + excludes+=(! -path *"./${path}/"* ) done readarray -d '' filepaths < <(find . "${excludes[@]}" \ From 3a4806a465837a729c6b953c5aee578c8bd10972 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Sat, 30 May 2020 11:57:50 +0200 Subject: [PATCH 4/7] Update readme --- README.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 37a1dfd..294beb8 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,6 @@ jobs: uses: ludeeus/action-shellcheck@master ``` - - ## Globally disable checks To disable specific checks add it to a `SHELLCHECK_OPTS` env key in the job definition. @@ -37,3 +35,25 @@ example: env: SHELLCHECK_OPTS: -e SC2059 -e SC2034 -e SC1090 ``` + +## Disable paths + +You can use the `ignore` input to disable specific directories. + +```text +sample structure: +sample/directory/with/files/toignore/test.sh +sample/directory/with/files/test.sh +``` + +example: + +```yaml + ... + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master + with: + ignore: toignore +``` + +This will skip `sample/directory/with/files/toignore/test.sh` From 6eb62923bcfa39a3da3adb6346a242af676296f5 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Sat, 30 May 2020 12:00:24 +0200 Subject: [PATCH 5/7] Update --- .github/workflows/push.yml | 2 +- README.md | 2 +- runaction.sh | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index a85e862..5f0c204 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -10,4 +10,4 @@ jobs: - name: Run Shellcheck uses: ./ with: - ignore: "ignore" + ignore: ignore diff --git a/README.md b/README.md index 294beb8..cc5e239 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ example: SHELLCHECK_OPTS: -e SC2059 -e SC2034 -e SC1090 ``` -## Disable paths +## Ignore paths You can use the `ignore` input to disable specific directories. diff --git a/runaction.sh b/runaction.sh index 27eaef1..9ab034b 100755 --- a/runaction.sh +++ b/runaction.sh @@ -11,8 +11,8 @@ statuscode=0 excludes+=( ! -path *./.git/* ) for path in ${INPUT_IGNORE}; do - echo "::debug:: Adding '${path}' to excludes" - excludes+=(! -path *"./${path}/"* ) + echo "::debug:: Adding '*./${path}/*' to excludes" + excludes+=(! -path "*./${path}/*" ) done readarray -d '' filepaths < <(find . "${excludes[@]}" \ From acc4e4fe97c8d7fc3ccbd9b9a37af01c22a4376f Mon Sep 17 00:00:00 2001 From: ludeeus Date: Sat, 30 May 2020 12:01:39 +0200 Subject: [PATCH 6/7] take both --- runaction.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runaction.sh b/runaction.sh index 9ab034b..0107ce5 100755 --- a/runaction.sh +++ b/runaction.sh @@ -11,8 +11,9 @@ statuscode=0 excludes+=( ! -path *./.git/* ) for path in ${INPUT_IGNORE}; do - echo "::debug:: Adding '*./${path}/*' to excludes" + echo "::debug:: Adding '${path}' to excludes" excludes+=(! -path "*./${path}/*" ) + excludes+=(! -path "*/${path}/*" ) done readarray -d '' filepaths < <(find . "${excludes[@]}" \ From b44aa9b87a62e0e8453ddf6c086640338d08b367 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Sat, 30 May 2020 12:02:32 +0200 Subject: [PATCH 7/7] Update --- .github/workflows/push.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 5f0c204..bb1bfbf 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -2,12 +2,12 @@ on: push name: 'Trigger: Push' jobs: shellcheck: - name: Shellcheck + name: ShellCheck runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@master - - name: Run Shellcheck + - name: Run ShellCheck uses: ./ with: ignore: ignore