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

Add exclude and testfiles

This commit is contained in:
ludeeus 2020-05-30 11:44:01 +02:00
parent c07d062aa5
commit 18c29dd450
9 changed files with 52 additions and 19 deletions

1
.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
* text=auto eol=lf

View file

@ -6,5 +6,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Shellcheck
uses: ludeeus/action-shellcheck@master
- name: Run Shellcheck
uses: ${GITHUB_REPOSITORY}@${GITHUB_SHA}
with:
ignore: "ignore"

View file

@ -3,12 +3,4 @@ FROM alpine:3.11.6
RUN apk add --no-cache shellcheck bash
COPY runaction.sh /action/runaction.sh
ENTRYPOINT ["bash", "/action/runaction.sh"]
LABEL "name"="ShellCheck"
LABEL "maintainer"="Ludeeus <hi@ludeeus.dev>"
LABEL "version"="0.1.0"
LABEL "com.github.actions.name"="ShellCheck"
LABEL "com.github.actions.description"="GitHub action for ShellCheck."
LABEL "com.github.actions.icon"="terminal"
LABEL "com.github.actions.color"="black"
ENTRYPOINT ["bash", "/action/runaction.sh"]

14
action.yaml Normal file
View file

@ -0,0 +1,14 @@
name: "ShellCheck"
author: "Ludeeus <hi@ludeeus.dev>"
description: "GitHub action for ShellCheck."
inputs:
ignore:
description: 'Paths to ignore when running ShellCheck'
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
branding:
icon: 'terminal'
color: 'gray-dark'

View file

@ -2,13 +2,23 @@
cd "$GITHUB_WORKSPACE" || exit 1
declare err
declare statuscode
declare -a filepaths
declare -a excludes
declare -a tmp
err=0
statuscode=0
readarray -d '' filepaths < <(find . '(' \
excludes+=( ! -path *./.git/* )
for path in ${INPUT_IGNORE}; do
[[ ${path#./*} != "$path" ]] || path=./${path}
echo "::debug:: Adding '${path}' to excludes"
excludes+=(! -path *"${path}"* )
done
readarray -d '' filepaths < <(find . "${excludes[@]}" \
'(' \
\
-name '*.bash' \
-o -path '*/.bash*' \
@ -37,19 +47,19 @@ readarray -d '' filepaths < <(find . '(' \
-print0)
readarray -d '' tmp < <(find . -type f ! -name '*.*' -perm /111 -print0)
readarray -d '' tmp < <(find . "${excludes[@]}" -type f ! -name '*.*' -perm /111 -print0)
for file in "${tmp[@]}"; do
head -n1 "$file" | grep -Eqs "^#! */[^ ]*/[abkz]*sh" || continue
filepaths+=("$file")
done
if find . -path '*bin/*/*' -type f -perm /111 -print |
if find . "${excludes[@]}" -path '*bin/*/*' -type f -perm /111 -print |
grep .
then
echo >&2 "::warning:: subdirectories of bin directories are not usable via PATH"
fi
if find . -path '*bin/*' -name '*.*' -type f -perm /111 -perm /444 -print |
if find . "${excludes[@]}" -path '*bin/*' -name '*.*' -type f -perm /111 -perm /444 -print |
grep .
then
echo >&2 "::warning:: programs in PATH should not have a filename suffix"
@ -57,7 +67,7 @@ fi
for file in "${filepaths[@]}"; do
echo "::debug:: Checking $file"
shellcheck "$file" || err=$?
shellcheck "$file" || statuscode=$?
done
exit "$err"
exit "$statuscode"

View file

@ -0,0 +1,3 @@
#!/bin/sh
echo $test

4
testfiles/test Normal file
View file

@ -0,0 +1,4 @@
#!/bin/bash
test="test"
echo "$test"

3
testfiles/test.bash Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
test="test"
echo "$test"

4
testfiles/test.sh Normal file
View file

@ -0,0 +1,4 @@
#!/usr/bin/sh
test="test"
echo "$test"