Skip to content

Commit 0730d8c

Browse files
doc-sheetdsBYK
authored
add shellcheck action to lint bash scripts (#3710)
* add shellcheck action to lint bash scripts * fix some shellcheck warnings --------- Co-authored-by: ds <ds@local> Co-authored-by: Burak Yigit Kaya <[email protected]>
1 parent 2f2bb9c commit 0730d8c

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

.github/workflows/shellcheck.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
name: "ShellCheck"
3+
on:
4+
push:
5+
paths:
6+
- "**.sh"
7+
branches: [master]
8+
pull_request:
9+
paths:
10+
- "**.sh"
11+
branches: [master]
12+
13+
jobs:
14+
shellcheck:
15+
name: ShellCheck
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Repository checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Run ShellCheck
24+
run: |
25+
git diff --name-only -z `git merge-base origin/master HEAD` -- \
26+
'install/_lib.sh' \
27+
| xargs -0 -r -- \
28+
shellcheck \
29+
--shell=bash \
30+
--exclude=SC1090,SC1091 \
31+
--format=json1 \
32+
| jq -r '
33+
.comments
34+
| map(.level |= if ([.] | inside(["info", "style"])) then "notice" else . end)
35+
| .[] as $note
36+
| "::\($note.level) file=\($note.file),line=\($note.line),endLine=\($note.endLine),col=\($note.column),endColumn=\($note.endColumn)::[SC\($note.code)] \($note.message)"
37+
' \
38+
| grep . >&2 && exit 1
39+
40+
exit 0

install/_lib.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function ensure_file_from_example {
3333
echo "$target already exists, skipped creation."
3434
else
3535
# sed from https://stackoverflow.com/a/25123013/90297
36+
# shellcheck disable=SC2001
3637
example="$(echo "$target" | sed 's/\.[^.]*$/.example&/')"
3738
if [[ ! -f "$example" ]]; then
3839
echo "Oops! Where did $example go? 🤨 We need it in order to create $target."
@@ -45,14 +46,14 @@ function ensure_file_from_example {
4546

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

51-
SENTRY_CONFIG_PY=sentry/sentry.conf.py
52-
SENTRY_CONFIG_YML=sentry/config.yml
52+
export SENTRY_CONFIG_PY=sentry/sentry.conf.py
53+
export SENTRY_CONFIG_YML=sentry/config.yml
5354

5455
# Increase the default 10 second SIGTERM timeout
5556
# to ensure celery queues are properly drained
5657
# between upgrades as task signatures may change across
5758
# versions
58-
STOP_TIMEOUT=60 # seconds
59+
export STOP_TIMEOUT=60 # seconds

0 commit comments

Comments
 (0)