1
0
Fork 0
mirror of https://github.com/ludeeus/action-shellcheck.git synced 2024-08-16 10:09:53 +02:00
shellcheck/action.yaml

219 lines
6.9 KiB
YAML
Raw Normal View History

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:
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."
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:
2020-10-25 21:00:46 +01:00
description: "Minimum severity of errors to consider. Options: [error, warning, info, style]"
required: false
2020-10-25 21:00:46 +01:00
default: ""
check_together:
2020-10-25 21:00:46 +01:00
description: "Run shellcheck on _all_ files at once, instead of one at a time"
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"
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"
2020-10-25 21:00:46 +01:00
outputs:
files:
description: A list of files with issues
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"
steps:
2020-10-25 21:00:46 +01:00
- 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"
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
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"
- 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
options+=("--format=${{ inputs.format }}")
echo "options=${options[@]}" >> $GITHUB_OUTPUT
2020-10-25 21:00:46 +01:00
- 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\"")
if [[ -n "${{ inputs.ignore }}" ]]; then
echo "::warning::ignore is deprecated. Please use ignore_paths instead"
for path in ${{ inputs.ignore }}; do
echo "::debug:: Adding '$path' to excludes"
excludes+=("! -path \"*./$path/*\"")
excludes+=("! -path \"*/$path/*\"")
excludes+=("! -path \"$path\"")
done
else
for path in ${{ inputs.ignore_paths }}; do
echo "::debug:: Adding '$path' to excludes"
excludes+=("! -path \"*./$path/*\"")
excludes+=("! -path \"*/$path/*\"")
excludes+=("! -path \"$path\"")
done
fi
for name in ${{ inputs.ignore_names }}; do
echo "::debug:: Adding '$name' to excludes"
excludes+=("! -name $name")
2020-10-25 21:00:46 +01:00
done
echo "excludes=${excludes[@]}" >> $GITHUB_OUTPUT
2020-10-25 21:00:46 +01: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
echo "::debug:: Adding '$file' to excludes"
2020-10-25 21:00:46 +01:00
files+=("-o -name \"*$file\"")
done
echo "files=${files[@]}" >> $GITHUB_OUTPUT
2020-10-25 21:00:46 +01:00
- name: Run the check
2020-10-25 21:00:46 +01:00
shell: bash
id: check
2020-10-25 21:00:46 +01:00
run: |
statuscode=0
2020-10-25 21:00:46 +01:00
declare -a filepaths
shebangregex="^#! */[^ ]*/(env *)?[abk]*sh"
2020-10-25 21:00:46 +01: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 }} \
')' \
-print0)
2020-10-25 21:00:46 +01:00
while IFS= read -r -d '' file; do
2020-10-25 21:00:46 +01:00
head -n1 "$file" | grep -Eqs "$shebangregex" || continue
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
"${{ github.action_path }}/shellcheck" \
${{ steps.options.outputs.options }} \
"${filepaths[@]}" || statuscode=$?
2020-10-25 21:00:46 +01:00
else
for file in "${filepaths[@]}"; do
echo "::debug::Checking '$file'"
2020-10-25 21:00:46 +01:00
"${{ github.action_path }}/shellcheck" \
${{ steps.options.outputs.options }} \
"$file" || statuscode=$?
2020-10-25 21:00:46 +01:00
done
fi
echo "filepaths=${filepaths[@]}" >> $GITHUB_OUTPUT
echo "statuscode=$statuscode" >> $GITHUB_OUTPUT
2020-10-25 21:00:46 +01:00
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}}