Skip to content
Merged
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
26 changes: 26 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: ShellCheck

on:
pull_request:
branches:
- main
paths:
- "**/*.sh"
- "Makefile"

permissions:
contents: read

jobs:
shellcheck:
name: Validate Shell Scripts
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false

- name: Run ShellCheck
run: make test-shellcheck
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ check-deps:
echo "✗ Missing (install from: https://go.dev/dl/)"; \
MISSING=$$((MISSING+1)); \
fi; \
echo -n "Checking shellcheck... "; \
if command -v shellcheck >/dev/null 2>&1; then \
echo "✓ Found: $$(shellcheck --version 2>&1 | grep version: | head -1)"; \
else \
echo "✗ Missing (install: brew install shellcheck or apt-get install shellcheck)"; \
MISSING=$$((MISSING+1)); \
fi; \
echo ""; \
if [ $$MISSING -eq 0 ]; then \
echo "✅ All dependencies are installed!"; \
Expand Down Expand Up @@ -116,6 +123,10 @@ ocp-doc-check: ## Download and run ocp-doc-checker against markdown files
test-kustomize: ## Validate all kustomization.yaml files can build
./hack/test-kustomize.sh

.PHONY: test-shellcheck
test-shellcheck: ## Validate shell scripts with shellcheck
./hack/test-shellcheck.sh

ci-validate: lintCheck check-reference-core check-reference-ran check-reference-hub

.PHONY: check-reference-core
Expand Down
61 changes: 61 additions & 0 deletions hack/test-shellcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

set -e

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

if ! command -v shellcheck &> /dev/null; then
echo -e "${RED}ERROR: shellcheck is not installed${NC}"
echo ""
echo "Please install shellcheck to run this check:"
echo " - macOS: brew install shellcheck"
echo " - Fedora/RHEL: dnf install ShellCheck"
echo " - Ubuntu/Debian: apt-get install shellcheck"
echo " - Manual: https://github.com/koalaman/shellcheck#installing"
echo ""
exit 1
fi

echo "Running ShellCheck on all shell scripts..."
echo ""

ERRORS=0
CHECKED=0

shell_files=()
while IFS= read -r file; do
shell_files+=("$file")
done < <(find . -name '*.sh' -not -path './.git/*' -not -path './venv/*' -not -path '*/.venv/*' -not -path './sdk-go/*' | sort)

if [ ${#shell_files[@]} -eq 0 ]; then
echo -e "${YELLOW}WARNING: No shell scripts found${NC}"
exit 0
fi

for script in "${shell_files[@]}"; do
echo -n " $script: "
CHECKED=$((CHECKED + 1))
output=$(shellcheck --severity=error "$script" 2>&1)
if [ $? -eq 0 ]; then
echo -e "${GREEN}OK${NC}"
else
echo -e "${RED}FAILED${NC}"
echo "$output" | sed 's/^/ /'
echo ""
ERRORS=$((ERRORS + 1))
fi
done

echo ""
echo "Summary: Checked $CHECKED shell scripts"

if [[ $ERRORS -eq 0 ]]; then
echo -e "${GREEN}All shell scripts passed ShellCheck!${NC}"
exit 0
else
echo -e "${RED}$ERRORS script(s) failed ShellCheck${NC}"
exit 1
fi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

fatal() {
echo "FATAL: $@"
echo "FATAL: $*"
exit 1
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

fatal() {
echo "FATAL: $@"
echo "FATAL: $*"
exit 1
}

Expand Down
Loading