mirror of
https://github.com/ludeeus/action-shellcheck.git
synced 2025-04-13 13:49:20 +02:00
Compare commits
No commits in common. "master" and "1.1.0" have entirely different histories.
@ -1,4 +0,0 @@
|
||||
{
|
||||
"name": "ludeeus/action-shellcheck",
|
||||
"image": "mcr.microsoft.com/devcontainers/base:bullseye"
|
||||
}
|
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
|
18
.github/problem-matcher-gcc.json
vendored
Normal file
18
.github/problem-matcher-gcc.json
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"problemMatcher": [
|
||||
{
|
||||
"owner": "shellcheck-gcc",
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^(.+):(\\d+):(\\d+):\\s(note|warning|error):\\s(.*)\\s\\[(SC\\d+)\\]$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"severity": 4,
|
||||
"message": 5,
|
||||
"code": 6
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
23
.github/problem-matcher-tty.json
vendored
Normal file
23
.github/problem-matcher-tty.json
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"problemMatcher": [
|
||||
{
|
||||
"owner": "shellcheck-tty",
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^In\\s(.+)\\sline\\s(\\d+):$",
|
||||
"file": 1,
|
||||
"line": 2
|
||||
},
|
||||
{
|
||||
"regexp": ".*"
|
||||
},
|
||||
{
|
||||
"regexp": "(SC\\d+):\\s(.+)$",
|
||||
"code": 1,
|
||||
"message": 2,
|
||||
"loop": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
8
.github/release-drafter.yml
vendored
Normal file
8
.github/release-drafter.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
change-template: '- #$NUMBER $TITLE @$AUTHOR'
|
||||
sort-direction: ascending
|
||||
exclude-labels:
|
||||
- "release-drafter-ignore"
|
||||
template: |
|
||||
## What’s Changed
|
||||
|
||||
$CHANGES
|
11
.github/workflows/additional_files.yml
vendored
11
.github/workflows/additional_files.yml
vendored
@ -2,13 +2,8 @@ name: 'additional_files'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "master"
|
||||
branches: ["master"]
|
||||
pull_request:
|
||||
branches:
|
||||
- "master"
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
additional_files:
|
||||
@ -21,14 +16,14 @@ jobs:
|
||||
- macos-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.0
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Run ShellCheck
|
||||
uses: ./
|
||||
id: check
|
||||
with:
|
||||
additional_files: run finish discovery
|
||||
ignore_paths: ignore
|
||||
ignore: ignore
|
||||
scandir: testfiles
|
||||
|
||||
- name: Verify check
|
||||
|
@ -1,18 +1,13 @@
|
||||
name: 'ignore_names'
|
||||
name: 'base'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "master"
|
||||
branches: ["master"]
|
||||
pull_request:
|
||||
branches:
|
||||
- "master"
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
ignore_names:
|
||||
name: ignore_names
|
||||
base:
|
||||
name: base
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
@ -21,19 +16,18 @@ jobs:
|
||||
- macos-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.0
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Run ShellCheck
|
||||
uses: ./
|
||||
id: check
|
||||
with:
|
||||
ignore_paths: ignore
|
||||
ignore_names: ignore_single_file.sh
|
||||
ignore: ignore
|
||||
|
||||
- name: Verify check
|
||||
run: |
|
||||
expect="testfiles/test.bash"
|
||||
notexpect="testfiles/ignore_single_file.sh"
|
||||
notexpect="testfiles/ignore/ignore.bash"
|
||||
|
||||
if [[ ! "${{ steps.check.outputs.files }}" =~ $expect ]];then
|
||||
echo "::error:: Expected file $expect not found in ${{ steps.check.outputs.files }}"
|
||||
@ -41,4 +35,4 @@ jobs:
|
||||
elif [[ "${{ steps.check.outputs.files }}" =~ $notexpect ]];then
|
||||
echo "::error:: Expected file $notexpect found in ${{ steps.check.outputs.files }}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
11
.github/workflows/check_together.yml
vendored
11
.github/workflows/check_together.yml
vendored
@ -2,13 +2,8 @@ name: 'check_together'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "master"
|
||||
branches: ["master"]
|
||||
pull_request:
|
||||
branches:
|
||||
- "master"
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
check_together:
|
||||
@ -21,13 +16,13 @@ jobs:
|
||||
- macos-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.0
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Run ShellCheck
|
||||
uses: ./
|
||||
id: check
|
||||
with:
|
||||
ignore_paths: ignore
|
||||
ignore: ignore
|
||||
check_together: true
|
||||
|
||||
- name: Verify check
|
||||
|
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
|
16
.github/workflows/release-drafter.yml
vendored
Normal file
16
.github/workflows/release-drafter.yml
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
name: Release Drafter
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
release-drafter:
|
||||
name: Release Drafter
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 🏃 Run Release Drafter
|
||||
uses: release-drafter/release-drafter@v5
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
23
.github/workflows/scandir.yml
vendored
23
.github/workflows/scandir.yml
vendored
@ -1,14 +1,9 @@
|
||||
name: 'scandir'
|
||||
|
||||
on:
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "master"
|
||||
branches: ["master"]
|
||||
pull_request:
|
||||
branches:
|
||||
- "master"
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
scandir:
|
||||
@ -21,7 +16,7 @@ jobs:
|
||||
- macos-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.0
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Run ShellCheck
|
||||
uses: ./
|
||||
@ -30,8 +25,8 @@ jobs:
|
||||
scandir: testfiles/scandir
|
||||
|
||||
- name: Verify check
|
||||
run: |
|
||||
expect="testfiles/scandir/run[[:space:]]me.bash"
|
||||
run: |
|
||||
expect="testfiles/scandir/test.bash"
|
||||
notexpect="testfiles/test.bash"
|
||||
|
||||
if [[ ! "${{ steps.one.outputs.files }}" =~ $expect ]];then
|
||||
@ -40,17 +35,17 @@ jobs:
|
||||
elif [[ "${{ steps.one.outputs.files }}" =~ $notexpect ]];then
|
||||
echo "::error:: Expected file $notexpect found in ${{ steps.one.outputs.files }}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
- name: Run ShellCheck
|
||||
uses: ./
|
||||
id: two
|
||||
with:
|
||||
scandir: './testfiles/scandir'
|
||||
ignore_paths: ignore
|
||||
ignore: ignore
|
||||
|
||||
- name: Verify check
|
||||
run: |
|
||||
run: |
|
||||
expect="testfiles/scandir/test.bash"
|
||||
notexpect="testfiles/test.bash"
|
||||
|
||||
@ -60,4 +55,4 @@ jobs:
|
||||
elif [[ "${{ steps.two.outputs.files }}" =~ $notexpect ]];then
|
||||
echo "::error:: Expected file $notexpect found in ${{ steps.two.outputs.files }}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
75
README.md
75
README.md
@ -1,26 +1,25 @@
|
||||
# ShellCheck
|
||||
|
||||
_GitHub action for [ShellCheck](https://www.shellcheck.net/)._
|
||||
_GitHub action for ShellCheck._
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
branch:
|
||||
- master
|
||||
|
||||
name: "Trigger: Push action"
|
||||
permissions: {}
|
||||
name: 'Trigger: Push action'
|
||||
|
||||
jobs:
|
||||
shellcheck:
|
||||
name: Shellcheck
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run ShellCheck
|
||||
uses: ludeeus/action-shellcheck@master
|
||||
- uses: actions/checkout@v2
|
||||
- name: Run ShellCheck
|
||||
uses: ludeeus/action-shellcheck@master
|
||||
```
|
||||
|
||||
## ShellCheck options
|
||||
@ -29,8 +28,8 @@ You can pass any supported ShellCheck option or flag with the `SHELLCHECK_OPTS`
|
||||
|
||||
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`)
|
||||
* To disable specific checks (eg: `-e SC2059 -e SC2034 -e SC1090`)
|
||||
* To test against different shells (eg: `-s dash` or `-s ksh`)
|
||||
|
||||
example:
|
||||
|
||||
@ -42,18 +41,15 @@ example:
|
||||
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.
|
||||
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.
|
||||
You can use the `ignore` input to disable specific directories.
|
||||
|
||||
```text
|
||||
sample structure:
|
||||
sample/directory/with/files/ignoreme/test.sh
|
||||
sample/directory/with/files/ignoremetoo/test.sh
|
||||
sample/directory/with/files/test.sh
|
||||
sample/directory/with/files/ignorable.sh
|
||||
```
|
||||
|
||||
example:
|
||||
@ -63,27 +59,10 @@ example:
|
||||
- name: Run ShellCheck
|
||||
uses: ludeeus/action-shellcheck@master
|
||||
with:
|
||||
ignore_paths: >-
|
||||
ignoreme
|
||||
ignoremetoo
|
||||
ignore_names: ignorable.sh
|
||||
ignore: ignoreme ignoremetoo
|
||||
```
|
||||
|
||||
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`.
|
||||
This will skip `sample/directory/with/files/ignoreme/test.sh` and `sample/directory/with/files/ignoremetoo/test.sh`
|
||||
|
||||
## Minimum severity of errors to consider (error, warning, info, style)
|
||||
|
||||
@ -140,12 +119,26 @@ If you need to scan for unusual files, you can use the `additional_files` key.
|
||||
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
|
||||
```
|
||||
|
||||
## 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
|
||||
- `gcc` has single-line log messages
|
||||
- `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
|
||||
...
|
||||
@ -154,15 +147,3 @@ Shellcheck can print output in these formats: `checkstyle`, `diff`, `gcc`, `json
|
||||
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
|
||||
```
|
||||
|
181
action.yaml
181
action.yaml
@ -10,15 +10,6 @@ inputs:
|
||||
description: "Paths to ignore when running ShellCheck"
|
||||
required: false
|
||||
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:
|
||||
description: "Minimum severity of errors to consider. Options: [error, warning, info, style]"
|
||||
required: false
|
||||
@ -35,19 +26,14 @@ inputs:
|
||||
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 }}
|
||||
value: ${{ steps.filepaths.outputs.filepaths }}
|
||||
options:
|
||||
description: The options used
|
||||
value: ${{ steps.options.outputs.options }}
|
||||
@ -57,10 +43,16 @@ branding:
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Enable problem-matcher
|
||||
shell: bash
|
||||
run: |
|
||||
problem_matcher_file="${{ github.action_path }}/.github/problem-matcher-${{ inputs.format }}.json"
|
||||
if [[ ${{ inputs.disable_matcher }} != "true" && -f "$problem_matcher_file" ]]; then
|
||||
echo "::add-matcher::$problem_matcher_file"
|
||||
fi
|
||||
|
||||
- name: Download shellcheck
|
||||
shell: bash
|
||||
env:
|
||||
INPUT_VERSION: ${{ inputs.version }}
|
||||
run: |
|
||||
if [[ "${{ runner.os }}" == "macOS" ]]; then
|
||||
osvariant="darwin"
|
||||
@ -68,13 +60,14 @@ runs:
|
||||
osvariant="linux"
|
||||
fi
|
||||
|
||||
scversion="stable"
|
||||
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"
|
||||
"${baseurl}/${scversion}/shellcheck-${scversion}.${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" \
|
||||
mv "${{ github.action_path }}/shellcheck-${scversion}/shellcheck" \
|
||||
"${{ github.action_path }}/shellcheck"
|
||||
|
||||
- name: Display shellcheck version
|
||||
@ -85,85 +78,49 @@ runs:
|
||||
- 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}")
|
||||
if [[ -n "${{ inputs.severity }}" ]]; then
|
||||
options+=("-S ${{ inputs.severity }}")
|
||||
fi
|
||||
options+=("--format=${INPUT_FORMAT}")
|
||||
echo "options=${options[@]}" >> $GITHUB_OUTPUT
|
||||
options+=("--format=${{ inputs.format }}")
|
||||
echo "::set-output name=options::${options[@]}"
|
||||
|
||||
- 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")
|
||||
excludes+=("! -path \"*./.git/*\"")
|
||||
excludes+=("! -path \"*.go\"")
|
||||
excludes+=("! -path \"*/mvnw\"")
|
||||
for path in ${{ inputs.ignore }}; do
|
||||
echo "::debug:: Adding "$path" to excludes"
|
||||
excludes+=("! -path \"*./$path/*\"")
|
||||
excludes+=("! -path \"*/$path/*\"")
|
||||
done
|
||||
echo "excludes=${excludes[@]}" >> $GITHUB_OUTPUT
|
||||
|
||||
set +f # re-enable globbing
|
||||
echo "::set-output name=excludes::${excludes[@]}"
|
||||
|
||||
- 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")
|
||||
for file in ${{ inputs.additional_files }}; do
|
||||
echo "::debug:: Adding "$file" to excludes"
|
||||
files+=("-o -name \"*$file\"")
|
||||
done
|
||||
echo "files=${files[@]}" >> $GITHUB_OUTPUT
|
||||
echo "::set-output name=files::${files[@]}"
|
||||
|
||||
- name: Run the check
|
||||
- name: Gather base file paths
|
||||
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 }}
|
||||
id: filepaths
|
||||
run: |
|
||||
statuscode=0
|
||||
declare -a filepaths
|
||||
shebangregex="^#! */[^ ]*/(env *)?[abk]*sh"
|
||||
shebangregex="^#! */[^ ]*/(env *)?[abkz]*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 \
|
||||
for path in $(find "${{ inputs.scandir }}" \
|
||||
-type f -type f ${{ steps.exclude.outputs.excludes }} \
|
||||
'(' \
|
||||
-name '*.bash' \
|
||||
-o -name '.bashrc' \
|
||||
@ -191,35 +148,63 @@ runs:
|
||||
-o -path '*/.profile' \
|
||||
-o -path '*/profile' \
|
||||
-o -name '*.shlib' \
|
||||
${INPUT_ADDITIONAL_FILE_ARGS} \
|
||||
')' \
|
||||
-print0)
|
||||
${{ steps.additional.outputs.files }} \
|
||||
')'\
|
||||
-print); do
|
||||
filepaths+=("$path");
|
||||
done
|
||||
|
||||
while IFS= read -r -d '' file; do
|
||||
for file in $(find "${{ inputs.scandir }}" ${{ steps.exclude.outputs.excludes }} -type f ! -name '*.*' -perm /111 -print); do
|
||||
head -n1 "$file" | grep -Eqs "$shebangregex" || continue
|
||||
filepaths+=("$file")
|
||||
done < <(find "${INPUT_SCANDIR}" \
|
||||
${INPUT_EXCLUDE_ARGS} \
|
||||
-type f ! -name '*.*' -perm /111 \
|
||||
-print0)
|
||||
filepaths+=("$file");
|
||||
done
|
||||
echo "::set-output name=filepaths::${filepaths[@]}"
|
||||
|
||||
if [[ -n "${INPUT_CHECK_TOGETHER}" ]]; then
|
||||
"${{ github.action_path }}/shellcheck" \
|
||||
${INPUT_SHELLCHECK_OPTIONS} \
|
||||
"${filepaths[@]}" || statuscode=$?
|
||||
- name: Check bin subdirs
|
||||
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" \
|
||||
${{ steps.options.outputs.options }} \
|
||||
${{ steps.filepaths.outputs.filepaths }} || statuscode=$?
|
||||
else
|
||||
for file in "${filepaths[@]}"; do
|
||||
for file in ${{ steps.filepaths.outputs.filepaths }}; do
|
||||
echo "::debug::Checking $file"
|
||||
"${{ github.action_path }}/shellcheck" \
|
||||
${INPUT_SHELLCHECK_OPTIONS} \
|
||||
"$file" || statuscode=$?
|
||||
${{ steps.options.outputs.options }} \
|
||||
"$file" || statuscode=$?;
|
||||
done
|
||||
fi
|
||||
|
||||
echo "filepaths=${filepaths[@]}" >> $GITHUB_OUTPUT
|
||||
echo "statuscode=$statuscode" >> $GITHUB_OUTPUT
|
||||
echo "::set-output name=statuscode::$statuscode"
|
||||
|
||||
set +f # re-enable globbing
|
||||
|
||||
- name: Exit action
|
||||
- name: Print information
|
||||
shell: bash
|
||||
run: exit ${{steps.check.outputs.statuscode}}
|
||||
run: |
|
||||
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}}
|
||||
|
@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
test="test"
|
||||
echo "$test"
|
@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
test="test"
|
||||
echo "$test"
|
5
testfiles/ignore/ignore.sh
Normal file
5
testfiles/ignore/ignore.sh
Normal file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo $test $test
|
||||
|
||||
echo $test2
|
@ -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 bash
|
||||
|
||||
echo "I love spaces"
|
Loading…
x
Reference in New Issue
Block a user