CI: add another Shell linter - Differential-ShellCheck (#372)

* ci(lint): Add differential-shellcheck action

It performs differential ShellCheck scans and report results directly in
pull request.

documentation: https://github.com/redhat-plumbers-in-action/differential-shellcheck

Signed-off-by: Jan Macku <jamacku@redhat.com>
Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
Co-authored-by: Luca Di Maio <luca.dimaio1@gmail.com>
This commit is contained in:
Jan Macku
2022-09-01 18:22:06 +02:00
committed by GitHub
co-authored by Luca Di Maio
parent c8436c3df3
commit 4027617a55
2 changed files with 43 additions and 2 deletions
+23 -2
View File
@@ -67,15 +67,36 @@ jobs:
run: |
result=0
podman pull docker.io/koalaman/shellcheck:stable
for file in $(find . -type f -not -path "*.git*"); do
for file in $(find . -type f -name ".*" -prune -o -print | grep -v '.git'); do
if file "$file" | grep -qi shell; then
echo "### Checking file $file..."
podman run --rm -v "$PWD:/mnt" docker.io/koalaman/shellcheck:stable -s sh -a -o all -Sstyle -Calways -x -e SC2310,SC2311,SC2312 $file
# Should read the .shellcheckrc file to behave like -s sh -a -o all -Sstyle -Calways -x -e SC2310,SC2311,SC2312
podman run --rm -v "$PWD:/mnt" docker.io/koalaman/shellcheck:stable -a -Sstyle -Calways $file
result=$(( result + $? ))
fi
done
exit $result
differential-shellcheck:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
pull-requests: write
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run Differential ShellCheck
uses: redhat-plumbers-in-action/differential-shellcheck@v3
with:
severity: style
token: ${{ secrets.GITHUB_TOKEN }}
bashate:
runs-on: ubuntu-latest
+20
View File
@@ -0,0 +1,20 @@
# Overrides the shell detected from the shebang. This is useful for files meant to be included (and thus lacking a shebang), or possibly as a more targeted alternative to 'disable=SC2039'.
shell=sh
# Always allow ShellCheck to open arbitrary files from 'source' statements.
external-sources=true
# Enable all optional checks
enable=all
# This function is invoked in an 'if' condition so set -e will be disabled. Invoke separately if failures should cause the script to exit.
# - We don't want to exit if errors happen inside a check, that's why we have a check...
disable=SC2310
# Bash implicitly disabled set -e for this function invocation because it's inside a command substitution. Add set -e; before it or enable inherit_errexit.
# - Don't care if we inherit errexit inside substitutions, we do checks for that.
disable=SC2311
# Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
# - We already check errors and adding "|| true" everywhere hinders readability.
disable=SC2312