Skip to content

Commit c4b78b6

Browse files
Merge pull request #745 from sebrandon1/add-shellcheck-gha
Add ShellCheck GitHub Actions workflow
2 parents cf08731 + 8cb71c8 commit c4b78b6

5 files changed

Lines changed: 100 additions & 2 deletions

File tree

.github/workflows/shellcheck.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
22+
with:
23+
persist-credentials: false
24+
25+
- name: Run ShellCheck
26+
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!"; \
@@ -108,6 +115,10 @@ ocp-doc-check: ## Download and run ocp-doc-checker against markdown files
108115
test-kustomize: ## Validate all kustomization.yaml files can build
109116
./hack/test-kustomize.sh
110117

118+
.PHONY: test-shellcheck
119+
test-shellcheck: ## Validate shell scripts with shellcheck
120+
./hack/test-shellcheck.sh
121+
111122
ci-validate: lintCheck check-reference-core check-reference-ran check-reference-hub
112123

113124
.PHONY: check-reference-core

hack/test-shellcheck.sh

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