mirror of
https://github.com/ludeeus/action-shellcheck.git
synced 2025-09-16 21:26:27 +02:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c489c81f79 | ||
![]() |
73cbb64041 | ||
![]() |
c7d4e499f1 | ||
![]() |
7ee62c0418 | ||
![]() |
2394c9008b | ||
![]() |
637bb438ec | ||
![]() |
2f2aa0d97f | ||
![]() |
c79c26d324 | ||
![]() |
35d6c4c933 | ||
![]() |
142c6d53df | ||
![]() |
06cf1c7f5d | ||
![]() |
513f424cc7 | ||
![]() |
fbd26dc426 |
22
.github/problem-matcher.json
vendored
Normal file
22
.github/problem-matcher.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"problemMatcher": [
|
||||||
|
{
|
||||||
|
"owner": "shellcheck",
|
||||||
|
"pattern": [
|
||||||
|
{
|
||||||
|
"regexp": "^In\\s(.+)\\sline\\s(\\d+):$",
|
||||||
|
"file": 1,
|
||||||
|
"line": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"regexp": ".*"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"regexp": "(SC\\d+):\\s(.+)$",
|
||||||
|
"code": 1,
|
||||||
|
"message": 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@@ -1,12 +1,14 @@
|
|||||||
on: push
|
on: [push, pull_request]
|
||||||
name: 'Trigger: Push'
|
name: 'ShellCheck'
|
||||||
jobs:
|
jobs:
|
||||||
shellcheck:
|
shellcheck:
|
||||||
name: ShellCheck
|
name: ShellCheck
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
@@ -1,6 +1,8 @@
|
|||||||
FROM alpine:3.11.6
|
FROM alpine:3.12.0
|
||||||
|
|
||||||
RUN apk add --no-cache shellcheck bash
|
RUN apk add --no-cache shellcheck bash
|
||||||
|
|
||||||
COPY runaction.sh /action/runaction.sh
|
COPY runaction /action/runaction
|
||||||
ENTRYPOINT ["bash", "/action/runaction.sh"]
|
COPY .github/problem-matcher.json /problem-matcher.json
|
||||||
|
|
||||||
|
ENTRYPOINT ["bash", "/action/runaction"]
|
34
README.md
34
README.md
@@ -5,7 +5,7 @@ _GitHub action for ShellCheck._
|
|||||||
## Example
|
## Example
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branch:
|
branch:
|
||||||
- master
|
- master
|
||||||
@@ -17,7 +17,7 @@ jobs:
|
|||||||
name: Shellcheck
|
name: Shellcheck
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@v2
|
||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ludeeus/action-shellcheck@master
|
uses: ludeeus/action-shellcheck@master
|
||||||
```
|
```
|
||||||
@@ -57,3 +57,33 @@ example:
|
|||||||
```
|
```
|
||||||
|
|
||||||
This will skip `sample/directory/with/files/toignore/test.sh`
|
This will skip `sample/directory/with/files/toignore/test.sh`
|
||||||
|
|
||||||
|
## Minimum severity of errors to consider (error, warning, info, style)
|
||||||
|
|
||||||
|
You can use the `severity` input to not fail until specified severity is met, for example fail only if there are errors in scripts but ignore styling, info and warnings.
|
||||||
|
|
||||||
|
example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
...
|
||||||
|
- name: Run ShellCheck
|
||||||
|
uses: ludeeus/action-shellcheck@master
|
||||||
|
with:
|
||||||
|
severity: error
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run shellcheck with all paths in a single invocation
|
||||||
|
|
||||||
|
If you run into SC1090/SC1091 errors you may need to tell shellcheck to check
|
||||||
|
all files at once:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
...
|
||||||
|
- name: Run ShellCheck
|
||||||
|
uses: ludeeus/action-shellcheck@master
|
||||||
|
with:
|
||||||
|
check_together: 'yes'
|
||||||
|
```
|
||||||
|
|
||||||
|
This can turn into a problem if you have enough script files to overwhelm the
|
||||||
|
maximum argv length on your system.
|
||||||
|
14
action.yaml
14
action.yaml
@@ -6,9 +6,17 @@ inputs:
|
|||||||
description: 'Paths to ignore when running ShellCheck'
|
description: 'Paths to ignore when running ShellCheck'
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
runs:
|
severity:
|
||||||
|
description: 'Minimum severity of errors to consider. Options: [error, warning, info, style]'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
check_together:
|
||||||
|
description: 'Run shellcheck on _all_ files at once, instead of one at a time'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'Dockerfile'
|
image: 'Dockerfile'
|
||||||
branding:
|
branding:
|
||||||
icon: 'terminal'
|
icon: 'terminal'
|
||||||
color: 'gray-dark'
|
color: 'gray-dark'
|
||||||
|
93
runaction
Executable file
93
runaction
Executable file
@@ -0,0 +1,93 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
## Enable problem matcher
|
||||||
|
cp /problem-matcher.json ./problem-matcher.json
|
||||||
|
|
||||||
|
echo "::add-matcher::problem-matcher.json"
|
||||||
|
|
||||||
|
## Run action
|
||||||
|
cd "$GITHUB_WORKSPACE" || exit 1
|
||||||
|
|
||||||
|
declare statuscode
|
||||||
|
declare -a filepaths
|
||||||
|
declare -a excludes
|
||||||
|
declare -a tmp
|
||||||
|
|
||||||
|
statuscode=0
|
||||||
|
shebangregex="^#! */[^ ]*/(env *)?[abkz]*sh"
|
||||||
|
|
||||||
|
excludes+=( ! -path *./.git/* )
|
||||||
|
excludes+=( ! -path *.go )
|
||||||
|
excludes+=( ! -path */mvnw )
|
||||||
|
|
||||||
|
for path in ${INPUT_IGNORE}; do
|
||||||
|
echo "::debug:: Adding '${path}' to excludes"
|
||||||
|
excludes+=(! -path "*./${path}/*" )
|
||||||
|
excludes+=(! -path "*/${path}/*" )
|
||||||
|
done
|
||||||
|
|
||||||
|
readarray -d '' filepaths < <(find . -type f "${excludes[@]}" \
|
||||||
|
'(' \
|
||||||
|
\
|
||||||
|
-name '*.bash' \
|
||||||
|
-o -name '.bashrc' \
|
||||||
|
-o -name 'bashrc' \
|
||||||
|
-o -name '.bash_aliases' \
|
||||||
|
-o -name '.bash_completion' \
|
||||||
|
-o -name '.bash_login' \
|
||||||
|
-o -name '.bash_logout' \
|
||||||
|
-o -name '.bash_profile' \
|
||||||
|
-o -name 'bash_profile' \
|
||||||
|
-o -name '*.ksh' \
|
||||||
|
-o -name 'suid_profile' \
|
||||||
|
-o -name '*.zsh' \
|
||||||
|
-o -name '.zlogin' \
|
||||||
|
-o -name 'zlogin' \
|
||||||
|
-o -name '.zlogout' \
|
||||||
|
-o -name 'zlogout' \
|
||||||
|
-o -name '.zprofile' \
|
||||||
|
-o -name 'zprofile' \
|
||||||
|
-o -name '.zsenv' \
|
||||||
|
-o -name 'zsenv' \
|
||||||
|
-o -name '.zshrc' \
|
||||||
|
-o -name 'zshrc' \
|
||||||
|
-o -name '*.sh' \
|
||||||
|
-o -path '*/.profile' \
|
||||||
|
-o -path '*/profile' \
|
||||||
|
-o -name '*.shlib' \
|
||||||
|
')'\
|
||||||
|
\
|
||||||
|
-print0)
|
||||||
|
|
||||||
|
readarray -d '' tmp < <(find . "${excludes[@]}" -type f ! -name '*.*' -perm /111 -print0)
|
||||||
|
for file in "${tmp[@]}"; do
|
||||||
|
head -n1 "$file" | grep -Eqs "$shebangregex" || continue
|
||||||
|
filepaths+=("$file")
|
||||||
|
done
|
||||||
|
|
||||||
|
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 . "${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
|
||||||
|
|
||||||
|
[[ -n "${INPUT_SEVERITY}" ]] && options+=(-S "${INPUT_SEVERITY}")
|
||||||
|
|
||||||
|
if [[ -n "$INPUT_CHECK_TOGETHER" ]]; then
|
||||||
|
echo "::debug:: shellcheck ${options[*]} ${filepaths[*]}"
|
||||||
|
shellcheck "${options[@]}" "${filepaths[@]}" || statuscode=$?
|
||||||
|
else
|
||||||
|
echo "::debug:: Shellcheck options: ${options[*]}"
|
||||||
|
for file in "${filepaths[@]}"; do
|
||||||
|
echo "::debug:: Checking $file"
|
||||||
|
shellcheck "${options[@]}" "$file" || statuscode=$?
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit "$statuscode"
|
72
runaction.sh
72
runaction.sh
@@ -1,72 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
cd "$GITHUB_WORKSPACE" || exit 1
|
|
||||||
|
|
||||||
declare statuscode
|
|
||||||
declare -a filepaths
|
|
||||||
declare -a excludes
|
|
||||||
declare -a tmp
|
|
||||||
|
|
||||||
statuscode=0
|
|
||||||
|
|
||||||
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*' \
|
|
||||||
-o -path '*/bash*' \
|
|
||||||
-o -name '*.ksh' \
|
|
||||||
-o -name 'ksh*' \
|
|
||||||
-o -path '*/.ksh*' \
|
|
||||||
-o -path '*/ksh*' \
|
|
||||||
-o -name 'suid_profile' \
|
|
||||||
-o -name '*.zsh' \
|
|
||||||
-o -name '.zlogin*' \
|
|
||||||
-o -name 'zlogin*' \
|
|
||||||
-o -name '.zlogout*' \
|
|
||||||
-o -name 'zlogout*' \
|
|
||||||
-o -name '.zprofile*' \
|
|
||||||
-o -name 'zprofile*' \
|
|
||||||
-o -path '*/.zsh*' \
|
|
||||||
-o -path '*/zsh*' \
|
|
||||||
-o -name '*.sh' \
|
|
||||||
-o -path '*/.profile*' \
|
|
||||||
-o -path '*/profile*' \
|
|
||||||
-o -path '*/.shlib*' \
|
|
||||||
-o -path '*/shlib*' \
|
|
||||||
')'\
|
|
||||||
\
|
|
||||||
-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 . "${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 . "${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" || statuscode=$?
|
|
||||||
done
|
|
||||||
|
|
||||||
exit "$statuscode"
|
|
6
testfiles/bashfile.c
Normal file
6
testfiles/bashfile.c
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/* C code test file
|
||||||
|
* file that should not be matched for shellcheck runs
|
||||||
|
*/
|
||||||
|
int main(void) {
|
||||||
|
return 0;
|
||||||
|
}
|
@@ -1,3 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo $test
|
echo $test $test
|
||||||
|
|
||||||
|
echo $test2
|
Reference in New Issue
Block a user