Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclude and testfiles #13

Merged
merged 7 commits into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
11 changes: 7 additions & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ on: push
name: 'Trigger: Push'
jobs:
shellcheck:
name: Shellcheck
name: ShellCheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Shellcheck
uses: ludeeus/action-shellcheck@master
- name: Checkout
uses: actions/checkout@master
- name: Run ShellCheck
uses: ./
with:
ignore: ignore
10 changes: 1 addition & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"
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"]
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -37,3 +35,25 @@ example:
env:
SHELLCHECK_OPTS: -e SC2059 -e SC2034 -e SC1090
```

## Ignore 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`
14 changes: 14 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "ShellCheck"
author: "Ludeeus <[email protected]>"
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'
25 changes: 17 additions & 8 deletions runaction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@

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
echo "::debug:: Adding '${path}' to excludes"
excludes+=(! -path "*./${path}/*" )
excludes+=(! -path "*/${path}/*" )
done

readarray -d '' filepaths < <(find . "${excludes[@]}" \
'(' \
\
-name '*.bash' \
-o -path '*/.bash*' \
Expand Down Expand Up @@ -37,27 +46,27 @@ 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"
fi

for file in "${filepaths[@]}"; do
echo "::debug:: Checking $file"
shellcheck "$file" || err=$?
shellcheck "$file" || statuscode=$?
done

exit "$err"
exit "$statuscode"
3 changes: 3 additions & 0 deletions testfiles/ignore/ignore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

echo $test
4 changes: 4 additions & 0 deletions testfiles/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

test="test"
echo "$test"
3 changes: 3 additions & 0 deletions testfiles/test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"
4 changes: 4 additions & 0 deletions testfiles/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/sh

test="test"
echo "$test"