Skip to content

add shellcheck action to lint bash scripts #3710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: "ShellCheck"
on:
push:
paths:
- "**.sh"
branches: [master]
pull_request:
paths:
- "**.sh"
branches: [master]

jobs:
shellcheck:
name: ShellCheck
runs-on: ubuntu-latest
steps:
- name: Repository checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run ShellCheck
run: |
git diff --name-only -z `git merge-base origin/master HEAD` -- \
'install/_lib.sh' \
| xargs -0 -r -- \
shellcheck \
--shell=bash \
--exclude=SC1090,SC1091 \
--format=json1 \
| jq -r '
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the necessity of piping output of shellcheck to jq?

Copy link
Contributor Author

@doc-sheet doc-sheet May 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to replace some keys like column and values like info and style with github action command.
col and notice in this case.

And to format shellcheck's json as one-line command like ::error file=file.sh,col=123::message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the trick with grep is just to negate exit code :)

.comments
| map(.level |= if ([.] | inside(["info", "style"])) then "notice" else . end)
| .[] as $note
| "::\($note.level) file=\($note.file),line=\($note.line),endLine=\($note.endLine),col=\($note.column),endColumn=\($note.endColumn)::[SC\($note.code)] \($note.message)"
' \
| grep . >&2 && exit 1

exit 0
9 changes: 5 additions & 4 deletions install/_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function ensure_file_from_example {
echo "$target already exists, skipped creation."
else
# sed from https://stackoverflow.com/a/25123013/90297
# shellcheck disable=SC2001
example="$(echo "$target" | sed 's/\.[^.]*$/.example&/')"
if [[ ! -f "$example" ]]; then
echo "Oops! Where did $example go? 🤨 We need it in order to create $target."
Expand All @@ -45,14 +46,14 @@ function ensure_file_from_example {

# Check the version of $1 is greater than or equal to $2 using sort. Note: versions must be stripped of "v"
function vergte() {
printf "%s\n%s" $1 $2 | sort --version-sort --check=quiet --reverse
printf "%s\n%s" "$1" "$2" | sort --version-sort --check=quiet --reverse
}

SENTRY_CONFIG_PY=sentry/sentry.conf.py
SENTRY_CONFIG_YML=sentry/config.yml
export SENTRY_CONFIG_PY=sentry/sentry.conf.py
export SENTRY_CONFIG_YML=sentry/config.yml

# Increase the default 10 second SIGTERM timeout
# to ensure celery queues are properly drained
# between upgrades as task signatures may change across
# versions
STOP_TIMEOUT=60 # seconds
export STOP_TIMEOUT=60 # seconds
Loading