mirror of
https://github.com/ludeeus/action-shellcheck.git
synced 2025-04-13 21:59:20 +02:00
Compare commits
37 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
00b27aa7cb | ||
![]() |
cd81f4475a | ||
![]() |
00cae500b0 | ||
![]() |
84dc45371e | ||
![]() |
e07831dc6f | ||
![]() |
c4b2ed0185 | ||
![]() |
e5c9260d11 | ||
![]() |
6d3f514f44 | ||
![]() |
0b28ced3b4 | ||
![]() |
3261165459 | ||
![]() |
1e1da5dfe2 | ||
![]() |
be27f35867 | ||
![]() |
6b1b9b1437 | ||
![]() |
3d0de11d23 | ||
![]() |
45e81d0a30 | ||
![]() |
9634fec4ed | ||
![]() |
1c879e7d68 | ||
![]() |
b2bbefc2e6 | ||
![]() |
20fbf19cec | ||
![]() |
10434c2598 | ||
![]() |
6096f68baf | ||
![]() |
203a3fd018 | ||
![]() |
c2b45ddc5f | ||
![]() |
2e033faa4a | ||
![]() |
0ef4a19bfe | ||
![]() |
a1080136d9 | ||
![]() |
7606914ded | ||
![]() |
ceeca77f65 | ||
![]() |
8379299538 | ||
![]() |
94e0aab03c | ||
![]() |
184a772465 | ||
![]() |
f01a9171d3 | ||
![]() |
7fa8ae9d42 | ||
![]() |
f0d446b80e | ||
![]() |
00209834e5 | ||
![]() |
ac3e5d1ab4 | ||
![]() |
b247a9c05d |
4
.devcontainer.json
Normal file
4
.devcontainer.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"name": "ludeeus/action-shellcheck",
|
||||||
|
"image": "mcr.microsoft.com/devcontainers/base:bullseye"
|
||||||
|
}
|
8
.github/dependabot.yml
vendored
Normal file
8
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
time: "06:00"
|
||||||
|
open-pull-requests-limit: 10
|
22
.github/problem-matcher.json
vendored
22
.github/problem-matcher.json
vendored
@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"problemMatcher": [
|
|
||||||
{
|
|
||||||
"owner": "shellcheck",
|
|
||||||
"pattern": [
|
|
||||||
{
|
|
||||||
"regexp": "^In\\s(.+)\\sline\\s(\\d+):$",
|
|
||||||
"file": 1,
|
|
||||||
"line": 2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"regexp": ".*"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"regexp": "(SC\\d+):\\s(.+)$",
|
|
||||||
"code": 1,
|
|
||||||
"message": 2
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
11
.github/workflows/additional_files.yml
vendored
11
.github/workflows/additional_files.yml
vendored
@ -2,8 +2,13 @@ name: 'additional_files'
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["master"]
|
branches:
|
||||||
|
- "master"
|
||||||
pull_request:
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "master"
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
additional_files:
|
additional_files:
|
||||||
@ -16,14 +21,14 @@ jobs:
|
|||||||
- macos-latest
|
- macos-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4.1.0
|
||||||
|
|
||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ./
|
uses: ./
|
||||||
id: check
|
id: check
|
||||||
with:
|
with:
|
||||||
additional_files: run finish discovery
|
additional_files: run finish discovery
|
||||||
ignore: ignore
|
ignore_paths: ignore
|
||||||
scandir: testfiles
|
scandir: testfiles
|
||||||
|
|
||||||
- name: Verify check
|
- name: Verify check
|
||||||
|
11
.github/workflows/check_together.yml
vendored
11
.github/workflows/check_together.yml
vendored
@ -2,8 +2,13 @@ name: 'check_together'
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["master"]
|
branches:
|
||||||
|
- "master"
|
||||||
pull_request:
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "master"
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check_together:
|
check_together:
|
||||||
@ -16,13 +21,13 @@ jobs:
|
|||||||
- macos-latest
|
- macos-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4.1.0
|
||||||
|
|
||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ./
|
uses: ./
|
||||||
id: check
|
id: check
|
||||||
with:
|
with:
|
||||||
ignore: ignore
|
ignore_paths: ignore
|
||||||
check_together: true
|
check_together: true
|
||||||
|
|
||||||
- name: Verify check
|
- name: Verify check
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
name: 'base'
|
name: 'ignore_names'
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["master"]
|
branches:
|
||||||
|
- "master"
|
||||||
pull_request:
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "master"
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
base:
|
ignore_names:
|
||||||
name: base
|
name: ignore_names
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
@ -16,18 +21,19 @@ jobs:
|
|||||||
- macos-latest
|
- macos-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4.1.0
|
||||||
|
|
||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ./
|
uses: ./
|
||||||
id: check
|
id: check
|
||||||
with:
|
with:
|
||||||
ignore: ignore
|
ignore_paths: ignore
|
||||||
|
ignore_names: ignore_single_file.sh
|
||||||
|
|
||||||
- name: Verify check
|
- name: Verify check
|
||||||
run: |
|
run: |
|
||||||
expect="testfiles/test.bash"
|
expect="testfiles/test.bash"
|
||||||
notexpect="testfiles/ignore/ignore.bash"
|
notexpect="testfiles/ignore_single_file.sh"
|
||||||
|
|
||||||
if [[ ! "${{ steps.check.outputs.files }}" =~ $expect ]];then
|
if [[ ! "${{ steps.check.outputs.files }}" =~ $expect ]];then
|
||||||
echo "::error:: Expected file $expect not found in ${{ steps.check.outputs.files }}"
|
echo "::error:: Expected file $expect not found in ${{ steps.check.outputs.files }}"
|
74
.github/workflows/ignore_paths.yml
vendored
Normal file
74
.github/workflows/ignore_paths.yml
vendored
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
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/scandir.yml
vendored
13
.github/workflows/scandir.yml
vendored
@ -2,8 +2,13 @@ name: 'scandir'
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["master"]
|
branches:
|
||||||
|
- "master"
|
||||||
pull_request:
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "master"
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
scandir:
|
scandir:
|
||||||
@ -16,7 +21,7 @@ jobs:
|
|||||||
- macos-latest
|
- macos-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4.1.0
|
||||||
|
|
||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -26,7 +31,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Verify check
|
- name: Verify check
|
||||||
run: |
|
run: |
|
||||||
expect="testfiles/scandir/test.bash"
|
expect="testfiles/scandir/run[[:space:]]me.bash"
|
||||||
notexpect="testfiles/test.bash"
|
notexpect="testfiles/test.bash"
|
||||||
|
|
||||||
if [[ ! "${{ steps.one.outputs.files }}" =~ $expect ]];then
|
if [[ ! "${{ steps.one.outputs.files }}" =~ $expect ]];then
|
||||||
@ -42,7 +47,7 @@ jobs:
|
|||||||
id: two
|
id: two
|
||||||
with:
|
with:
|
||||||
scandir: './testfiles/scandir'
|
scandir: './testfiles/scandir'
|
||||||
ignore: ignore
|
ignore_paths: ignore
|
||||||
|
|
||||||
- name: Verify check
|
- name: Verify check
|
||||||
run: |
|
run: |
|
||||||
|
71
README.md
71
README.md
@ -1,30 +1,36 @@
|
|||||||
# ShellCheck
|
# ShellCheck
|
||||||
|
|
||||||
_GitHub action for ShellCheck._
|
_GitHub action for [ShellCheck](https://www.shellcheck.net/)._
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branch:
|
branches:
|
||||||
- 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@v2
|
- uses: actions/checkout@v4
|
||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ludeeus/action-shellcheck@master
|
uses: ludeeus/action-shellcheck@master
|
||||||
```
|
```
|
||||||
|
|
||||||
## Globally disable checks
|
## ShellCheck options
|
||||||
|
|
||||||
To disable specific checks add it to a `SHELLCHECK_OPTS` env key in the job definition.
|
You can pass any supported ShellCheck option or flag with the `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:
|
||||||
|
|
||||||
@ -36,14 +42,18 @@ example:
|
|||||||
SHELLCHECK_OPTS: -e SC2059 -e SC2034 -e SC1090
|
SHELLCHECK_OPTS: -e SC2059 -e SC2034 -e SC1090
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ignore paths
|
## Ignore paths and names
|
||||||
|
|
||||||
You can use the `ignore` input to disable specific directories.
|
You can use the `ignore_paths` and `ignore_names` input to disable specific directories and files.
|
||||||
|
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/toignore/test.sh
|
sample/directory/with/files/ignoreme/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:
|
||||||
@ -53,10 +63,27 @@ example:
|
|||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ludeeus/action-shellcheck@master
|
uses: ludeeus/action-shellcheck@master
|
||||||
with:
|
with:
|
||||||
ignore: toignore
|
ignore_paths: >-
|
||||||
|
ignoreme
|
||||||
|
ignoremetoo
|
||||||
|
ignore_names: ignorable.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
This will skip `sample/directory/with/files/toignore/test.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`.
|
||||||
|
|
||||||
|
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)
|
## Minimum severity of errors to consider (error, warning, info, style)
|
||||||
|
|
||||||
@ -113,15 +140,29 @@ If you need to scan for unusual files, you can use the `additional_files` key.
|
|||||||
additional_files: 'run finish'
|
additional_files: 'run finish'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Disable problem matcher
|
## Change output format
|
||||||
|
|
||||||
If you do not want to have the problem-matcher annotate files, you can disable it
|
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).
|
||||||
by setting `disable_matcher` to `true`.
|
|
||||||
|
- `tty` has multi-line log messages
|
||||||
|
- `gcc` has single-line log messages
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
...
|
...
|
||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ludeeus/action-shellcheck@master
|
uses: ludeeus/action-shellcheck@master
|
||||||
with:
|
with:
|
||||||
disable_matcher: true
|
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
|
||||||
```
|
```
|
186
action.yaml
186
action.yaml
@ -3,13 +3,22 @@ author: "Ludeeus <hi@ludeeus.dev>"
|
|||||||
description: "GitHub action for ShellCheck."
|
description: "GitHub action for ShellCheck."
|
||||||
inputs:
|
inputs:
|
||||||
additional_files:
|
additional_files:
|
||||||
description: "A space seperated list of additional filename to check"
|
description: "A space separated list of additional filename to check"
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
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."
|
||||||
|
ignore_paths:
|
||||||
|
description: "Paths to ignore when running ShellCheck"
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
|
ignore_names:
|
||||||
|
description: "Names to ignore when running ShellCheck"
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
severity:
|
severity:
|
||||||
description: "Minimum severity of errors to consider. Options: [error, warning, info, style]"
|
description: "Minimum severity of errors to consider. Options: [error, warning, info, style]"
|
||||||
required: false
|
required: false
|
||||||
@ -26,10 +35,19 @@ inputs:
|
|||||||
description: "Set to true to skip using problem-matcher"
|
description: "Set to true to skip using problem-matcher"
|
||||||
required: false
|
required: false
|
||||||
default: "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:
|
outputs:
|
||||||
files:
|
files:
|
||||||
description: A list of files with issues
|
description: A list of files with issues
|
||||||
value: ${{ steps.filepaths.outputs.filepaths }}
|
value: ${{ steps.check.outputs.filepaths }}
|
||||||
options:
|
options:
|
||||||
description: The options used
|
description: The options used
|
||||||
value: ${{ steps.options.outputs.options }}
|
value: ${{ steps.options.outputs.options }}
|
||||||
@ -39,15 +57,10 @@ branding:
|
|||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
- name: Enable problem-matcher
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
if [[ ${{ inputs.disable_matcher }} != "true" ]]; then
|
|
||||||
echo "::add-matcher::${{ github.action_path }}/.github/problem-matcher.json"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Download shellcheck
|
- name: Download shellcheck
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
INPUT_VERSION: ${{ inputs.version }}
|
||||||
run: |
|
run: |
|
||||||
if [[ "${{ runner.os }}" == "macOS" ]]; then
|
if [[ "${{ runner.os }}" == "macOS" ]]; then
|
||||||
osvariant="darwin"
|
osvariant="darwin"
|
||||||
@ -55,61 +68,102 @@ runs:
|
|||||||
osvariant="linux"
|
osvariant="linux"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
scversion="stable"
|
|
||||||
baseurl="https://github.com/koalaman/shellcheck/releases/download"
|
baseurl="https://github.com/koalaman/shellcheck/releases/download"
|
||||||
|
|
||||||
curl -Lso "${{ github.action_path }}/sc.tar.xz" \
|
curl -Lso "${{ github.action_path }}/sc.tar.xz" \
|
||||||
"${baseurl}/${scversion}/shellcheck-${scversion}.${osvariant}.x86_64.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 }}"
|
tar -xf "${{ github.action_path }}/sc.tar.xz" -C "${{ github.action_path }}"
|
||||||
mv "${{ github.action_path }}/shellcheck-${scversion}/shellcheck" \
|
mv "${{ github.action_path }}/shellcheck-${INPUT_VERSION}/shellcheck" \
|
||||||
"${{ github.action_path }}/shellcheck"
|
"${{ github.action_path }}/shellcheck"
|
||||||
|
|
||||||
|
- name: Display shellcheck version
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
"${{ github.action_path }}/shellcheck" --version
|
||||||
|
|
||||||
- name: Set options
|
- name: Set options
|
||||||
shell: bash
|
shell: bash
|
||||||
id: options
|
id: options
|
||||||
|
env:
|
||||||
|
INPUT_SEVERITY: ${{ inputs.severity }}
|
||||||
|
INPUT_FORMAT: ${{ inputs.format }}
|
||||||
run: |
|
run: |
|
||||||
declare -a options
|
declare -a options
|
||||||
if [[ -n "${{ inputs.severity }}" ]]; then
|
if [[ -n "${INPUT_SEVERITY}" ]]; then
|
||||||
options+=("-S ${{ inputs.severity }}")
|
options+=("-S ${INPUT_SEVERITY}")
|
||||||
fi
|
fi
|
||||||
echo "::set-output name=options::${options[@]}"
|
options+=("--format=${INPUT_FORMAT}")
|
||||||
|
echo "options=${options[@]}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Gather excluded paths
|
- name: Gather excluded paths
|
||||||
shell: bash
|
shell: bash
|
||||||
id: exclude
|
id: exclude
|
||||||
|
env:
|
||||||
|
INPUT_IGNORE: ${{ inputs.ignore }}
|
||||||
|
INPUT_IGNORE_PATHS: ${{ inputs.ignore_paths }}
|
||||||
|
INPUT_IGNORE_NAMES: ${{ inputs.ignore_names }}
|
||||||
run: |
|
run: |
|
||||||
declare -a excludes
|
declare -a excludes
|
||||||
excludes+=("! -path \"*./.git/*\"")
|
set -f # temporarily disable globbing so that globs in input aren't expanded
|
||||||
excludes+=("! -path \"*.go\"")
|
|
||||||
excludes+=("! -path \"*/mvnw\"")
|
excludes+=("! -path *./.git/*")
|
||||||
for path in ${{ inputs.ignore }}; do
|
excludes+=("! -path *.go")
|
||||||
echo "::debug:: Adding "$path" to excludes"
|
excludes+=("! -path */mvnw")
|
||||||
excludes+=("! -path \"*./$path/*\"")
|
if [[ -n "${INPUT_IGNORE}" ]]; then
|
||||||
excludes+=("! -path \"*/$path/*\"")
|
for path in ${INPUT_IGNORE}; do
|
||||||
|
excludes+=("! -path *./$path/*")
|
||||||
|
excludes+=("! -path */$path/*")
|
||||||
|
excludes+=("! -path $path")
|
||||||
done
|
done
|
||||||
echo "::set-output name=excludes::${excludes[@]}"
|
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
|
- name: Gather additional files
|
||||||
shell: bash
|
shell: bash
|
||||||
id: additional
|
id: additional
|
||||||
|
env:
|
||||||
|
INPUT_ADDITIONAL_FILES: ${{ inputs.additional_files }}
|
||||||
run: |
|
run: |
|
||||||
declare -a files
|
declare -a files
|
||||||
for file in ${{ inputs.additional_files }}; do
|
for file in ${INPUT_ADDITIONAL_FILES}; do
|
||||||
echo "::debug:: Adding "$file" to excludes"
|
files+=("-o -name *$file")
|
||||||
files+=("-o -name \"*$file\"")
|
|
||||||
done
|
done
|
||||||
echo "::set-output name=files::${files[@]}"
|
echo "files=${files[@]}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Gather base file paths
|
- name: Run the check
|
||||||
shell: bash
|
shell: bash
|
||||||
id: filepaths
|
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: |
|
run: |
|
||||||
|
statuscode=0
|
||||||
declare -a filepaths
|
declare -a filepaths
|
||||||
shebangregex="^#! */[^ ]*/(env *)?[abkz]*sh"
|
shebangregex="^#! */[^ ]*/(env *)?[abk]*sh"
|
||||||
|
|
||||||
for path in $(find "${{ inputs.scandir }}" \
|
set -f # temporarily disable globbing so that globs in inputs aren't expanded
|
||||||
-type f -type f ${{ steps.exclude.outputs.excludes }} \
|
|
||||||
|
while IFS= read -r -d '' file; do
|
||||||
|
filepaths+=("$file")
|
||||||
|
done < <(find "${INPUT_SCANDIR}" \
|
||||||
|
${INPUT_EXCLUDE_ARGS} \
|
||||||
|
-type f \
|
||||||
'(' \
|
'(' \
|
||||||
-name '*.bash' \
|
-name '*.bash' \
|
||||||
-o -name '.bashrc' \
|
-o -name '.bashrc' \
|
||||||
@ -137,63 +191,35 @@ runs:
|
|||||||
-o -path '*/.profile' \
|
-o -path '*/.profile' \
|
||||||
-o -path '*/profile' \
|
-o -path '*/profile' \
|
||||||
-o -name '*.shlib' \
|
-o -name '*.shlib' \
|
||||||
${{ steps.additional.outputs.files }} \
|
${INPUT_ADDITIONAL_FILE_ARGS} \
|
||||||
')' \
|
')' \
|
||||||
-print); do
|
-print0)
|
||||||
filepaths+=("$path");
|
|
||||||
done
|
|
||||||
|
|
||||||
for file in $(find "${{ inputs.scandir }}" ${{ steps.exclude.outputs.excludes }} -type f ! -name '*.*' -perm /111 -print); do
|
while IFS= read -r -d '' file; do
|
||||||
head -n1 "$file" | grep -Eqs "$shebangregex" || continue
|
head -n1 "$file" | grep -Eqs "$shebangregex" || continue
|
||||||
filepaths+=("$file");
|
filepaths+=("$file")
|
||||||
done
|
done < <(find "${INPUT_SCANDIR}" \
|
||||||
echo "::set-output name=filepaths::${filepaths[@]}"
|
${INPUT_EXCLUDE_ARGS} \
|
||||||
|
-type f ! -name '*.*' -perm /111 \
|
||||||
|
-print0)
|
||||||
|
|
||||||
- name: Check bin subdirs
|
if [[ -n "${INPUT_CHECK_TOGETHER}" ]]; then
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
if find "${{ inputs.scandir }}" ${{ steps.exclude.outputs.excludes }} -path '*bin/*/*' -type f -perm /111 -print |
|
|
||||||
grep .
|
|
||||||
then
|
|
||||||
echo "::warning:: subdirectories of bin directories are not usable via PATH"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Check no suffix in PATH
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
if find "${{ inputs.scandir }}" ${{ steps.exclude.outputs.excludes }} -path '*bin/*' -name '*.*' -type f -perm /111 -perm /444 -print |
|
|
||||||
grep .
|
|
||||||
then
|
|
||||||
echo "::warning:: programs in PATH should not have a filename suffix"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Run the file check
|
|
||||||
id: check
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
statuscode=0
|
|
||||||
|
|
||||||
if [[ -n "${{ inputs.check_together }}" ]]; then
|
|
||||||
"${{ github.action_path }}/shellcheck" \
|
"${{ github.action_path }}/shellcheck" \
|
||||||
${{ steps.options.outputs.options }} \
|
${INPUT_SHELLCHECK_OPTIONS} \
|
||||||
${{ steps.filepaths.outputs.filepaths }} || statuscode=$?
|
"${filepaths[@]}" || statuscode=$?
|
||||||
else
|
else
|
||||||
for file in ${{ steps.filepaths.outputs.filepaths }}; do
|
for file in "${filepaths[@]}"; do
|
||||||
echo "::debug::Checking $file"
|
|
||||||
"${{ github.action_path }}/shellcheck" \
|
"${{ github.action_path }}/shellcheck" \
|
||||||
${{ steps.options.outputs.options }} \
|
${INPUT_SHELLCHECK_OPTIONS} \
|
||||||
"$file" || statuscode=$?;
|
"$file" || statuscode=$?
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "::set-output name=statuscode::$statuscode"
|
echo "filepaths=${filepaths[@]}" >> $GITHUB_OUTPUT
|
||||||
|
echo "statuscode=$statuscode" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Print information
|
set +f # re-enable globbing
|
||||||
|
|
||||||
|
- name: Exit action
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: exit ${{steps.check.outputs.statuscode}}
|
||||||
echo "Files: ${{steps.filepaths.outputs.filepaths}}"
|
|
||||||
echo "Excluded: ${{ steps.exclude.outputs.excludes }}"
|
|
||||||
echo "Options: ${{ steps.options.outputs.options }}"
|
|
||||||
echo "Status code: ${{steps.check.outputs.statuscode}}"
|
|
||||||
|
|
||||||
exit ${{steps.check.outputs.statuscode}}
|
|
||||||
|
3
testfiles/duplicate_name.bash
Normal file
3
testfiles/duplicate_name.bash
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
test="test"
|
||||||
|
echo "$test"
|
3
testfiles/ignore/ignore.bash
Normal file
3
testfiles/ignore/ignore.bash
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
test="test"
|
||||||
|
echo "$test"
|
@ -1,5 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
echo $test $test
|
|
||||||
|
|
||||||
echo $test2
|
|
4
testfiles/ignore_single_file.sh
Normal file
4
testfiles/ignore_single_file.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/sh
|
||||||
|
|
||||||
|
test="test"
|
||||||
|
echo "$test"
|
3
testfiles/ignore_some/do_not_ignore.bash
Normal file
3
testfiles/ignore_some/do_not_ignore.bash
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
test="test"
|
||||||
|
echo "$test"
|
3
testfiles/ignore_some/duplicate_name.bash
Normal file
3
testfiles/ignore_some/duplicate_name.bash
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
test="test"
|
||||||
|
echo "$test"
|
3
testfiles/ignore_some/ignore.bash
Normal file
3
testfiles/ignore_some/ignore.bash
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
test="test"
|
||||||
|
echo "$test"
|
3
testfiles/scandir/run me.bash
Normal file
3
testfiles/scandir/run me.bash
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo "I love spaces"
|
Loading…
x
Reference in New Issue
Block a user