mirror of
https://github.com/ludeeus/action-shellcheck.git
synced 2024-08-16 10:09:53 +02:00
Conditionally download shellcheck
- if shellcheck doesn't exist, downloads it. optionally to a version specified. - if it exists and no version is specified, use that - if it exists but a version specified, and it matches use that - otherwise fail loudly
This commit is contained in:
parent
cd81f4475a
commit
4966c1ae63
1 changed files with 73 additions and 41 deletions
114
action.yaml
114
action.yaml
|
@ -1,49 +1,49 @@
|
||||||
name: "ShellCheck"
|
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:
|
additional_files:
|
||||||
description: "A space separated 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."
|
deprecationMessage: 'Use ignore_paths or ignore_names instead.'
|
||||||
ignore_paths:
|
ignore_paths:
|
||||||
description: "Paths to ignore when running ShellCheck"
|
description: 'Paths to ignore when running ShellCheck'
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ''
|
||||||
ignore_names:
|
ignore_names:
|
||||||
description: "Names to ignore when running ShellCheck"
|
description: 'Names to ignore when running ShellCheck'
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
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
|
||||||
default: ""
|
default: ''
|
||||||
check_together:
|
check_together:
|
||||||
description: "Run shellcheck on _all_ files at once, instead of one at a time"
|
description: 'Run shellcheck on _all_ files at once, instead of one at a time'
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ''
|
||||||
scandir:
|
scandir:
|
||||||
description: "Directory to be searched for files. Defaults to ."
|
description: 'Directory to be searched for files. Defaults to .'
|
||||||
required: false
|
required: false
|
||||||
default: "."
|
default: '.'
|
||||||
disable_matcher:
|
disable_matcher:
|
||||||
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."
|
deprecationMessage: 'There are no problem-matchers, this setting does not do anything.'
|
||||||
format:
|
format:
|
||||||
description: "Output format (checkstyle, diff, gcc, json, json1, quiet, tty)"
|
description: 'Output format (checkstyle, diff, gcc, json, json1, quiet, tty)'
|
||||||
required: false
|
required: false
|
||||||
default: "gcc"
|
default: 'gcc'
|
||||||
version:
|
version:
|
||||||
description: "Specify a concrete version of ShellCheck to use"
|
description: 'Specify a concrete version of ShellCheck to use'
|
||||||
required: false
|
required: false
|
||||||
default: "stable"
|
|
||||||
outputs:
|
outputs:
|
||||||
files:
|
files:
|
||||||
description: A list of files with issues
|
description: A list of files with issues
|
||||||
|
@ -52,35 +52,67 @@ outputs:
|
||||||
description: The options used
|
description: The options used
|
||||||
value: ${{ steps.options.outputs.options }}
|
value: ${{ steps.options.outputs.options }}
|
||||||
branding:
|
branding:
|
||||||
icon: "terminal"
|
icon: 'terminal'
|
||||||
color: "gray-dark"
|
color: 'gray-dark'
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: 'composite'
|
||||||
steps:
|
steps:
|
||||||
- name: Download shellcheck
|
- name: Download shellcheck
|
||||||
shell: bash
|
shell: bash
|
||||||
|
id: binary
|
||||||
env:
|
env:
|
||||||
INPUT_VERSION: ${{ inputs.version }}
|
INPUT_VERSION: ${{ inputs.version }}
|
||||||
run: |
|
run: |
|
||||||
if [[ "${{ runner.os }}" == "macOS" ]]; then
|
# check if shellcheck already installed
|
||||||
osvariant="darwin"
|
existing="$(command -v shellcheck)"
|
||||||
else
|
existing_version=[[ -n "${existing}" ]] && "${existing}" --version | grep -oP '(?<=version: )[^ ]+'
|
||||||
osvariant="linux"
|
|
||||||
|
# if doesn't exist, download it
|
||||||
|
if [[ -z "${existing}" ]]; then
|
||||||
|
|
||||||
|
desired_version=${INPUT_VERSION:-stable}
|
||||||
|
|
||||||
|
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}/${desired_version}/shellcheck-${desired_version}.${osvariant}.x86_64.tar.xz"
|
||||||
|
|
||||||
|
tar -xf "${{ github.action_path }}/sc.tar.xz" -C "${{ github.action_path }}"
|
||||||
|
mv "${{ github.action_path }}/shellcheck-${desired_version}/shellcheck" \
|
||||||
|
"${{ github.action_path }}/shellcheck"
|
||||||
|
|
||||||
|
echo "path=${{ github.action_path }}/shellcheck" >> $GITHUB_OUTPUT
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
baseurl="https://github.com/koalaman/shellcheck/releases/download"
|
# if existing but no version specified, use whatever exists
|
||||||
|
if [[ -z "${INPUT_VERSION}" ]]; then
|
||||||
|
echo "Using existing shellcheck"
|
||||||
|
echo "path=${existing}" >> $GITHUB_OUTPUT
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
curl -Lso "${{ github.action_path }}/sc.tar.xz" \
|
# if existing and version specified, check if it matches
|
||||||
"${baseurl}/${INPUT_VERSION}/shellcheck-${INPUT_VERSION}.${osvariant}.x86_64.tar.xz"
|
if [[ "${existing_version}" == "${INPUT_VERSION}" ]]; then
|
||||||
|
echo "Using existing shellcheck ${INPUT_VERSION}"
|
||||||
|
echo "path=${existing}" >> $GITHUB_OUTPUT
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
tar -xf "${{ github.action_path }}/sc.tar.xz" -C "${{ github.action_path }}"
|
# otherwise, fail loudly
|
||||||
mv "${{ github.action_path }}/shellcheck-${INPUT_VERSION}/shellcheck" \
|
echo "Existing shellcheck version ${existing_version} does not match specified version ${INPUT_VERSION}"
|
||||||
"${{ github.action_path }}/shellcheck"
|
exit 1
|
||||||
|
|
||||||
- name: Display shellcheck version
|
- name: Display shellcheck version
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
"${{ github.action_path }}/shellcheck" --version
|
"${{ steps.binary.outputs.path }}" --version
|
||||||
|
|
||||||
- name: Set options
|
- name: Set options
|
||||||
shell: bash
|
shell: bash
|
||||||
|
@ -204,12 +236,12 @@ runs:
|
||||||
-print0)
|
-print0)
|
||||||
|
|
||||||
if [[ -n "${INPUT_CHECK_TOGETHER}" ]]; then
|
if [[ -n "${INPUT_CHECK_TOGETHER}" ]]; then
|
||||||
"${{ github.action_path }}/shellcheck" \
|
"${{ steps.binary.outputs.path }}" \
|
||||||
${INPUT_SHELLCHECK_OPTIONS} \
|
${INPUT_SHELLCHECK_OPTIONS} \
|
||||||
"${filepaths[@]}" || statuscode=$?
|
"${filepaths[@]}" || statuscode=$?
|
||||||
else
|
else
|
||||||
for file in "${filepaths[@]}"; do
|
for file in "${filepaths[@]}"; do
|
||||||
"${{ github.action_path }}/shellcheck" \
|
"${{ steps.binary.outputs.path }}" \
|
||||||
${INPUT_SHELLCHECK_OPTIONS} \
|
${INPUT_SHELLCHECK_OPTIONS} \
|
||||||
"$file" || statuscode=$?
|
"$file" || statuscode=$?
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue