-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlint-parallel.sh
More file actions
executable file
·155 lines (123 loc) · 3.68 KB
/
lint-parallel.sh
File metadata and controls
executable file
·155 lines (123 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# Parallel Linting Script
#
# This script demonstrates running linters in parallel by calling the linter binary
# with individual file type arguments. Each linter runs in a separate process.
#
# Usage: ./scripts/lint-parallel.sh
#
# This approach provides parallel execution without modifying the linter binary,
# but has trade-offs:
#
# Pros:
# - No code changes required - uses existing CLI interface
# - Simple to implement and understand
# - Real parallel execution with performance gains
# - Easy to adjust grouping strategy
#
# Cons:
# - Output may be interleaved (mixed messages from different linters)
# - Multiple Rust compilation/startup overhead if binary not cached
# - Less control over output formatting
# - Harder to aggregate errors cleanly
set -e
echo "========================================"
echo "Running Linters in Parallel"
echo "========================================"
echo ""
# Build the linter binary once (release mode for better performance)
echo "Building linter binary..."
cargo build --release --bin linter --quiet
LINTER_BIN="./target/release/linter"
echo ""
# Track overall success/failure
FAILED=0
# Temporary directory for storing results
RESULT_DIR=$(mktemp -d)
trap 'rm -rf "$RESULT_DIR"' EXIT
# Function to run a linter and capture its exit code
run_linter() {
local linter_name=$1
local result_file="$RESULT_DIR/$linter_name.result"
echo "Starting $linter_name linter..."
if "$LINTER_BIN" "$linter_name" > "$result_file.log" 2>&1; then
echo "0" > "$result_file"
echo "✓ $linter_name completed successfully"
else
echo "1" > "$result_file"
echo "✗ $linter_name failed"
fi
}
# Start timing
START_TIME=$(date +%s)
# Group 1: Run linters in parallel (different file types - no conflicts)
echo "Group 1: Running linters in parallel (markdown, yaml, toml, shellcheck, rustfmt)..."
echo ""
run_linter "markdown" &
PID_MARKDOWN=$!
run_linter "yaml" &
PID_YAML=$!
run_linter "toml" &
PID_TOML=$!
run_linter "shellcheck" &
PID_SHELLCHECK=$!
run_linter "rustfmt" &
PID_RUSTFMT=$!
# Wait for Group 1 to complete
wait $PID_MARKDOWN $PID_YAML $PID_TOML $PID_SHELLCHECK $PID_RUSTFMT
echo ""
echo "Group 1 completed."
echo ""
# Group 2: Run clippy sequentially (may conflict with rustfmt on .rs files)
echo "Group 2: Running clippy (sequential)..."
echo ""
run_linter "clippy"
echo ""
echo "Group 2 completed."
echo ""
# Separate group: Run cspell (checks all files, read-only)
echo "Running cspell (read-only checker)..."
echo ""
run_linter "cspell"
echo ""
# Calculate elapsed time
END_TIME=$(date +%s)
ELAPSED=$((END_TIME - START_TIME))
# Display results
echo ""
echo "========================================"
echo "Linting Results"
echo "========================================"
echo ""
for linter in markdown yaml toml shellcheck rustfmt clippy cspell; do
result_file="$RESULT_DIR/$linter.result"
log_file="$RESULT_DIR/$linter.result.log"
if [ -f "$result_file" ]; then
exit_code=$(cat "$result_file")
if [ "$exit_code" -eq 0 ]; then
echo "✓ $linter: PASSED"
else
echo "✗ $linter: FAILED"
FAILED=1
# Show the error log
if [ -f "$log_file" ]; then
echo " Log:"
sed 's/^/ /' "$log_file"
fi
fi
fi
done
echo ""
echo "========================================"
echo "Total time: ${ELAPSED}s"
echo "========================================"
# Exit with error if any linter failed
if [ $FAILED -eq 1 ]; then
echo ""
echo "❌ Some linters failed. Please fix the issues above."
exit 1
else
echo ""
echo "✅ All linters passed!"
exit 0
fi