29 Commits
0.0.1 ... 0.3.0

Author SHA1 Message Date
ludeeus
2f2aa0d97f Update alpine to 3.12.0 2020-06-27 19:42:52 +02:00
Daniel
c79c26d324 Add filetype to find command (#19)
This fixes an error when a directory contains "bash" in the name. This
would lead to a shellcheck on a directory and crash.
2020-06-27 11:43:04 +02:00
Brandon W Maister
35d6c4c933 Add the ability to check all scripts in one shellcheck command (#17)
This is the most straightforward way to allow sourcing scripts, as shellcheck
[SC1090] only allows `source` files that are in the same invocation, I believe
unless `-x` is also specified.

[SC1090]: https://github.com/koalaman/shellcheck/wiki/SC1090
2020-06-26 21:41:45 +02:00
Ilir Bekteshi
142c6d53df Add severity input (#16)
Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
2020-06-26 08:05:34 +02:00
Joakim Sørensen
06cf1c7f5d Update and rename push.yml to ShellCheck.yml 2020-06-25 12:20:30 +02:00
Gareth Healy
513f424cc7 Added mvnw to excludes (#15) 2020-06-10 11:56:06 +02:00
ludeeus
fbd26dc426 Exclude go and profile 2020-06-07 16:53:52 +02:00
Joakim Sørensen
f22efe748c Merge pull request #13 from ludeeus/testfiles
Add exclude and testfiles
2020-05-30 12:02:57 +02:00
ludeeus
b44aa9b87a Update 2020-05-30 12:02:32 +02:00
ludeeus
acc4e4fe97 take both 2020-05-30 12:01:39 +02:00
ludeeus
6eb62923bc Update 2020-05-30 12:00:24 +02:00
ludeeus
3a4806a465 Update readme 2020-05-30 11:57:50 +02:00
ludeeus
21696cbf1a simplify 2020-05-30 11:55:03 +02:00
ludeeus
fa3cc6ede4 Use self 2020-05-30 11:46:07 +02:00
ludeeus
18c29dd450 Add exclude and testfiles 2020-05-30 11:44:01 +02:00
ludeeus
c07d062aa5 Fix remnants of tests 2020-05-30 00:12:17 +02:00
ludeeus
a1eeadd7ec Add back bash 2020-05-30 00:06:50 +02:00
ludeeus
f615dc5486 restructure 2020-05-30 00:06:39 +02:00
ludeeus
b443c466bf Remove bash 2020-05-29 23:13:38 +02:00
ludeeus
35efb355bc Update README 2020-05-29 23:11:34 +02:00
ludeeus
5e7f90b47a Move image to alpine 2020-05-29 23:11:06 +02:00
Joakim Sørensen
70c0c19934 Merge pull request #10 from cramte/fix-runaction-exitcode
Fix runaction.sh return values
2020-05-05 08:29:47 +02:00
cramte
9f3543661d Fix runaction.sh return values 2020-05-03 22:11:15 +02:00
Joakim Sørensen
746dd2ddc0 Merge pull request #4 from kurahaupo/patch-1
apply to all Bash, Ksh, Zsh & POSIX Shell files
2019-12-01 10:17:06 +01:00
Joakim Sørensen
88a963fbeb Merge pull request #2 from tchia04/migrate_to_yml
converted main.workflow to Actions V2 yml files
2019-11-29 22:30:12 +01:00
Martin Kealey
2e9d4c556d Update runaction.sh 2019-11-20 16:56:37 +11:00
Martin Kealey
9445381284 apply to all Bash, Ksh, Zsh & POSIX Shell files
Does not need bash to run; standard posix sh suffices.

Apply shellcheck to:

* files with shbang lines that indicate a shell (sh, bash, ash, bsh, ksh, zsh)

* typical home directory shell startup files:
  for posix sh & all shells: .profile
  for bash: .bashrc, .bash_aliases, .bash_completion, .bash_login, .bash_logout, .bash_profile
  for ksh: .profile
  for zsh: .zprofile, .zlogin, .zlogout, .zshenv, .zshrc

* typical system-wide shell startup files:
  for posix sh & all shells: /etc/profile
  for bash: /etc/bashrc, /etc/bash_profile
  for ksh:
  for zsh: /etc/zprofile, /etc/zlogin, /etc/zlogout, /etc/zshenv, /etc/zshrc

* files with suffixes: .bash, .zsh, .ksh, & .sh
2019-11-20 16:45:19 +11:00
Tony Chia
370adf4cb6 converted main.workflow to Actions V2 yml files 2019-09-18 13:28:56 -07:00
ludeeus
43d591f972 Add support for .bashrc and .bash_profile 2019-03-14 18:15:36 +01:00
12 changed files with 217 additions and 50 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
* text=auto eol=lf

16
.github/main.workflow vendored
View File

@@ -1,16 +0,0 @@
workflow "Trigger: Push" {
on = "push"
resolves = [
"Shellcheck",
"Black Code Formatter",
]
}
action "Shellcheck" {
uses = "ludeeus/action-shellcheck@master"
}
action "Black Code Formatter" {
uses = "lgeiger/black-action@master"
args = "$GITHUB_WORKSPACE --check"
}

13
.github/workflows/ShellCheck.yml vendored Normal file
View 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

View File

@@ -1,16 +1,6 @@
FROM debian:latest FROM alpine:3.12.0
COPY runaction.sh /runaction.sh RUN apk add --no-cache shellcheck bash
RUN chmod +x /runaction.sh
RUN apt update
RUN apt install -y shellcheck
ENTRYPOINT ["/runaction.sh"] COPY runaction /action/runaction
ENTRYPOINT ["bash", "/action/runaction"]
LABEL "name"="shellcheck"
LABEL "maintainer"="Ludeeus <ludeeus@gmail.com>"
LABEL "version"="0.0.1"
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"

View File

@@ -1,24 +1,89 @@
# SHELLCHECK # ShellCheck
[![BuyMeCoffee][buymecoffeebedge]][buymecoffee] _GitHub action for ShellCheck._
_Run shellcheck on ALL sh files in the repository._
## Example ## Example
``` ```yaml
workflow "Shellcheck" { on:
on = "push" push:
resolves = [ branch:
"Shellcheck", - master
]
}
name: 'Trigger: Push action'
action "Shellcheck" { jobs:
uses = "ludeeus/actions/shellcheck@master" 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 ## Globally disable checks
[buymecoffeebedge]: https://camo.githubusercontent.com/cd005dca0ef55d7725912ec03a936d3a7c8de5b5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275792532306d6525323061253230636f666665652d646f6e6174652d79656c6c6f772e737667
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
View 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'

82
runaction Executable file
View File

@@ -0,0 +1,82 @@
#!/bin/bash
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"

View File

@@ -1,4 +0,0 @@
#!/bin/bash
cd "$GITHUB_WORKSPACE" || exit 1
find . -name \*.sh -exec shellcheck {} +

View File

@@ -0,0 +1,3 @@
#!/bin/sh
echo $test

4
testfiles/test Normal file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
test="test"
echo "$test"

3
testfiles/test.bash Normal file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"

4
testfiles/test.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/sh
test="test"
echo "$test"