mirror of
https://github.com/ludeeus/action-shellcheck.git
synced 2025-09-16 21:26:27 +02:00
Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2394c9008b | ||
![]() |
637bb438ec | ||
![]() |
2f2aa0d97f | ||
![]() |
c79c26d324 | ||
![]() |
35d6c4c933 | ||
![]() |
142c6d53df | ||
![]() |
06cf1c7f5d | ||
![]() |
513f424cc7 | ||
![]() |
fbd26dc426 | ||
![]() |
f22efe748c | ||
![]() |
b44aa9b87a | ||
![]() |
acc4e4fe97 | ||
![]() |
6eb62923bc | ||
![]() |
3a4806a465 | ||
![]() |
21696cbf1a | ||
![]() |
fa3cc6ede4 | ||
![]() |
18c29dd450 | ||
![]() |
c07d062aa5 | ||
![]() |
a1eeadd7ec | ||
![]() |
f615dc5486 | ||
![]() |
b443c466bf | ||
![]() |
35efb355bc | ||
![]() |
5e7f90b47a | ||
![]() |
70c0c19934 | ||
![]() |
9f3543661d | ||
![]() |
746dd2ddc0 | ||
![]() |
88a963fbeb | ||
![]() |
2e9d4c556d | ||
![]() |
9445381284 | ||
![]() |
370adf4cb6 |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
* text=auto eol=lf
|
8
.github/main.workflow
vendored
8
.github/main.workflow
vendored
@@ -1,8 +0,0 @@
|
||||
workflow "Trigger: Push" {
|
||||
on = "push"
|
||||
resolves = ["Shellcheck"]
|
||||
}
|
||||
|
||||
action "Shellcheck" {
|
||||
uses = "ludeeus/action-shellcheck@master"
|
||||
}
|
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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
13
.github/workflows/ShellCheck.yml
vendored
Normal file
13
.github/workflows/ShellCheck.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
on: [push, pull_request]
|
||||
name: 'ShellCheck'
|
||||
jobs:
|
||||
shellcheck:
|
||||
name: ShellCheck
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
- name: Run ShellCheck
|
||||
uses: ./
|
||||
with:
|
||||
ignore: ignore
|
18
Dockerfile
18
Dockerfile
@@ -1,16 +1,6 @@
|
||||
FROM debian:latest
|
||||
FROM alpine:3.12.0
|
||||
|
||||
COPY runaction.sh /runaction.sh
|
||||
RUN chmod +x /runaction.sh
|
||||
RUN apt update
|
||||
RUN apt install -y shellcheck
|
||||
RUN apk add --no-cache shellcheck bash
|
||||
|
||||
ENTRYPOINT ["/runaction.sh"]
|
||||
|
||||
LABEL "name"="shellcheck"
|
||||
LABEL "maintainer"="Ludeeus <ludeeus@gmail.com>"
|
||||
LABEL "version"="0.1.0"
|
||||
LABEL "com.github.actions.name"="shellcheck"
|
||||
LABEL "com.github.actions.description"="Run shell check on ALL sh files in the repository."
|
||||
LABEL "com.github.actions.icon"="terminal"
|
||||
LABEL "com.github.actions.color"="black"
|
||||
COPY runaction /action/runaction
|
||||
ENTRYPOINT ["bash", "/action/runaction"]
|
97
README.md
97
README.md
@@ -1,24 +1,89 @@
|
||||
# SHELLCHECK
|
||||
# ShellCheck
|
||||
|
||||
[![BuyMeCoffee][buymecoffeebedge]][buymecoffee]
|
||||
|
||||
_Run shellcheck on ALL sh files in the repository._
|
||||
_GitHub action for ShellCheck._
|
||||
|
||||
## Example
|
||||
|
||||
```
|
||||
workflow "Shellcheck" {
|
||||
on = "push"
|
||||
resolves = [
|
||||
"Shellcheck",
|
||||
]
|
||||
}
|
||||
```yaml
|
||||
on:
|
||||
push:
|
||||
branch:
|
||||
- master
|
||||
|
||||
name: 'Trigger: Push action'
|
||||
|
||||
action "Shellcheck" {
|
||||
uses = "ludeeus/actions/shellcheck@master"
|
||||
}
|
||||
jobs:
|
||||
shellcheck:
|
||||
name: Shellcheck
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Run ShellCheck
|
||||
uses: ludeeus/action-shellcheck@master
|
||||
```
|
||||
|
||||
[buymecoffee]: https://www.buymeacoffee.com/ludeeus
|
||||
[buymecoffeebedge]: https://camo.githubusercontent.com/cd005dca0ef55d7725912ec03a936d3a7c8de5b5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275792532306d6525323061253230636f666665652d646f6e6174652d79656c6c6f772e737667
|
||||
## Globally disable checks
|
||||
|
||||
To disable specific checks add it to a `SHELLCHECK_OPTS` env key in the job definition.
|
||||
|
||||
example:
|
||||
|
||||
```yaml
|
||||
...
|
||||
- name: Run ShellCheck
|
||||
uses: ludeeus/action-shellcheck@master
|
||||
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`
|
||||
|
||||
## 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.
|
||||
|
22
action.yaml
Normal file
22
action.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
name: "ShellCheck"
|
||||
author: "Ludeeus <hi@ludeeus.dev>"
|
||||
description: "GitHub action for ShellCheck."
|
||||
inputs:
|
||||
ignore:
|
||||
description: 'Paths to ignore when running ShellCheck'
|
||||
required: false
|
||||
default: ''
|
||||
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'
|
||||
image: 'Dockerfile'
|
||||
branding:
|
||||
icon: 'terminal'
|
||||
color: 'gray-dark'
|
84
runaction
Executable file
84
runaction
Executable file
@@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
|
||||
## Enable problem matcher
|
||||
|
||||
cd "$GITHUB_WORKSPACE" || exit 1
|
||||
|
||||
declare statuscode
|
||||
declare -a filepaths
|
||||
declare -a excludes
|
||||
declare -a tmp
|
||||
|
||||
statuscode=0
|
||||
|
||||
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 -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 '*/.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
|
||||
|
||||
[[ -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"
|
@@ -1,6 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd "$GITHUB_WORKSPACE" || exit 1
|
||||
find . -name \*.sh -exec shellcheck {} +
|
||||
find . -name \*.bashrc -exec shellcheck {} +
|
||||
find . -name \*.bash_profile -exec shellcheck {} +
|
5
testfiles/ignore/ignore.sh
Normal file
5
testfiles/ignore/ignore.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo $test $test
|
||||
|
||||
echo $test2
|
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"
|
Reference in New Issue
Block a user