2020-05-30 11:44:01 +02:00
|
|
|
name: "ShellCheck"
|
|
|
|
author: "Ludeeus <hi@ludeeus.dev>"
|
|
|
|
description: "GitHub action for ShellCheck."
|
|
|
|
inputs:
|
2020-10-25 21:00:46 +01:00
|
|
|
additional_files:
|
2021-02-11 04:30:11 -05:00
|
|
|
description: "A space separated list of additional filename to check"
|
2020-10-25 21:00:46 +01:00
|
|
|
required: false
|
|
|
|
default: ""
|
2020-05-30 11:44:01 +02:00
|
|
|
ignore:
|
2020-10-25 21:00:46 +01:00
|
|
|
description: "Paths to ignore when running ShellCheck"
|
2020-05-30 11:44:01 +02:00
|
|
|
required: false
|
2020-10-25 21:00:46 +01:00
|
|
|
default: ""
|
2022-09-03 10:53:15 +02:00
|
|
|
deprecationMessage: "Use ignore_paths or ignore_names instead."
|
2021-11-14 11:01:29 +01:00
|
|
|
ignore_paths:
|
|
|
|
description: "Paths to ignore when running ShellCheck"
|
|
|
|
required: false
|
|
|
|
default: ""
|
|
|
|
ignore_names:
|
|
|
|
description: "Names to ignore when running ShellCheck"
|
|
|
|
required: false
|
|
|
|
default: ""
|
2020-06-26 08:05:34 +02:00
|
|
|
severity:
|
2020-10-25 21:00:46 +01:00
|
|
|
description: "Minimum severity of errors to consider. Options: [error, warning, info, style]"
|
2020-06-26 08:05:34 +02:00
|
|
|
required: false
|
2020-10-25 21:00:46 +01:00
|
|
|
default: ""
|
2020-06-26 15:41:45 -04:00
|
|
|
check_together:
|
2020-10-25 21:00:46 +01:00
|
|
|
description: "Run shellcheck on _all_ files at once, instead of one at a time"
|
2020-06-26 15:41:45 -04:00
|
|
|
required: false
|
2020-10-25 21:00:46 +01:00
|
|
|
default: ""
|
2020-10-03 14:49:12 +02:00
|
|
|
scandir:
|
2020-10-25 21:00:46 +01:00
|
|
|
description: "Directory to be searched for files. Defaults to ."
|
2020-10-03 14:49:12 +02:00
|
|
|
required: false
|
2020-10-25 21:00:46 +01:00
|
|
|
default: "."
|
|
|
|
disable_matcher:
|
|
|
|
description: "Set to true to skip using problem-matcher"
|
|
|
|
required: false
|
|
|
|
default: "false"
|
2021-03-31 21:03:27 +02:00
|
|
|
format:
|
|
|
|
description: "Output format (checkstyle, diff, gcc, json, json1, quiet, tty)"
|
|
|
|
required: false
|
|
|
|
default: "gcc"
|
2021-11-14 10:21:33 +01:00
|
|
|
version:
|
2021-11-14 18:10:08 +09:00
|
|
|
description: "Specify a concrete version of ShellCheck to use"
|
|
|
|
required: false
|
|
|
|
default: "stable"
|
2020-10-25 21:00:46 +01:00
|
|
|
outputs:
|
|
|
|
files:
|
|
|
|
description: A list of files with issues
|
2022-09-03 10:31:50 +02:00
|
|
|
value: ${{ steps.check.outputs.filepaths }}
|
2020-10-25 21:00:46 +01:00
|
|
|
options:
|
|
|
|
description: The options used
|
|
|
|
value: ${{ steps.options.outputs.options }}
|
2020-05-30 11:44:01 +02:00
|
|
|
branding:
|
2020-10-25 21:00:46 +01:00
|
|
|
icon: "terminal"
|
|
|
|
color: "gray-dark"
|
|
|
|
runs:
|
|
|
|
using: "composite"
|
2021-03-31 21:03:27 +02:00
|
|
|
steps:
|
2020-10-25 21:00:46 +01:00
|
|
|
- name: Enable problem-matcher
|
|
|
|
shell: bash
|
|
|
|
run: |
|
2021-03-31 21:03:27 +02:00
|
|
|
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"
|
2020-10-25 21:00:46 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
- name: Download shellcheck
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
if [[ "${{ runner.os }}" == "macOS" ]]; then
|
|
|
|
osvariant="darwin"
|
|
|
|
else
|
|
|
|
osvariant="linux"
|
|
|
|
fi
|
|
|
|
|
2021-11-14 10:21:33 +01:00
|
|
|
scversion="${{ inputs.version }}"
|
2020-10-25 21:00:46 +01:00
|
|
|
baseurl="https://github.com/koalaman/shellcheck/releases/download"
|
|
|
|
|
|
|
|
curl -Lso "${{ github.action_path }}/sc.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-${scversion}/shellcheck" \
|
|
|
|
"${{ github.action_path }}/shellcheck"
|
|
|
|
|
2021-01-16 23:47:30 +01:00
|
|
|
- name: Display shellcheck version
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
"${{ github.action_path }}/shellcheck" --version
|
|
|
|
|
2020-10-25 21:00:46 +01:00
|
|
|
- name: Set options
|
|
|
|
shell: bash
|
|
|
|
id: options
|
|
|
|
run: |
|
|
|
|
declare -a options
|
|
|
|
if [[ -n "${{ inputs.severity }}" ]]; then
|
|
|
|
options+=("-S ${{ inputs.severity }}")
|
|
|
|
fi
|
2021-03-31 21:03:27 +02:00
|
|
|
options+=("--format=${{ inputs.format }}")
|
2020-10-25 21:00:46 +01:00
|
|
|
echo "::set-output name=options::${options[@]}"
|
|
|
|
|
|
|
|
- name: Gather excluded paths
|
|
|
|
shell: bash
|
|
|
|
id: exclude
|
|
|
|
run: |
|
|
|
|
declare -a excludes
|
2022-09-03 10:53:15 +02:00
|
|
|
set -f # temporarily disable globbing so that globs in input aren't expanded
|
|
|
|
|
2020-10-25 21:00:46 +01:00
|
|
|
excludes+=("! -path \"*./.git/*\"")
|
|
|
|
excludes+=("! -path \"*.go\"")
|
|
|
|
excludes+=("! -path \"*/mvnw\"")
|
2021-11-14 11:01:29 +01:00
|
|
|
if [[ -n "${{ inputs.ignore }}" ]]; then
|
|
|
|
echo "::warning::ignore is deprecated. Please use ignore_paths instead"
|
|
|
|
for path in ${{ inputs.ignore }}; do
|
2022-09-03 10:31:50 +02:00
|
|
|
echo "::debug:: Adding '$path' to excludes"
|
2021-11-14 11:01:29 +01:00
|
|
|
excludes+=("! -path \"*./$path/*\"")
|
|
|
|
excludes+=("! -path \"*/$path/*\"")
|
2022-09-03 01:29:32 -07:00
|
|
|
excludes+=("! -path \"$path\"")
|
2021-11-14 11:01:29 +01:00
|
|
|
done
|
|
|
|
else
|
|
|
|
for path in ${{ inputs.ignore_paths }}; do
|
2022-09-03 10:31:50 +02:00
|
|
|
echo "::debug:: Adding '$path' to excludes"
|
2021-11-14 11:01:29 +01:00
|
|
|
excludes+=("! -path \"*./$path/*\"")
|
|
|
|
excludes+=("! -path \"*/$path/*\"")
|
2022-09-03 01:29:32 -07:00
|
|
|
excludes+=("! -path \"$path\"")
|
2021-11-14 11:01:29 +01:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
for name in ${{ inputs.ignore_names }}; do
|
2022-09-03 10:31:50 +02:00
|
|
|
echo "::debug:: Adding '$name' to excludes"
|
2021-11-14 11:01:29 +01:00
|
|
|
excludes+=("! -name $name")
|
2020-10-25 21:00:46 +01:00
|
|
|
done
|
|
|
|
echo "::set-output name=excludes::${excludes[@]}"
|
|
|
|
|
2022-09-03 01:29:32 -07:00
|
|
|
set +f # re-enable globbing
|
|
|
|
|
2020-10-25 21:00:46 +01:00
|
|
|
- name: Gather additional files
|
|
|
|
shell: bash
|
|
|
|
id: additional
|
|
|
|
run: |
|
|
|
|
declare -a files
|
|
|
|
for file in ${{ inputs.additional_files }}; do
|
2022-09-03 10:31:50 +02:00
|
|
|
echo "::debug:: Adding '$file' to excludes"
|
2020-10-25 21:00:46 +01:00
|
|
|
files+=("-o -name \"*$file\"")
|
|
|
|
done
|
|
|
|
echo "::set-output name=files::${files[@]}"
|
|
|
|
|
2022-09-03 10:31:50 +02:00
|
|
|
- name: Run the check
|
2020-10-25 21:00:46 +01:00
|
|
|
shell: bash
|
2022-09-03 10:31:50 +02:00
|
|
|
id: check
|
2020-10-25 21:00:46 +01:00
|
|
|
run: |
|
2022-09-03 10:31:50 +02:00
|
|
|
statuscode=0
|
2020-10-25 21:00:46 +01:00
|
|
|
declare -a filepaths
|
2021-11-01 10:08:12 +01:00
|
|
|
shebangregex="^#! */[^ ]*/(env *)?[abk]*sh"
|
2020-10-25 21:00:46 +01:00
|
|
|
|
2022-09-03 10:31:50 +02:00
|
|
|
while IFS= read -r -d '' file; do
|
|
|
|
filepaths+=("$file")
|
|
|
|
done < <(find "${{ inputs.scandir }}" \
|
|
|
|
${{ steps.exclude.outputs.excludes }} \
|
|
|
|
-type f \
|
2020-10-25 21:00:46 +01:00
|
|
|
'(' \
|
|
|
|
-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' \
|
|
|
|
${{ steps.additional.outputs.files }} \
|
2022-09-03 10:31:50 +02:00
|
|
|
')' \
|
|
|
|
-print0)
|
2020-10-25 21:00:46 +01:00
|
|
|
|
2022-09-03 10:31:50 +02:00
|
|
|
while IFS= read -r -d '' file; do
|
2020-10-25 21:00:46 +01:00
|
|
|
head -n1 "$file" | grep -Eqs "$shebangregex" || continue
|
2022-09-03 10:31:50 +02:00
|
|
|
filepaths+=("$file")
|
|
|
|
done < <(find "${{ inputs.scandir }}" \
|
|
|
|
${{ steps.exclude.outputs.excludes }} \
|
|
|
|
-type f ! -name '*.*' -perm /111 \
|
|
|
|
-print0)
|
2020-10-25 21:00:46 +01:00
|
|
|
|
|
|
|
if [[ -n "${{ inputs.check_together }}" ]]; then
|
2022-09-03 10:31:50 +02:00
|
|
|
"${{ github.action_path }}/shellcheck" \
|
|
|
|
${{ steps.options.outputs.options }} \
|
|
|
|
"${filepaths[@]}" || statuscode=$?
|
2020-10-25 21:00:46 +01:00
|
|
|
else
|
2022-09-03 10:31:50 +02:00
|
|
|
for file in "${filepaths[@]}"; do
|
|
|
|
echo "::debug::Checking '$file'"
|
2020-10-25 21:00:46 +01:00
|
|
|
"${{ github.action_path }}/shellcheck" \
|
2022-09-03 10:31:50 +02:00
|
|
|
${{ steps.options.outputs.options }} \
|
|
|
|
"$file" || statuscode=$?
|
2020-10-25 21:00:46 +01:00
|
|
|
done
|
|
|
|
fi
|
2021-03-31 21:03:27 +02:00
|
|
|
|
2022-09-03 10:31:50 +02:00
|
|
|
echo "::set-output name=filepaths::${filepaths[@]}"
|
2020-10-25 21:00:46 +01:00
|
|
|
echo "::set-output name=statuscode::$statuscode"
|
|
|
|
|
2022-09-03 10:45:55 +02:00
|
|
|
- name: Exit action
|
2020-10-25 21:00:46 +01:00
|
|
|
shell: bash
|
2022-09-03 10:45:55 +02:00
|
|
|
run: exit ${{steps.check.outputs.statuscode}}
|