Skip to content

Commit 4f4111f

Browse files
committed
infra/linters: Add shellcheck
Add shellcheck linter both as an action and as a Makefile rule. Fail on severity greater than 'warning' to avoid refactoring current scripts. Signed-off-by: Alex Apostolescu <[email protected]>
1 parent 339cb01 commit 4f4111f

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

.github/workflows/actions.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,16 @@ jobs:
108108
with:
109109
options: "--check --diff"
110110
src: ${{ env.FILES }}
111+
112+
shellcheck: # Runs on all shell scripts in the repository.
113+
runs-on: ubuntu-latest
114+
steps:
115+
- uses: actions/checkout@v4
116+
with:
117+
fetch-depth: 0
118+
119+
- name: shellcheck
120+
uses: ludeeus/[email protected]
121+
with:
122+
version: v0.10.0
123+
severity: "warning"

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ clean: stop_bash
4040
cleanall: clean
4141
-docker inspect --type=image $(IMAGE_NAME) > /dev/null 2>&1 && docker image rm $(IMAGE_NAME)
4242

43-
.PHONY: lint markdownlint cpplint black
44-
lint: markdownlint cpplint black
43+
.PHONY: lint markdownlint cpplint black shellcheck
44+
lint: markdownlint cpplint black shellcheck
4545

4646
CHANGED_MD_FILES = $(call get_changed_files,\.md$$)
4747
markdownlint:
@@ -68,6 +68,14 @@ black:
6868
black --check --diff $(CHANGED_PY_FILES); \
6969
fi
7070

71+
CHANGED_SHELL_FILES = $(call get_changed_files,\.\(sh\|bash\)$$)
72+
shellcheck:
73+
@echo "Checking shell scripts ..."
74+
@if [ "$(CHANGED_SHELL_FILES)" ]; then \
75+
docker run --rm -v $(PWD):/data --workdir=/data koalaman/shellcheck-alpine:v0.10.0 \
76+
shellcheck --severity=warning $(CHANGED_SHELL_FILES); \
77+
fi
78+
7179
# Get a list of files that changed in the current branch and match the given pattern
7280
define get_changed_files # $(1): pattern
7381
$(shell git diff --name-only HEAD $(shell git merge-base HEAD main) | grep "$(1)" | tr '\n' ' ')

content/assignments/lambda-function-loader/tests/checker.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,10 @@ main() {
501501
run_tests "$@"
502502

503503
if [[ $# -eq 0 ]]; then
504-
PADDING=$(printf '.%.0s' $(eval echo "{1..$((PADDING_LEN+6))}"))
504+
PADDING=""
505+
for ((i=0; i<((PADDING_LEN+6)); i++)); do
506+
PADDING+="."
507+
done
505508
printf "Total Score%s[%+3s/%-3s]\n" "$PADDING" $TOTAL_SCORE $MAX_TOTAL_SCORE
506509
fi
507510
}

0 commit comments

Comments
 (0)