2020-05-29 23:11:34 +02:00
# ShellCheck
2019-03-09 11:25:14 +01:00
2020-05-29 23:11:34 +02:00
_GitHub action for ShellCheck._
2019-03-09 11:25:14 +01:00
## Example
2020-05-29 23:11:34 +02:00
```yaml
2020-06-26 08:05:34 +02:00
on:
2020-05-29 23:11:34 +02:00
push:
2021-11-01 10:02:27 +01:00
branches:
2020-05-29 23:11:34 +02:00
- master
2019-03-09 11:25:14 +01:00
2022-09-03 01:29:32 -07:00
name: "Trigger: Push action"
2022-11-06 20:47:49 +01:00
permissions: {}
2019-03-09 11:25:14 +01:00
2020-05-29 23:11:34 +02:00
jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
2022-11-06 20:56:54 +01:00
- uses: actions/checkout@v3
2022-09-03 01:29:32 -07:00
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
2019-03-09 11:25:14 +01:00
```
2021-01-13 10:26:27 -07:00
## ShellCheck options
2020-05-29 23:11:34 +02:00
2021-01-13 10:26:27 -07:00
You can pass any supported ShellCheck option or flag with the `SHELLCHECK_OPTS` env key in the job definition.
Some examples include:
2022-09-03 01:29:32 -07:00
- To disable specific checks (eg: `-e SC2059 -e SC2034 -e SC1090` )
- To test against different shells (eg: `-s dash` or `-s ksh` )
2020-05-29 23:11:34 +02:00
example:
```yaml
...
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: -e SC2059 -e SC2034 -e SC1090
```
2020-05-30 11:57:50 +02:00
2021-11-14 11:01:29 +01:00
## Ignore paths and names
2020-05-30 11:57:50 +02:00
2021-11-14 11:01:29 +01:00
You can use the `ignore_paths` and `ignore_names` input to disable specific directories and files.
2020-05-30 11:57:50 +02:00
```text
sample structure:
2020-12-24 12:06:42 +01:00
sample/directory/with/files/ignoreme/test.sh
sample/directory/with/files/ignoremetoo/test.sh
2020-05-30 11:57:50 +02:00
sample/directory/with/files/test.sh
2021-11-14 11:01:29 +01:00
sample/directory/with/files/ignorable.sh
2020-05-30 11:57:50 +02:00
```
example:
```yaml
...
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
2021-11-14 11:01:29 +01:00
ignore_paths: ignoreme ignoremetoo
ignore_names: ignorable.sh
2020-05-30 11:57:50 +02:00
```
2021-11-14 11:01:29 +01:00
This will skip `sample/directory/with/files/ignoreme/test.sh` , `sample/directory/with/files/ignoremetoo/test.sh` and `sample/directory/with/files/ignorable.sh` .
2020-06-26 08:05:34 +02:00
2022-09-03 01:29:32 -07:00
You can also ignore specific files using full paths or glob patterns with `ignore_paths` .
example:
```yaml
...
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
ignore_paths: ./sample/directory/with/files/ignorable.sh ** /ignoreme/test.sh
```
This will skip `sample/directory/with/files/ignorable.sh` and `sample/directory/with/files/ignoreme/test.sh` .
2020-06-26 08:05:34 +02:00
## 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
```
2020-06-26 15:41:45 -04:00
## 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
2020-10-03 14:49:12 +02:00
uses: ludeeus/action-shellcheck@master
with:
check_together: 'yes'
2020-06-26 15:41:45 -04:00
```
This can turn into a problem if you have enough script files to overwhelm the
maximum argv length on your system.
2020-10-03 14:49:12 +02:00
## Run shellcheck only in a single directory
If you have multiple directories with scripts, but only want to scan
one of them, you can use the following configuration:
```yaml
...
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
scandir: './scripts'
```
2020-10-25 21:00:46 +01:00
## Scan for additional files
If you need to scan for unusual files, you can use the `additional_files` key.
```yaml
...
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
additional_files: 'run finish'
```
## Disable problem matcher
If you do not want to have the problem-matcher annotate files, you can disable it
by setting `disable_matcher` to `true` .
```yaml
...
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
disable_matcher: true
2020-12-24 12:06:42 +01:00
```
2021-03-31 21:03:27 +02:00
## Change output format
Shellcheck can print output in these formats: `checkstyle` , `diff` , `gcc` , `json` , `json1` , `quiet` , `tty` . See some examples [here ](https://github.com/koalaman/shellcheck/wiki/Integration#pick-the-output-format-that-makes-your-life-easier ).
Only `tty` and `gcc` produce file annotations via problem matcher, default is `gcc` .
- `tty` has multi-line log messages, but all annotations are reported as errors
- `gcc` has single-line log messages, so it's easier to parse with a problem matcher (including correct severity annotation)
```yaml
...
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
format: tty
```
2021-11-14 18:10:08 +09:00
## Run a specific version of Shellcheck
If running the latest stable version of Shellcheck is not to your liking, you can specify a concrete version of Shellcheck to be used. When specifying a custom version, please use any of the released versions listed in the [Shellcheck repository ](https://github.com/koalaman/shellcheck/tags ).
```yaml
...
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
2021-11-14 10:21:33 +01:00
version: v0.7.0
2021-11-14 18:10:08 +09:00
```