mirror of
https://github.com/ludeeus/action-shellcheck.git
synced 2025-01-19 01:52:00 +01:00
Merge pull request #13 from ludeeus/testfiles
Add exclude and testfiles
This commit is contained in:
commit
f22efe748c
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
* text=auto eol=lf
|
11
.github/workflows/push.yml
vendored
11
.github/workflows/push.yml
vendored
@ -2,9 +2,12 @@ on: push
|
|||||||
name: 'Trigger: Push'
|
name: 'Trigger: Push'
|
||||||
jobs:
|
jobs:
|
||||||
shellcheck:
|
shellcheck:
|
||||||
name: Shellcheck
|
name: ShellCheck
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- name: Checkout
|
||||||
- name: Shellcheck
|
uses: actions/checkout@master
|
||||||
uses: ludeeus/action-shellcheck@master
|
- name: Run ShellCheck
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
ignore: ignore
|
||||||
|
@ -4,11 +4,3 @@ RUN apk add --no-cache shellcheck bash
|
|||||||
|
|
||||||
COPY runaction.sh /action/runaction.sh
|
COPY runaction.sh /action/runaction.sh
|
||||||
ENTRYPOINT ["bash", "/action/runaction.sh"]
|
ENTRYPOINT ["bash", "/action/runaction.sh"]
|
||||||
|
|
||||||
LABEL "name"="ShellCheck"
|
|
||||||
LABEL "maintainer"="Ludeeus <hi@ludeeus.dev>"
|
|
||||||
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"
|
|
||||||
|
24
README.md
24
README.md
@ -22,8 +22,6 @@ jobs:
|
|||||||
uses: ludeeus/action-shellcheck@master
|
uses: ludeeus/action-shellcheck@master
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Globally disable checks
|
## Globally disable checks
|
||||||
|
|
||||||
To disable specific checks add it to a `SHELLCHECK_OPTS` env key in the job definition.
|
To disable specific checks add it to a `SHELLCHECK_OPTS` env key in the job definition.
|
||||||
@ -37,3 +35,25 @@ example:
|
|||||||
env:
|
env:
|
||||||
SHELLCHECK_OPTS: -e SC2059 -e SC2034 -e SC1090
|
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
action.yaml
Normal file
14
action.yaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
name: "ShellCheck"
|
||||||
|
author: "Ludeeus <hi@ludeeus.dev>"
|
||||||
|
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
runaction.sh
25
runaction.sh
@ -2,13 +2,22 @@
|
|||||||
|
|
||||||
cd "$GITHUB_WORKSPACE" || exit 1
|
cd "$GITHUB_WORKSPACE" || exit 1
|
||||||
|
|
||||||
declare err
|
declare statuscode
|
||||||
declare -a filepaths
|
declare -a filepaths
|
||||||
|
declare -a excludes
|
||||||
declare -a tmp
|
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' \
|
-name '*.bash' \
|
||||||
-o -path '*/.bash*' \
|
-o -path '*/.bash*' \
|
||||||
@ -37,19 +46,19 @@ readarray -d '' filepaths < <(find . '(' \
|
|||||||
-print0)
|
-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
|
for file in "${tmp[@]}"; do
|
||||||
head -n1 "$file" | grep -Eqs "^#! */[^ ]*/[abkz]*sh" || continue
|
head -n1 "$file" | grep -Eqs "^#! */[^ ]*/[abkz]*sh" || continue
|
||||||
filepaths+=("$file")
|
filepaths+=("$file")
|
||||||
done
|
done
|
||||||
|
|
||||||
if find . -path '*bin/*/*' -type f -perm /111 -print |
|
if find . "${excludes[@]}" -path '*bin/*/*' -type f -perm /111 -print |
|
||||||
grep .
|
grep .
|
||||||
then
|
then
|
||||||
echo >&2 "::warning:: subdirectories of bin directories are not usable via PATH"
|
echo >&2 "::warning:: subdirectories of bin directories are not usable via PATH"
|
||||||
fi
|
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 .
|
grep .
|
||||||
then
|
then
|
||||||
echo >&2 "::warning:: programs in PATH should not have a filename suffix"
|
echo >&2 "::warning:: programs in PATH should not have a filename suffix"
|
||||||
@ -57,7 +66,7 @@ fi
|
|||||||
|
|
||||||
for file in "${filepaths[@]}"; do
|
for file in "${filepaths[@]}"; do
|
||||||
echo "::debug:: Checking $file"
|
echo "::debug:: Checking $file"
|
||||||
shellcheck "$file" || err=$?
|
shellcheck "$file" || statuscode=$?
|
||||||
done
|
done
|
||||||
|
|
||||||
exit "$err"
|
exit "$statuscode"
|
3
testfiles/ignore/ignore.sh
Normal file
3
testfiles/ignore/ignore.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo $test
|
4
testfiles/test
Normal file
4
testfiles/test
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
test="test"
|
||||||
|
echo "$test"
|
3
testfiles/test.bash
Normal file
3
testfiles/test.bash
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
test="test"
|
||||||
|
echo "$test"
|
4
testfiles/test.sh
Normal file
4
testfiles/test.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/sh
|
||||||
|
|
||||||
|
test="test"
|
||||||
|
echo "$test"
|
Loading…
x
Reference in New Issue
Block a user