Skip to content

Commit 49f17fd

Browse files
committed
Add ShellCheck GitHub Actions workflow with local make target
- Add hack/test-shellcheck.sh wrapper script following the same pattern as hack/test-kustomize.sh for local developer use - Add test-shellcheck Makefile target that invokes the wrapper script - Add shellcheck to check-deps dependency verification - GHA workflow delegates to make test-shellcheck instead of inline commands - Fix SC2145 shellcheck errors in extra-manifests-builder test scripts
1 parent 8b0e015 commit 49f17fd

5 files changed

Lines changed: 94 additions & 2 deletions

File tree

.github/workflows/shellcheck.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: ShellCheck
3+
4+
on:
5+
pull_request:
6+
branches:
7+
- main
8+
paths:
9+
- "**/*.sh"
10+
- "Makefile"
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
shellcheck:
17+
name: Validate Shell Scripts
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Validate Shell Scripts
24+
run: make test-shellcheck

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ check-deps:
4444
echo "✗ Missing (install from: https://go.dev/dl/)"; \
4545
MISSING=$$((MISSING+1)); \
4646
fi; \
47+
echo -n "Checking shellcheck... "; \
48+
if command -v shellcheck >/dev/null 2>&1; then \
49+
echo "✓ Found: $$(shellcheck --version 2>&1 | grep version: | head -1)"; \
50+
else \
51+
echo "✗ Missing (install: brew install shellcheck or apt-get install shellcheck)"; \
52+
MISSING=$$((MISSING+1)); \
53+
fi; \
4754
echo ""; \
4855
if [ $$MISSING -eq 0 ]; then \
4956
echo "✅ All dependencies are installed!"; \
@@ -116,6 +123,10 @@ ocp-doc-check: ## Download and run ocp-doc-checker against markdown files
116123
test-kustomize: ## Validate all kustomization.yaml files can build
117124
./hack/test-kustomize.sh
118125

126+
.PHONY: test-shellcheck
127+
test-shellcheck: ## Validate shell scripts with shellcheck
128+
./hack/test-shellcheck.sh
129+
119130
ci-validate: lintCheck check-reference-core check-reference-ran check-reference-hub
120131

121132
.PHONY: check-reference-core

hack/test-shellcheck.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
RED='\033[0;31m'
6+
GREEN='\033[0;32m'
7+
NC='\033[0m' # No Color
8+
9+
if ! command -v shellcheck &> /dev/null; then
10+
echo -e "${RED}ERROR: shellcheck is not installed${NC}"
11+
echo ""
12+
echo "Please install shellcheck to run this check:"
13+
echo " - macOS: brew install shellcheck"
14+
echo " - Fedora/RHEL: dnf install ShellCheck"
15+
echo " - Ubuntu/Debian: apt-get install shellcheck"
16+
echo " - Manual: https://github.com/koalaman/shellcheck#installing"
17+
echo ""
18+
exit 1
19+
fi
20+
21+
echo "Running ShellCheck on all shell scripts..."
22+
echo ""
23+
24+
ERRORS=0
25+
CHECKED=0
26+
27+
shell_files=()
28+
while IFS= read -r file; do
29+
shell_files+=("$file")
30+
done < <(find . -name '*.sh' -not -path './.git/*' -not -path './venv/*' -not -path '*/.venv/*' -not -path './sdk-go/*' | sort)
31+
32+
if [ ${#shell_files[@]} -eq 0 ]; then
33+
echo "No shell scripts found"
34+
exit 0
35+
fi
36+
37+
for script in "${shell_files[@]}"; do
38+
echo -n " $script: "
39+
CHECKED=$((CHECKED + 1))
40+
if shellcheck --severity=error "$script" 2>&1; then
41+
echo -e "${GREEN}OK${NC}"
42+
else
43+
echo -e "${RED}FAILED${NC}"
44+
ERRORS=$((ERRORS + 1))
45+
fi
46+
done
47+
48+
echo ""
49+
echo "Summary: Checked $CHECKED shell scripts"
50+
51+
if [[ $ERRORS -eq 0 ]]; then
52+
echo -e "${GREEN}All shell scripts passed ShellCheck!${NC}"
53+
exit 0
54+
else
55+
echo -e "${RED}$ERRORS script(s) failed ShellCheck${NC}"
56+
exit 1
57+
fi

telco-ran/configuration/extra-manifests-builder/01-container-mount-ns-and-kubelet-conf/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
fatal() {
4-
echo "FATAL: $@"
4+
echo "FATAL: $*"
55
exit 1
66
}
77

telco-ran/configuration/extra-manifests-builder/08-set-rcu-normal/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
fatal() {
4-
echo "FATAL: $@"
4+
echo "FATAL: $*"
55
exit 1
66
}
77

0 commit comments

Comments
 (0)