mirror of
https://github.com/ludeeus/action-shellcheck.git
synced 2025-04-15 06:39:20 +02:00
Compare commits
No commits in common. "master" and "0.2.1" have entirely different histories.
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "ludeeus/action-shellcheck",
|
|
||||||
"image": "mcr.microsoft.com/devcontainers/base:bullseye"
|
|
||||||
}
|
|
1
.github/ISSUE_TEMPLATE/config.yml
vendored
1
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1 +0,0 @@
|
|||||||
blank_issues_enabled: false
|
|
24
.github/ISSUE_TEMPLATE/feature_request.md
vendored
24
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -1,24 +0,0 @@
|
|||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
labels: "Feature Request"
|
|
||||||
---
|
|
||||||
|
|
||||||
## Checklist
|
|
||||||
|
|
||||||
- [ ] This Feature Request only contains 1 request (if you have multiple open multiple feature requests).
|
|
||||||
|
|
||||||
## The idea
|
|
||||||
|
|
||||||
A good description of what you are suggesting.
|
|
||||||
|
|
||||||
## Implementation
|
|
||||||
|
|
||||||
How do you see this being implemented?
|
|
||||||
|
|
||||||
## Alternatives
|
|
||||||
|
|
||||||
Are there any alternative solutions or features you've considered?
|
|
||||||
|
|
||||||
## Additional context
|
|
||||||
|
|
14
.github/ISSUE_TEMPLATE/issue.md
vendored
14
.github/ISSUE_TEMPLATE/issue.md
vendored
@ -1,14 +0,0 @@
|
|||||||
---
|
|
||||||
name: "Issue"
|
|
||||||
about: For issue reporting.
|
|
||||||
labels: "bug"
|
|
||||||
---
|
|
||||||
|
|
||||||
## Describe the issue
|
|
||||||
|
|
||||||
A clear and concise description of what the issue is.
|
|
||||||
|
|
||||||
### Links
|
|
||||||
|
|
||||||
- **Link to action run:**
|
|
||||||
- **Link to action configuration:**
|
|
8
.github/dependabot.yml
vendored
8
.github/dependabot.yml
vendored
@ -1,8 +0,0 @@
|
|||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: weekly
|
|
||||||
time: "06:00"
|
|
||||||
open-pull-requests-limit: 10
|
|
47
.github/workflows/additional_files.yml
vendored
47
.github/workflows/additional_files.yml
vendored
@ -1,47 +0,0 @@
|
|||||||
name: 'additional_files'
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
|
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
additional_files:
|
|
||||||
name: additional_files
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
os:
|
|
||||||
- ubuntu-latest
|
|
||||||
- macos-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4.1.0
|
|
||||||
|
|
||||||
- name: Run ShellCheck
|
|
||||||
uses: ./
|
|
||||||
id: check
|
|
||||||
with:
|
|
||||||
additional_files: run finish discovery
|
|
||||||
ignore_paths: ignore
|
|
||||||
scandir: testfiles
|
|
||||||
|
|
||||||
- name: Verify check
|
|
||||||
run: |
|
|
||||||
expect="testfiles/scandir/run"
|
|
||||||
|
|
||||||
if [[ ! "${{ steps.check.outputs.files }}" =~ testfiles/scandir/run ]];then
|
|
||||||
echo "::error:: Expected file testfiles/scandir/run not found in ${{ steps.check.outputs.files }}"
|
|
||||||
exit 1
|
|
||||||
elif [[ ! "${{ steps.check.outputs.files }}" =~ testfiles/scandir/finish ]];then
|
|
||||||
echo "::error:: Expected file testfiles/scandir/finish not found in ${{ steps.check.outputs.files }}"
|
|
||||||
exit 1
|
|
||||||
elif [[ ! "${{ steps.check.outputs.files }}" =~ testfiles/scandir/discovery ]];then
|
|
||||||
echo "::error:: Expected file testfiles/scandir/discovery not found in ${{ steps.check.outputs.files }}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
44
.github/workflows/check_together.yml
vendored
44
.github/workflows/check_together.yml
vendored
@ -1,44 +0,0 @@
|
|||||||
name: 'check_together'
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
|
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check_together:
|
|
||||||
name: check_together
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
os:
|
|
||||||
- ubuntu-latest
|
|
||||||
- macos-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4.1.0
|
|
||||||
|
|
||||||
- name: Run ShellCheck
|
|
||||||
uses: ./
|
|
||||||
id: check
|
|
||||||
with:
|
|
||||||
ignore_paths: ignore
|
|
||||||
check_together: true
|
|
||||||
|
|
||||||
- name: Verify check
|
|
||||||
run: |
|
|
||||||
expect="testfiles/test.bash"
|
|
||||||
notexpect="testfiles/ignore/ignore.bash"
|
|
||||||
|
|
||||||
if [[ ! "${{ steps.check.outputs.files }}" =~ $expect ]];then
|
|
||||||
echo "::error:: Expected file $expect not found in ${{ steps.check.outputs.files }}"
|
|
||||||
exit 1
|
|
||||||
elif [[ "${{ steps.check.outputs.files }}" =~ $notexpect ]];then
|
|
||||||
echo "::error:: Expected file $notexpect found in ${{ steps.check.outputs.files }}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
44
.github/workflows/ignore_names.yml
vendored
44
.github/workflows/ignore_names.yml
vendored
@ -1,44 +0,0 @@
|
|||||||
name: 'ignore_names'
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
|
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
ignore_names:
|
|
||||||
name: ignore_names
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
os:
|
|
||||||
- ubuntu-latest
|
|
||||||
- macos-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4.1.0
|
|
||||||
|
|
||||||
- name: Run ShellCheck
|
|
||||||
uses: ./
|
|
||||||
id: check
|
|
||||||
with:
|
|
||||||
ignore_paths: ignore
|
|
||||||
ignore_names: ignore_single_file.sh
|
|
||||||
|
|
||||||
- name: Verify check
|
|
||||||
run: |
|
|
||||||
expect="testfiles/test.bash"
|
|
||||||
notexpect="testfiles/ignore_single_file.sh"
|
|
||||||
|
|
||||||
if [[ ! "${{ steps.check.outputs.files }}" =~ $expect ]];then
|
|
||||||
echo "::error:: Expected file $expect not found in ${{ steps.check.outputs.files }}"
|
|
||||||
exit 1
|
|
||||||
elif [[ "${{ steps.check.outputs.files }}" =~ $notexpect ]];then
|
|
||||||
echo "::error:: Expected file $notexpect found in ${{ steps.check.outputs.files }}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
74
.github/workflows/ignore_paths.yml
vendored
74
.github/workflows/ignore_paths.yml
vendored
@ -1,74 +0,0 @@
|
|||||||
name: "ignore_paths"
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
|
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
ignore_paths:
|
|
||||||
name: ignore_paths
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
os:
|
|
||||||
- ubuntu-latest
|
|
||||||
- macos-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4.1.0
|
|
||||||
|
|
||||||
- name: Run ShellCheck
|
|
||||||
uses: ./
|
|
||||||
id: check
|
|
||||||
with:
|
|
||||||
ignore_paths: ignore ./testfiles/ignore_some/duplicate_name.bash **/ignore_some/ignore.bash
|
|
||||||
|
|
||||||
- name: Verify check
|
|
||||||
run: |
|
|
||||||
fail=false
|
|
||||||
|
|
||||||
# verify a non-ignored path is not excluded
|
|
||||||
expect="testfiles/test.bash"
|
|
||||||
if [[ ! "${{ steps.check.outputs.files }}" =~ $expect ]];then
|
|
||||||
echo "::error:: Expected file $expect not found in ${{ steps.check.outputs.files }}"
|
|
||||||
fail=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# verify a file with the same name as an ignored file but at a
|
|
||||||
# different path is not excluded
|
|
||||||
expect="testfiles/duplicate_name.bash"
|
|
||||||
if [[ ! "${{ steps.check.outputs.files }}" =~ $expect ]];then
|
|
||||||
echo "::error:: Expected file $expect not found in ${{ steps.check.outputs.files }}"
|
|
||||||
fail=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# verify ignored full path excluded
|
|
||||||
notexpect="testfiles/ignore_some/duplicate_name.bash"
|
|
||||||
if [[ "${{ steps.check.outputs.files }}" =~ $notexpect ]];then
|
|
||||||
echo "::error:: Unexpected file $notexpect found in ${{ steps.check.outputs.files }}"
|
|
||||||
fail=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# verify ignored directory excluded
|
|
||||||
notexpect="testfiles/ignore/ignore.bash"
|
|
||||||
if [[ "${{ steps.check.outputs.files }}" =~ $notexpect ]];then
|
|
||||||
echo "::error:: Unexpected file $notexpect found in ${{ steps.check.outputs.files }}"
|
|
||||||
fail=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# verify ignored glob excluded
|
|
||||||
notexpect="testfiles/ignore_some/ignore.bash"
|
|
||||||
if [[ "${{ steps.check.outputs.files }}" =~ $notexpect ]];then
|
|
||||||
echo "::error:: Unexpected file $notexpect found in ${{ steps.check.outputs.files }}"
|
|
||||||
fail=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $fail;then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
13
.github/workflows/push.yml
vendored
Normal file
13
.github/workflows/push.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
on: push
|
||||||
|
name: 'Trigger: Push'
|
||||||
|
jobs:
|
||||||
|
shellcheck:
|
||||||
|
name: ShellCheck
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Run ShellCheck
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
ignore: ignore
|
63
.github/workflows/scandir.yml
vendored
63
.github/workflows/scandir.yml
vendored
@ -1,63 +0,0 @@
|
|||||||
name: 'scandir'
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
|
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
scandir:
|
|
||||||
name: scandir
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
os:
|
|
||||||
- ubuntu-latest
|
|
||||||
- macos-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4.1.0
|
|
||||||
|
|
||||||
- name: Run ShellCheck
|
|
||||||
uses: ./
|
|
||||||
id: one
|
|
||||||
with:
|
|
||||||
scandir: testfiles/scandir
|
|
||||||
|
|
||||||
- name: Verify check
|
|
||||||
run: |
|
|
||||||
expect="testfiles/scandir/run[[:space:]]me.bash"
|
|
||||||
notexpect="testfiles/test.bash"
|
|
||||||
|
|
||||||
if [[ ! "${{ steps.one.outputs.files }}" =~ $expect ]];then
|
|
||||||
echo "::error:: Expected file $expect not found in ${{ steps.one.outputs.files }}"
|
|
||||||
exit 1
|
|
||||||
elif [[ "${{ steps.one.outputs.files }}" =~ $notexpect ]];then
|
|
||||||
echo "::error:: Expected file $notexpect found in ${{ steps.one.outputs.files }}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Run ShellCheck
|
|
||||||
uses: ./
|
|
||||||
id: two
|
|
||||||
with:
|
|
||||||
scandir: './testfiles/scandir'
|
|
||||||
ignore_paths: ignore
|
|
||||||
|
|
||||||
- name: Verify check
|
|
||||||
run: |
|
|
||||||
expect="testfiles/scandir/test.bash"
|
|
||||||
notexpect="testfiles/test.bash"
|
|
||||||
|
|
||||||
if [[ ! "${{ steps.two.outputs.files }}" =~ $expect ]];then
|
|
||||||
echo "::error:: Expected file $expect not found in ${{ steps.two.outputs.files }}"
|
|
||||||
exit 1
|
|
||||||
elif [[ "${{ steps.two.outputs.files }}" =~ $notexpect ]];then
|
|
||||||
echo "::error:: Expected file $notexpect found in ${{ steps.two.outputs.files }}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
6
Dockerfile
Normal file
6
Dockerfile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
FROM alpine:3.11.6
|
||||||
|
|
||||||
|
RUN apk add --no-cache shellcheck bash
|
||||||
|
|
||||||
|
COPY runaction.sh /action/runaction.sh
|
||||||
|
ENTRYPOINT ["bash", "/action/runaction.sh"]
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 ludeeus
|
Copyright (c) 2019 ludeeus
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
137
README.md
137
README.md
@ -1,36 +1,30 @@
|
|||||||
# ShellCheck
|
# ShellCheck
|
||||||
|
|
||||||
_GitHub action for [ShellCheck](https://www.shellcheck.net/)._
|
_GitHub action for ShellCheck._
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branch:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
name: "Trigger: Push action"
|
name: 'Trigger: Push action'
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
shellcheck:
|
shellcheck:
|
||||||
name: Shellcheck
|
name: Shellcheck
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@master
|
||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ludeeus/action-shellcheck@master
|
uses: ludeeus/action-shellcheck@master
|
||||||
```
|
```
|
||||||
|
|
||||||
## ShellCheck options
|
## Globally disable checks
|
||||||
|
|
||||||
You can pass any supported ShellCheck option or flag with the `SHELLCHECK_OPTS` env key in the job definition.
|
To disable specific checks add it to a `SHELLCHECK_OPTS` env key in the job definition.
|
||||||
|
|
||||||
Some examples include:
|
|
||||||
|
|
||||||
- To disable specific checks (eg: `-e SC2059 -e SC2034 -e SC1090`)
|
|
||||||
- To test against different shells (eg: `-s dash` or `-s ksh`)
|
|
||||||
|
|
||||||
example:
|
example:
|
||||||
|
|
||||||
@ -42,18 +36,14 @@ example:
|
|||||||
SHELLCHECK_OPTS: -e SC2059 -e SC2034 -e SC1090
|
SHELLCHECK_OPTS: -e SC2059 -e SC2034 -e SC1090
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ignore paths and names
|
## Ignore paths
|
||||||
|
|
||||||
You can use the `ignore_paths` and `ignore_names` input to disable specific directories and files.
|
You can use the `ignore` input to disable specific directories.
|
||||||
These are passed as environment variables, and should evaluate to a single space-separated string.
|
|
||||||
It may be convenient to use [`>-`](https://yaml.org/spec/1.2.2/#65-line-folding) for readability if you have multiple selectors.
|
|
||||||
|
|
||||||
```text
|
```text
|
||||||
sample structure:
|
sample structure:
|
||||||
sample/directory/with/files/ignoreme/test.sh
|
sample/directory/with/files/toignore/test.sh
|
||||||
sample/directory/with/files/ignoremetoo/test.sh
|
|
||||||
sample/directory/with/files/test.sh
|
sample/directory/with/files/test.sh
|
||||||
sample/directory/with/files/ignorable.sh
|
|
||||||
```
|
```
|
||||||
|
|
||||||
example:
|
example:
|
||||||
@ -63,106 +53,7 @@ example:
|
|||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ludeeus/action-shellcheck@master
|
uses: ludeeus/action-shellcheck@master
|
||||||
with:
|
with:
|
||||||
ignore_paths: >-
|
ignore: toignore
|
||||||
ignoreme
|
|
||||||
ignoremetoo
|
|
||||||
ignore_names: ignorable.sh
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This will skip `sample/directory/with/files/ignoreme/test.sh`, `sample/directory/with/files/ignoremetoo/test.sh` and `sample/directory/with/files/ignorable.sh`.
|
This will skip `sample/directory/with/files/toignore/test.sh`
|
||||||
|
|
||||||
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`.
|
|
||||||
|
|
||||||
## 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.
|
|
||||||
|
|
||||||
## 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'
|
|
||||||
```
|
|
||||||
|
|
||||||
## 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'
|
|
||||||
```
|
|
||||||
|
|
||||||
## 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).
|
|
||||||
|
|
||||||
- `tty` has multi-line log messages
|
|
||||||
- `gcc` has single-line log messages
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
...
|
|
||||||
- name: Run ShellCheck
|
|
||||||
uses: ludeeus/action-shellcheck@master
|
|
||||||
with:
|
|
||||||
format: tty
|
|
||||||
```
|
|
||||||
|
|
||||||
## 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:
|
|
||||||
version: v0.9.0
|
|
||||||
```
|
|
||||||
|
225
action.yaml
225
action.yaml
@ -2,224 +2,13 @@ name: "ShellCheck"
|
|||||||
author: "Ludeeus <hi@ludeeus.dev>"
|
author: "Ludeeus <hi@ludeeus.dev>"
|
||||||
description: "GitHub action for ShellCheck."
|
description: "GitHub action for ShellCheck."
|
||||||
inputs:
|
inputs:
|
||||||
additional_files:
|
|
||||||
description: "A space separated list of additional filename to check"
|
|
||||||
required: false
|
|
||||||
default: ""
|
|
||||||
ignore:
|
ignore:
|
||||||
description: "Paths to ignore when running ShellCheck"
|
description: 'Paths to ignore when running ShellCheck'
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ''
|
||||||
deprecationMessage: "Use ignore_paths or ignore_names instead."
|
runs:
|
||||||
ignore_paths:
|
using: 'docker'
|
||||||
description: "Paths to ignore when running ShellCheck"
|
image: 'Dockerfile'
|
||||||
required: false
|
|
||||||
default: ""
|
|
||||||
ignore_names:
|
|
||||||
description: "Names 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: ""
|
|
||||||
scandir:
|
|
||||||
description: "Directory to be searched for files. Defaults to ."
|
|
||||||
required: false
|
|
||||||
default: "."
|
|
||||||
disable_matcher:
|
|
||||||
description: "Set to true to skip using problem-matcher"
|
|
||||||
required: false
|
|
||||||
default: "false"
|
|
||||||
deprecationMessage: "There are no problem-matchers, this setting does not do anything."
|
|
||||||
format:
|
|
||||||
description: "Output format (checkstyle, diff, gcc, json, json1, quiet, tty)"
|
|
||||||
required: false
|
|
||||||
default: "gcc"
|
|
||||||
version:
|
|
||||||
description: "Specify a concrete version of ShellCheck to use"
|
|
||||||
required: false
|
|
||||||
default: "stable"
|
|
||||||
outputs:
|
|
||||||
files:
|
|
||||||
description: A list of files with issues
|
|
||||||
value: ${{ steps.check.outputs.filepaths }}
|
|
||||||
options:
|
|
||||||
description: The options used
|
|
||||||
value: ${{ steps.options.outputs.options }}
|
|
||||||
branding:
|
branding:
|
||||||
icon: "terminal"
|
icon: 'terminal'
|
||||||
color: "gray-dark"
|
color: 'gray-dark'
|
||||||
runs:
|
|
||||||
using: "composite"
|
|
||||||
steps:
|
|
||||||
- name: Download shellcheck
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
INPUT_VERSION: ${{ inputs.version }}
|
|
||||||
run: |
|
|
||||||
if [[ "${{ runner.os }}" == "macOS" ]]; then
|
|
||||||
osvariant="darwin"
|
|
||||||
else
|
|
||||||
osvariant="linux"
|
|
||||||
fi
|
|
||||||
|
|
||||||
baseurl="https://github.com/koalaman/shellcheck/releases/download"
|
|
||||||
|
|
||||||
curl -Lso "${{ github.action_path }}/sc.tar.xz" \
|
|
||||||
"${baseurl}/${INPUT_VERSION}/shellcheck-${INPUT_VERSION}.${osvariant}.x86_64.tar.xz"
|
|
||||||
|
|
||||||
tar -xf "${{ github.action_path }}/sc.tar.xz" -C "${{ github.action_path }}"
|
|
||||||
mv "${{ github.action_path }}/shellcheck-${INPUT_VERSION}/shellcheck" \
|
|
||||||
"${{ github.action_path }}/shellcheck"
|
|
||||||
|
|
||||||
- name: Display shellcheck version
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
"${{ github.action_path }}/shellcheck" --version
|
|
||||||
|
|
||||||
- name: Set options
|
|
||||||
shell: bash
|
|
||||||
id: options
|
|
||||||
env:
|
|
||||||
INPUT_SEVERITY: ${{ inputs.severity }}
|
|
||||||
INPUT_FORMAT: ${{ inputs.format }}
|
|
||||||
run: |
|
|
||||||
declare -a options
|
|
||||||
if [[ -n "${INPUT_SEVERITY}" ]]; then
|
|
||||||
options+=("-S ${INPUT_SEVERITY}")
|
|
||||||
fi
|
|
||||||
options+=("--format=${INPUT_FORMAT}")
|
|
||||||
echo "options=${options[@]}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Gather excluded paths
|
|
||||||
shell: bash
|
|
||||||
id: exclude
|
|
||||||
env:
|
|
||||||
INPUT_IGNORE: ${{ inputs.ignore }}
|
|
||||||
INPUT_IGNORE_PATHS: ${{ inputs.ignore_paths }}
|
|
||||||
INPUT_IGNORE_NAMES: ${{ inputs.ignore_names }}
|
|
||||||
run: |
|
|
||||||
declare -a excludes
|
|
||||||
set -f # temporarily disable globbing so that globs in input aren't expanded
|
|
||||||
|
|
||||||
excludes+=("! -path *./.git/*")
|
|
||||||
excludes+=("! -path *.go")
|
|
||||||
excludes+=("! -path */mvnw")
|
|
||||||
if [[ -n "${INPUT_IGNORE}" ]]; then
|
|
||||||
for path in ${INPUT_IGNORE}; do
|
|
||||||
excludes+=("! -path *./$path/*")
|
|
||||||
excludes+=("! -path */$path/*")
|
|
||||||
excludes+=("! -path $path")
|
|
||||||
done
|
|
||||||
else
|
|
||||||
for path in ${INPUT_IGNORE_PATHS}; do
|
|
||||||
excludes+=("! -path *./$path/*")
|
|
||||||
excludes+=("! -path */$path/*")
|
|
||||||
excludes+=("! -path $path")
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
for name in ${INPUT_IGNORE_NAMES}; do
|
|
||||||
excludes+=("! -name $name")
|
|
||||||
done
|
|
||||||
echo "excludes=${excludes[@]}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
set +f # re-enable globbing
|
|
||||||
|
|
||||||
- name: Gather additional files
|
|
||||||
shell: bash
|
|
||||||
id: additional
|
|
||||||
env:
|
|
||||||
INPUT_ADDITIONAL_FILES: ${{ inputs.additional_files }}
|
|
||||||
run: |
|
|
||||||
declare -a files
|
|
||||||
for file in ${INPUT_ADDITIONAL_FILES}; do
|
|
||||||
files+=("-o -name *$file")
|
|
||||||
done
|
|
||||||
echo "files=${files[@]}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Run the check
|
|
||||||
shell: bash
|
|
||||||
id: check
|
|
||||||
env:
|
|
||||||
INPUT_SCANDIR: ${{ inputs.scandir }}
|
|
||||||
INPUT_CHECK_TOGETHER: ${{ inputs.check_together }}
|
|
||||||
INPUT_EXCLUDE_ARGS: ${{ steps.exclude.outputs.excludes }}
|
|
||||||
INPUT_ADDITIONAL_FILE_ARGS: ${{ steps.additional.outputs.files }}
|
|
||||||
INPUT_SHELLCHECK_OPTIONS: ${{ steps.options.outputs.options }}
|
|
||||||
run: |
|
|
||||||
statuscode=0
|
|
||||||
declare -a filepaths
|
|
||||||
shebangregex="^#! */[^ ]*/(env *)?[abk]*sh"
|
|
||||||
|
|
||||||
set -f # temporarily disable globbing so that globs in inputs aren't expanded
|
|
||||||
|
|
||||||
while IFS= read -r -d '' file; do
|
|
||||||
filepaths+=("$file")
|
|
||||||
done < <(find "${INPUT_SCANDIR}" \
|
|
||||||
${INPUT_EXCLUDE_ARGS} \
|
|
||||||
-type f \
|
|
||||||
'(' \
|
|
||||||
-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' \
|
|
||||||
${INPUT_ADDITIONAL_FILE_ARGS} \
|
|
||||||
')' \
|
|
||||||
-print0)
|
|
||||||
|
|
||||||
while IFS= read -r -d '' file; do
|
|
||||||
head -n1 "$file" | grep -Eqs "$shebangregex" || continue
|
|
||||||
filepaths+=("$file")
|
|
||||||
done < <(find "${INPUT_SCANDIR}" \
|
|
||||||
${INPUT_EXCLUDE_ARGS} \
|
|
||||||
-type f ! -name '*.*' -perm /111 \
|
|
||||||
-print0)
|
|
||||||
|
|
||||||
if [[ -n "${INPUT_CHECK_TOGETHER}" ]]; then
|
|
||||||
"${{ github.action_path }}/shellcheck" \
|
|
||||||
${INPUT_SHELLCHECK_OPTIONS} \
|
|
||||||
"${filepaths[@]}" || statuscode=$?
|
|
||||||
else
|
|
||||||
for file in "${filepaths[@]}"; do
|
|
||||||
"${{ github.action_path }}/shellcheck" \
|
|
||||||
${INPUT_SHELLCHECK_OPTIONS} \
|
|
||||||
"$file" || statuscode=$?
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "filepaths=${filepaths[@]}" >> $GITHUB_OUTPUT
|
|
||||||
echo "statuscode=$statuscode" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
set +f # re-enable globbing
|
|
||||||
|
|
||||||
- name: Exit action
|
|
||||||
shell: bash
|
|
||||||
run: exit ${{steps.check.outputs.statuscode}}
|
|
74
runaction.sh
Executable file
74
runaction.sh
Executable file
@ -0,0 +1,74 @@
|
|||||||
|
#!/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 . "${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
|
||||||
|
|
||||||
|
for file in "${filepaths[@]}"; do
|
||||||
|
echo "::debug:: Checking $file"
|
||||||
|
shellcheck "$file" || statuscode=$?
|
||||||
|
done
|
||||||
|
|
||||||
|
exit "$statuscode"
|
@ -1,6 +0,0 @@
|
|||||||
/* C code test file
|
|
||||||
* file that should not be matched for shellcheck runs
|
|
||||||
*/
|
|
||||||
int main(void) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
test="test"
|
|
||||||
echo "$test"
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
test="test"
|
|
||||||
echo "$test"
|
|
3
testfiles/ignore/ignore.sh
Normal file
3
testfiles/ignore/ignore.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo $test
|
@ -1,4 +0,0 @@
|
|||||||
#!/usr/bin/sh
|
|
||||||
|
|
||||||
test="test"
|
|
||||||
echo "$test"
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
test="test"
|
|
||||||
echo "$test"
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
test="test"
|
|
||||||
echo "$test"
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
test="test"
|
|
||||||
echo "$test"
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env bashio
|
|
||||||
|
|
||||||
echo "hi"
|
|
@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bashio
|
|
||||||
|
|
||||||
hi="hi"
|
|
||||||
|
|
||||||
echo "$hi"
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
echo "hi"
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
echo "I love spaces"
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
test="test"
|
|
||||||
echo "$test"
|
|
Loading…
x
Reference in New Issue
Block a user