Skip to content

Commit 9bf4946

Browse files
janiszclaude
andauthored
ci: lint scripts and workflows (#48)
Signed-off-by: Tomasz Janiszewski <tomek@redhat.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent c3ceac6 commit 9bf4946

20 files changed

+228
-140
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ jobs:
6767
6868
- name: Generate build summary
6969
run: |
70-
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
71-
echo "" >> $GITHUB_STEP_SUMMARY
72-
echo "**Registry**: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY
73-
echo "" >> $GITHUB_STEP_SUMMARY
74-
echo "**Tags**:" >> $GITHUB_STEP_SUMMARY
75-
echo '```' >> $GITHUB_STEP_SUMMARY
76-
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
77-
echo '```' >> $GITHUB_STEP_SUMMARY
78-
echo "" >> $GITHUB_STEP_SUMMARY
79-
echo "**Platforms**: linux/amd64, linux/arm64, linux/ppc64le, linux/s390x" >> $GITHUB_STEP_SUMMARY
70+
{
71+
echo "## Build Summary"
72+
echo ""
73+
echo "**Registry**: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
74+
echo ""
75+
echo "**Tags**:"
76+
echo '```'
77+
echo "${{ steps.meta.outputs.tags }}"
78+
echo '```'
79+
echo ""
80+
echo "**Platforms**: linux/amd64, linux/arm64, linux/ppc64le, linux/s390x"
81+
} >> "$GITHUB_STEP_SUMMARY"

.github/workflows/e2e.yml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,31 @@ jobs:
5353
cd e2e-tests/mcpchecker
5454
5555
# Get stats in GitHub Actions format
56-
../../e2e-tests/bin/mcpchecker summary mcpchecker-stackrox-mcp-e2e-out.json --github-output >> $GITHUB_OUTPUT
56+
../../e2e-tests/bin/mcpchecker summary mcpchecker-stackrox-mcp-e2e-out.json --github-output >> "$GITHUB_OUTPUT"
5757
5858
# Get human-readable summary for PR comment
5959
SUMMARY=$(../../e2e-tests/bin/mcpchecker summary mcpchecker-stackrox-mcp-e2e-out.json)
60-
echo "summary<<EOF" >> $GITHUB_OUTPUT
61-
echo "$SUMMARY" >> $GITHUB_OUTPUT
62-
echo "EOF" >> $GITHUB_OUTPUT
60+
{
61+
echo "summary<<EOF"
62+
echo "$SUMMARY"
63+
echo "EOF"
64+
} >> "$GITHUB_OUTPUT"
6365
6466
# Add to GitHub Actions step summary
65-
echo "## E2E Test Results" >> $GITHUB_STEP_SUMMARY
66-
echo "" >> $GITHUB_STEP_SUMMARY
67-
echo '```' >> $GITHUB_STEP_SUMMARY
68-
echo "$SUMMARY" >> $GITHUB_STEP_SUMMARY
69-
echo '```' >> $GITHUB_STEP_SUMMARY
67+
{
68+
echo "## E2E Test Results"
69+
echo ""
70+
echo '```'
71+
echo "$SUMMARY"
72+
echo '```'
73+
} >> "$GITHUB_STEP_SUMMARY"
7074
else
71-
echo "total=0" >> $GITHUB_OUTPUT
72-
echo "passed=0" >> $GITHUB_OUTPUT
73-
echo "failed=0" >> $GITHUB_OUTPUT
74-
echo "summary=No results file found" >> $GITHUB_OUTPUT
75+
{
76+
echo "total=0"
77+
echo "passed=0"
78+
echo "failed=0"
79+
echo "summary=No results file found"
80+
} >> "$GITHUB_OUTPUT"
7581
fi
7682
7783
- name: Find existing comment

.github/workflows/style.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@ jobs:
6666

6767
- name: Run chart-testing (lint)
6868
run: ct lint charts/stackrox-mcp --validate-maintainers=false --all
69+
70+
- name: Run shellcheck
71+
run: make shell-lint
72+
73+
- name: Run actionlint
74+
run: make actionlint

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
if [ -n "$(git status --porcelain)" ]; then
3434
echo "Error: go.mod or go.sum files are not up to date"
3535
echo "Modified files:"
36-
git status --porcelain
36+
git diff
3737
echo ""
3838
echo "Please run 'go mod tidy' in all directories containing go.mod and commit the changes"
3939
exit 1
@@ -53,6 +53,6 @@ jobs:
5353
- name: Upload coverage to Codecov
5454
uses: codecov/codecov-action@v5
5555
with:
56-
file: ./coverage.out
56+
files: ./coverage.out
5757
token: ${{ secrets.CODECOV_TOKEN }}
5858
fail_ci_if_error: false

.shellcheckrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Follow external sources (equivalent to -x flag)
2+
external-sources=true
3+
4+
# Enable all optional checks
5+
enable=all
6+
7+
# Exclude checks that are too noisy
8+
# SC2312: Consider invoking this command separately to avoid masking its return value
9+
exclude=SC2312

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ lint: ## Run golangci-lint
9191
go install -v "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6"
9292
golangci-lint run
9393

94+
.PHONY: shell-lint
95+
shell-lint: ## Run shellcheck on shell scripts
96+
@echo "Running shellcheck..."
97+
@shellcheck scripts/*.sh e2e-tests/scripts/*.sh
98+
99+
.PHONY: actionlint
100+
actionlint: ## Run actionlint on GitHub Actions workflows
101+
@echo "Running actionlint..."
102+
@cd e2e-tests/tools && go build -o ../../bin/actionlint github.com/rhysd/actionlint/cmd/actionlint
103+
@./bin/actionlint -color
104+
94105
##############
95106
## Protobuf ##
96107
##############

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,23 @@ Common commands:
409409
- `make test` - Run tests
410410
- `make fmt` - Format code
411411
- `make lint` - Run linter
412+
413+
### Code Style Checks
414+
415+
The project enforces several code style checks:
416+
417+
- **Go formatting**: `make fmt-check` (or `make fmt` to auto-fix)
418+
- **Go linting**: `make lint`
419+
- **Shell scripts**: `make shell-lint`
420+
- **GitHub Actions workflows**: `make actionlint`
421+
- **Dockerfile**: `make dockerfile-lint`
422+
- **Helm charts**: `make helm-lint`
423+
424+
All checks run automatically in CI on pull requests.
425+
426+
#### Shell Script Guidelines
427+
428+
- All scripts must pass `shellcheck` with no errors
429+
- Use `set -e` for error handling
430+
- Use `SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"` for directory detection
431+
- Include cleanup traps for temporary resources (see existing scripts for examples)

e2e-tests/scripts/build-mcpchecker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ set -e
44
E2E_DIR="$(cd "$(dirname "$0")/.." && pwd)"
55

66
echo "Building mcpchecker from tool dependencies..."
7-
cd "$E2E_DIR/tools"
7+
cd "${E2E_DIR}/tools"
88
go build -o ../bin/mcpchecker github.com/mcpchecker/mcpchecker/cmd/mcpchecker
99

1010
echo "mcpchecker built successfully"
11-
cd "$E2E_DIR"
11+
cd "${E2E_DIR}"
1212
./bin/mcpchecker help

e2e-tests/scripts/run-tests.sh

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
set -e
33

44
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5-
E2E_DIR="$(dirname "$SCRIPT_DIR")"
6-
ROOT_DIR="$(dirname "$E2E_DIR")"
5+
E2E_DIR="$(dirname "${SCRIPT_DIR}")"
6+
ROOT_DIR="$(dirname "${E2E_DIR}")"
77

88
# Cleanup function
99
WIREMOCK_WAS_STARTED=false
1010
cleanup() {
11-
if [ "$WIREMOCK_WAS_STARTED" = true ]; then
11+
if [[ "${WIREMOCK_WAS_STARTED}" = true ]]; then
1212
echo "Stopping WireMock..."
13-
cd "$ROOT_DIR"
13+
cd "${ROOT_DIR}"
1414
make mock-stop > /dev/null 2>&1 || true
1515
fi
1616
}
@@ -23,16 +23,16 @@ echo "════════════════════════
2323
echo ""
2424

2525
# Load environment variables
26-
if [ -f "$E2E_DIR/.env" ]; then
26+
if [[ -f "${E2E_DIR}/.env" ]]; then
2727
echo "Loading environment variables from .env..."
2828
# shellcheck source=/dev/null
29-
set -a && source "$E2E_DIR/.env" && set +a
29+
set -a && source "${E2E_DIR}/.env" && set +a
3030
fi
3131

3232
# Check if WireMock is already running
3333
if ! curl -skf https://localhost:8081/__admin/mappings > /dev/null 2>&1; then
3434
echo "Starting WireMock mock service..."
35-
cd "$ROOT_DIR"
35+
cd "${ROOT_DIR}"
3636
make mock-start
3737
WIREMOCK_WAS_STARTED=true
3838
else
@@ -45,55 +45,55 @@ export STACKROX_MCP__CENTRAL__API_TOKEN="test-token-admin"
4545
export STACKROX_MCP__CENTRAL__INSECURE_SKIP_TLS_VERIFY="true"
4646

4747
# Check OpenAI API key for judge
48-
if [ -z "$OPENAI_API_KEY" ]; then
48+
if [[ -z "${OPENAI_API_KEY}" ]]; then
4949
echo "Warning: OPENAI_API_KEY is not set (needed for LLM judge)"
5050
echo "Note: mcpchecker only supports OpenAI-compatible APIs for the judge"
5151
fi
5252

5353
# Build mcpchecker if not present
54-
if [ ! -f "$E2E_DIR/bin/mcpchecker" ]; then
54+
if [[ ! -f "${E2E_DIR}/bin/mcpchecker" ]]; then
5555
echo "mcpchecker binary not found. Building..."
56-
"$SCRIPT_DIR/build-mcpchecker.sh"
56+
"${SCRIPT_DIR}/build-mcpchecker.sh"
5757
echo ""
5858
fi
5959

6060

6161
# Set agent environment variables (use OpenAI)
6262
export MODEL_BASE_URL="${MODEL_BASE_URL:-https://api.openai.com/v1}"
63-
export MODEL_KEY="${MODEL_KEY:-$OPENAI_API_KEY}"
63+
export MODEL_KEY="${MODEL_KEY:-${OPENAI_API_KEY}}"
6464
export MODEL_NAME="${MODEL_NAME:-gpt-5-nano}"
6565

6666
# Set judge environment variables (use OpenAI)
6767
export JUDGE_BASE_URL="${JUDGE_BASE_URL:-https://api.openai.com/v1}"
68-
export JUDGE_API_KEY="${JUDGE_API_KEY:-$OPENAI_API_KEY}"
68+
export JUDGE_API_KEY="${JUDGE_API_KEY:-${OPENAI_API_KEY}}"
6969
export JUDGE_MODEL_NAME="${JUDGE_MODEL_NAME:-gpt-5-nano}"
7070

7171
echo "Configuration:"
72-
echo " Central URL: $STACKROX_MCP__CENTRAL__URL (WireMock)"
73-
echo " Agent: $MODEL_NAME (OpenAI)"
74-
echo " Judge: $JUDGE_MODEL_NAME (OpenAI)"
72+
echo " Central URL: ${STACKROX_MCP__CENTRAL__URL} (WireMock)"
73+
echo " Agent: ${MODEL_NAME} (OpenAI)"
74+
echo " Judge: ${JUDGE_MODEL_NAME} (OpenAI)"
7575
echo " MCP Server: stackrox-mcp (via go run)"
7676
echo ""
7777

7878
# Run mcpchecker
79-
cd "$E2E_DIR/mcpchecker"
79+
cd "${E2E_DIR}/mcpchecker"
8080
echo "Running mcpchecker tests..."
8181
echo ""
8282

8383
EVAL_FILE="eval.yaml"
84-
echo "Using eval file: $EVAL_FILE"
85-
"$E2E_DIR/bin/mcpchecker" check "$EVAL_FILE"
84+
echo "Using eval file: ${EVAL_FILE}"
85+
"${E2E_DIR}/bin/mcpchecker" check "${EVAL_FILE}"
8686

8787
EXIT_CODE=$?
8888

8989
echo ""
90-
if [ $EXIT_CODE -eq 0 ]; then
90+
if [[ "${EXIT_CODE}" -eq 0 ]]; then
9191
echo "══════════════════════════════════════════════════════════"
9292
echo " Tests Completed Successfully!"
9393
echo "══════════════════════════════════════════════════════════"
9494
else
9595
echo "══════════════════════════════════════════════════════════"
9696
echo " Tests Failed"
9797
echo "══════════════════════════════════════════════════════════"
98-
exit $EXIT_CODE
98+
exit "${EXIT_CODE}"
9999
fi

e2e-tests/scripts/smoke-test-mock.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
set -e
33

44
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5-
E2E_DIR="$(dirname "$SCRIPT_DIR")"
6-
ROOT_DIR="$(dirname "$E2E_DIR")"
5+
E2E_DIR="$(dirname "${SCRIPT_DIR}")"
6+
ROOT_DIR="$(dirname "${E2E_DIR}")"
77

88
echo "══════════════════════════════════════════════════════════"
99
echo " WireMock Integration Smoke Test"
@@ -12,14 +12,14 @@ echo ""
1212

1313
# Start WireMock
1414
echo "1. Starting WireMock..."
15-
cd "$ROOT_DIR"
15+
cd "${ROOT_DIR}"
1616
make mock-stop > /dev/null 2>&1 || true
1717
make mock-start
1818

1919
# Wait for WireMock to be ready
2020
echo ""
2121
echo "2. Waiting for WireMock to be ready..."
22-
for i in {1..10}; do
22+
for _ in {1..10}; do
2323
if nc -z localhost 8081 2>/dev/null; then
2424
echo "✓ WireMock is ready"
2525
break
@@ -30,7 +30,7 @@ done
3030
# Test MCP server can connect
3131
echo ""
3232
echo "3. Testing MCP server connection..."
33-
cd "$ROOT_DIR"
33+
cd "${ROOT_DIR}"
3434

3535
# Run MCP server and test a simple tool call
3636
timeout 10 bash -c '
@@ -50,29 +50,29 @@ echo "4. Testing WireMock responses..."
5050
AUTH_RESULT=$(grpcurl -insecure -H "Authorization: Bearer test-token-admin" \
5151
-d '{}' localhost:8081 v1.ClustersService/GetClusters 2>&1 || true)
5252

53-
if echo "$AUTH_RESULT" | grep -q "clusters"; then
53+
if echo "${AUTH_RESULT}" | grep -q "clusters"; then
5454
echo "✓ Authentication works"
5555
else
5656
echo "✗ Authentication failed"
57-
echo "$AUTH_RESULT"
57+
echo "${AUTH_RESULT}"
5858
fi
5959

6060
# Test CVE query
6161
CVE_RESULT=$(grpcurl -insecure -H "Authorization: Bearer test-token-admin" \
6262
-d '{"query": "CVE:\"CVE-2021-44228\""}' \
6363
localhost:8081 v1.DeploymentService/ListDeployments 2>&1 || true)
6464

65-
if echo "$CVE_RESULT" | grep -q "deployments"; then
65+
if echo "${CVE_RESULT}" | grep -q "deployments"; then
6666
echo "✓ CVE query returns data"
6767
else
6868
echo "✗ CVE query failed"
69-
echo "$CVE_RESULT"
69+
echo "${CVE_RESULT}"
7070
fi
7171

7272
# Cleanup
7373
echo ""
7474
echo "5. Cleaning up..."
75-
cd "$ROOT_DIR"
75+
cd "${ROOT_DIR}"
7676
make mock-stop
7777

7878
echo ""

0 commit comments

Comments
 (0)