34 Commits
0.1.0 ... 0.5.0

Author SHA1 Message Date
Joakim Sørensen
c489c81f79 Re enable problem-matcher (#25) 2020-07-28 14:21:49 +02:00
pvogt09
73cbb64041 Fixes issues with globbing files with partial match(#23)
Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
2020-07-28 13:54:55 +02:00
Tom Riat
c7d4e499f1 Update action checkout to the new default branch (#24)
Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
2020-07-28 10:59:37 +02:00
Oscar Tin Lai
7ee62c0418 Enable shellcheck for shebang with /bin/env (#22)
Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
2020-07-14 20:39:58 +02:00
Joakim Sørensen
2394c9008b Remove problem matcher
Fixes #21
2020-07-14 20:29:42 +02:00
Joakim Sørensen
637bb438ec Adds problem-matcher (#20)
* Adds problem-matcher

* Fix issue

* match as group 1

* use message

* Limit output

* remove testfile
2020-07-05 23:50:07 +02:00
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
14 changed files with 261 additions and 43 deletions

1
.gitattributes vendored Normal file
View File

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

View File

@@ -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
View 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
}
]
}
]
}

15
.github/workflows/ShellCheck.yml vendored Normal file
View File

@@ -0,0 +1,15 @@
on: [push, pull_request]
name: 'ShellCheck'
jobs:
shellcheck:
name: ShellCheck
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run ShellCheck
uses: ./
with:
ignore: ignore

View File

@@ -1,16 +1,8 @@
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"]
COPY runaction /action/runaction
COPY .github/problem-matcher.json /problem-matcher.json
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"
ENTRYPOINT ["bash", "/action/runaction"]

View File

@@ -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@v2
- 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
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'

93
runaction Executable file
View 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"

View File

@@ -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 {} +

6
testfiles/bashfile.c Normal file
View File

@@ -0,0 +1,6 @@
/* C code test file
* file that should not be matched for shellcheck runs
*/
int main(void) {
return 0;
}

View File

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

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"