mirror of
https://github.com/ludeeus/action-shellcheck.git
synced 2024-08-16 10:09:53 +02:00
Fix warnings reported by shellcheck (#61)
Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
This commit is contained in:
parent
6096f68baf
commit
10434c2598
3 changed files with 41 additions and 39 deletions
12
.github/workflows/scandir.yml
vendored
12
.github/workflows/scandir.yml
vendored
|
@ -1,6 +1,6 @@
|
||||||
name: 'scandir'
|
name: 'scandir'
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["master"]
|
branches: ["master"]
|
||||||
pull_request:
|
pull_request:
|
||||||
|
@ -25,8 +25,8 @@ jobs:
|
||||||
scandir: testfiles/scandir
|
scandir: testfiles/scandir
|
||||||
|
|
||||||
- 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
|
||||||
|
@ -35,7 +35,7 @@ jobs:
|
||||||
elif [[ "${{ steps.one.outputs.files }}" =~ $notexpect ]];then
|
elif [[ "${{ steps.one.outputs.files }}" =~ $notexpect ]];then
|
||||||
echo "::error:: Expected file $notexpect found in ${{ steps.one.outputs.files }}"
|
echo "::error:: Expected file $notexpect found in ${{ steps.one.outputs.files }}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ./
|
uses: ./
|
||||||
|
@ -45,7 +45,7 @@ jobs:
|
||||||
ignore_paths: ignore
|
ignore_paths: ignore
|
||||||
|
|
||||||
- name: Verify check
|
- name: Verify check
|
||||||
run: |
|
run: |
|
||||||
expect="testfiles/scandir/test.bash"
|
expect="testfiles/scandir/test.bash"
|
||||||
notexpect="testfiles/test.bash"
|
notexpect="testfiles/test.bash"
|
||||||
|
|
||||||
|
@ -55,4 +55,4 @@ jobs:
|
||||||
elif [[ "${{ steps.two.outputs.files }}" =~ $notexpect ]];then
|
elif [[ "${{ steps.two.outputs.files }}" =~ $notexpect ]];then
|
||||||
echo "::error:: Expected file $notexpect found in ${{ steps.two.outputs.files }}"
|
echo "::error:: Expected file $notexpect found in ${{ steps.two.outputs.files }}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
65
action.yaml
65
action.yaml
|
@ -45,7 +45,7 @@ inputs:
|
||||||
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 }}
|
||||||
|
@ -111,14 +111,14 @@ runs:
|
||||||
if [[ -n "${{ inputs.ignore }}" ]]; then
|
if [[ -n "${{ inputs.ignore }}" ]]; then
|
||||||
echo "::warning::ignore is deprecated. Please use ignore_paths instead"
|
echo "::warning::ignore is deprecated. Please use ignore_paths instead"
|
||||||
for path in ${{ inputs.ignore }}; do
|
for path in ${{ inputs.ignore }}; do
|
||||||
echo "::debug:: Adding "$path" to excludes"
|
echo "::debug:: Adding '$path' to excludes"
|
||||||
excludes+=("! -path \"*./$path/*\"")
|
excludes+=("! -path \"*./$path/*\"")
|
||||||
excludes+=("! -path \"*/$path/*\"")
|
excludes+=("! -path \"*/$path/*\"")
|
||||||
excludes+=("! -path \"$path\"")
|
excludes+=("! -path \"$path\"")
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
for path in ${{ inputs.ignore_paths }}; do
|
for path in ${{ inputs.ignore_paths }}; do
|
||||||
echo "::debug:: Adding "$path" to excludes"
|
echo "::debug:: Adding '$path' to excludes"
|
||||||
excludes+=("! -path \"*./$path/*\"")
|
excludes+=("! -path \"*./$path/*\"")
|
||||||
excludes+=("! -path \"*/$path/*\"")
|
excludes+=("! -path \"*/$path/*\"")
|
||||||
excludes+=("! -path \"$path\"")
|
excludes+=("! -path \"$path\"")
|
||||||
|
@ -126,7 +126,7 @@ runs:
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for name in ${{ inputs.ignore_names }}; do
|
for name in ${{ inputs.ignore_names }}; do
|
||||||
echo "::debug:: Adding "$name" to excludes"
|
echo "::debug:: Adding '$name' to excludes"
|
||||||
excludes+=("! -name $name")
|
excludes+=("! -name $name")
|
||||||
done
|
done
|
||||||
echo "::set-output name=excludes::${excludes[@]}"
|
echo "::set-output name=excludes::${excludes[@]}"
|
||||||
|
@ -139,20 +139,24 @@ runs:
|
||||||
run: |
|
run: |
|
||||||
declare -a files
|
declare -a files
|
||||||
for file in ${{ inputs.additional_files }}; do
|
for file in ${{ inputs.additional_files }}; do
|
||||||
echo "::debug:: Adding "$file" to excludes"
|
echo "::debug:: Adding '$file' to excludes"
|
||||||
files+=("-o -name \"*$file\"")
|
files+=("-o -name \"*$file\"")
|
||||||
done
|
done
|
||||||
echo "::set-output name=files::${files[@]}"
|
echo "::set-output name=files::${files[@]}"
|
||||||
|
|
||||||
- name: Gather base file paths
|
- name: Run the check
|
||||||
shell: bash
|
shell: bash
|
||||||
id: filepaths
|
id: check
|
||||||
run: |
|
run: |
|
||||||
|
statuscode=0
|
||||||
declare -a filepaths
|
declare -a filepaths
|
||||||
shebangregex="^#! */[^ ]*/(env *)?[abk]*sh"
|
shebangregex="^#! */[^ ]*/(env *)?[abk]*sh"
|
||||||
|
|
||||||
for path in $(find "${{ inputs.scandir }}" \
|
while IFS= read -r -d '' file; do
|
||||||
-type f -type f ${{ steps.exclude.outputs.excludes }} \
|
filepaths+=("$file")
|
||||||
|
done < <(find "${{ inputs.scandir }}" \
|
||||||
|
${{ steps.exclude.outputs.excludes }} \
|
||||||
|
-type f \
|
||||||
'(' \
|
'(' \
|
||||||
-name '*.bash' \
|
-name '*.bash' \
|
||||||
-o -name '.bashrc' \
|
-o -name '.bashrc' \
|
||||||
|
@ -181,44 +185,39 @@ runs:
|
||||||
-o -path '*/profile' \
|
-o -path '*/profile' \
|
||||||
-o -name '*.shlib' \
|
-o -name '*.shlib' \
|
||||||
${{ steps.additional.outputs.files }} \
|
${{ steps.additional.outputs.files }} \
|
||||||
')'\
|
')' \
|
||||||
-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 "${{ inputs.scandir }}" \
|
||||||
echo "::set-output name=filepaths::${filepaths[@]}"
|
${{ steps.exclude.outputs.excludes }} \
|
||||||
|
-type f ! -name '*.*' -perm /111 \
|
||||||
- name: Run the file check
|
-print0)
|
||||||
id: check
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
statuscode=0
|
|
||||||
|
|
||||||
if [[ -n "${{ inputs.check_together }}" ]]; then
|
if [[ -n "${{ inputs.check_together }}" ]]; then
|
||||||
"${{ github.action_path }}/shellcheck" \
|
"${{ github.action_path }}/shellcheck" \
|
||||||
${{ steps.options.outputs.options }} \
|
|
||||||
${{ steps.filepaths.outputs.filepaths }} || statuscode=$?
|
|
||||||
else
|
|
||||||
for file in ${{ steps.filepaths.outputs.filepaths }}; do
|
|
||||||
echo "::debug::Checking $file"
|
|
||||||
"${{ github.action_path }}/shellcheck" \
|
|
||||||
${{ steps.options.outputs.options }} \
|
${{ steps.options.outputs.options }} \
|
||||||
"$file" || statuscode=$?;
|
"${filepaths[@]}" || statuscode=$?
|
||||||
|
else
|
||||||
|
for file in "${filepaths[@]}"; do
|
||||||
|
echo "::debug::Checking '$file'"
|
||||||
|
"${{ github.action_path }}/shellcheck" \
|
||||||
|
${{ steps.options.outputs.options }} \
|
||||||
|
"$file" || statuscode=$?
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "::set-output name=filepaths::${filepaths[@]}"
|
||||||
echo "::set-output name=statuscode::$statuscode"
|
echo "::set-output name=statuscode::$statuscode"
|
||||||
|
|
||||||
- name: Print information
|
- name: Print information
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
echo "Files: ${{steps.filepaths.outputs.filepaths}}"
|
echo "Files: ${{ steps.check.outputs.filepaths }}"
|
||||||
echo "Excluded: ${{ steps.exclude.outputs.excludes }}"
|
echo "Excluded: ${{ steps.exclude.outputs.excludes }}"
|
||||||
echo "Options: ${{ steps.options.outputs.options }}"
|
echo "Options: ${{ steps.options.outputs.options }}"
|
||||||
echo "Status code: ${{steps.check.outputs.statuscode}}"
|
echo "Status code: ${{ steps.check.outputs.statuscode }}"
|
||||||
|
|
||||||
exit ${{steps.check.outputs.statuscode}}
|
exit ${{steps.check.outputs.statuscode}}
|
||||||
|
|
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…
Reference in a new issue