Skip to content

Commit 3bc8ea0

Browse files
justin808claude
andcommitted
Refactor precompile validation into reusable script
Extracted all pattern detection logic into script/validate-precompile-output so it can be: - Run locally: script/validate-precompile-output <output_file> - Piped: RAILS_ENV=production rake assets:precompile 2>&1 | script/validate-precompile-output - - Used by CI with GitHub Actions annotations The script supports both local and CI usage, automatically using GitHub Actions annotation format when GITHUB_ACTIONS env var is set. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 98a983f commit 3bc8ea0

File tree

2 files changed

+185
-129
lines changed

2 files changed

+185
-129
lines changed

.github/workflows/precompile-check.yml

Lines changed: 4 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ jobs:
132132
run: cd react_on_rails/spec/dummy && pnpm run build:rescript
133133
- name: Generate file system-based packs
134134
run: cd react_on_rails/spec/dummy && RAILS_ENV=production bundle exec rake react_on_rails:generate_packs
135-
- name: Run assets:precompile and check output
135+
- name: Run assets:precompile and capture output
136136
run: |
137137
cd react_on_rails/spec/dummy
138138
@@ -146,139 +146,14 @@ jobs:
146146
PRECOMPILE_EXIT=${PIPESTATUS[0]}
147147
148148
echo "=========================================="
149-
echo "Precompile finished. Checking output for known issues..."
150-
echo ""
151-
152-
# Check for known failure patterns
153-
FAILURES_FOUND=0
154149
155150
# Check if rake command itself failed
156151
if [ "$PRECOMPILE_EXIT" -ne 0 ]; then
157152
echo "::error::Precompile command failed with exit code $PRECOMPILE_EXIT"
158-
FAILURES_FOUND=1
159-
fi
160-
161-
# Pattern 1: Duplicate webpack compilation (indicates rake tasks running twice)
162-
# Look for webpack's "Compiled successfully" message which appears once per compilation
163-
if grep -q "Compiled successfully" precompile_output.txt; then
164-
COMPILE_SUCCESS_COUNT=$(grep -c "Compiled successfully" precompile_output.txt || true)
165-
if [ "$COMPILE_SUCCESS_COUNT" -gt 1 ]; then
166-
echo "::error::FAILURE: Detected $COMPILE_SUCCESS_COUNT webpack compilations (expected 1). Tasks may be running twice."
167-
echo " Matching lines:"
168-
grep -n "Compiled successfully" precompile_output.txt | head -5
169-
FAILURES_FOUND=1
170-
fi
171-
fi
172-
173-
# Pattern 2: Duplicate task execution messages (generate_packs)
174-
if grep -q "react_on_rails:generate_packs" precompile_output.txt; then
175-
GENERATE_PACKS_COUNT=$(grep -c "react_on_rails:generate_packs" precompile_output.txt || true)
176-
if [ "$GENERATE_PACKS_COUNT" -gt 1 ]; then
177-
echo "::error::FAILURE: react_on_rails:generate_packs task ran $GENERATE_PACKS_COUNT times (should only run once)."
178-
echo " Matching lines:"
179-
grep -n "react_on_rails:generate_packs" precompile_output.txt
180-
FAILURES_FOUND=1
181-
fi
182-
fi
183-
184-
# Pattern 2b: Duplicate locale generation
185-
if grep -q "react_on_rails:locale" precompile_output.txt; then
186-
LOCALE_COUNT=$(grep -c "react_on_rails:locale" precompile_output.txt || true)
187-
if [ "$LOCALE_COUNT" -gt 1 ]; then
188-
echo "::error::FAILURE: react_on_rails:locale task ran $LOCALE_COUNT times (should only run once)."
189-
echo " Matching lines:"
190-
grep -n "react_on_rails:locale" precompile_output.txt
191-
FAILURES_FOUND=1
192-
fi
193-
fi
194-
195-
# Pattern 2c: Duplicate webpack builds (check "Built at:" messages)
196-
BUILT_AT_COUNT=$(grep -c "Built at:" precompile_output.txt || true)
197-
if [ "$BUILT_AT_COUNT" -gt 1 ]; then
198-
echo "::error::FAILURE: Detected $BUILT_AT_COUNT webpack builds (expected 1). Tasks may be running twice."
199-
echo " Matching lines:"
200-
grep -n "Built at:" precompile_output.txt | head -5
201-
FAILURES_FOUND=1
202-
fi
203-
204-
# Pattern 3: Module not found errors
205-
if grep -Ei "module not found|cannot find module|can't resolve" precompile_output.txt; then
206-
echo "::error::FAILURE: Module resolution errors detected in precompile output."
207-
echo " Sample matching lines:"
208-
grep -Ei "module not found|cannot find module|can't resolve" precompile_output.txt | head -3
209-
FAILURES_FOUND=1
210-
fi
211-
212-
# Pattern 3b: ENOENT errors (missing files/directories)
213-
if grep -q "Error: ENOENT" precompile_output.txt; then
214-
echo "::error::FAILURE: Missing file or directory errors detected."
215-
echo " Sample matching lines:"
216-
grep -n "Error: ENOENT" precompile_output.txt | head -3
217-
FAILURES_FOUND=1
218-
fi
219-
220-
# Pattern 4: Webpack build errors (use specific webpack error markers)
221-
if grep -Ei "webpack.*error|failed to compile|compilation failed|ERROR in" precompile_output.txt; then
222-
echo "::error::FAILURE: Webpack compilation errors detected."
223-
echo " Sample matching lines:"
224-
grep -Ei "webpack.*error|failed to compile|compilation failed|ERROR in" precompile_output.txt | head -3
225-
FAILURES_FOUND=1
153+
exit "$PRECOMPILE_EXIT"
226154
fi
227-
228-
# Pattern 5: Ruby/Rails errors during precompile (match error class format)
229-
if grep -E "(NameError|LoadError|NoMethodError|SyntaxError):" precompile_output.txt; then
230-
echo "::error::FAILURE: Ruby errors detected during precompile."
231-
echo " Sample matching lines:"
232-
grep -E "(NameError|LoadError|NoMethodError|SyntaxError):" precompile_output.txt | head -3
233-
FAILURES_FOUND=1
234-
fi
235-
236-
# Pattern 6: Asset pipeline errors
237-
if grep -Ei "Sprockets::FileNotFound|Asset.*was not declared" precompile_output.txt; then
238-
echo "::error::FAILURE: Asset pipeline errors detected."
239-
echo " Sample matching lines:"
240-
grep -Ei "Sprockets::FileNotFound|Asset.*was not declared" precompile_output.txt | head -3
241-
FAILURES_FOUND=1
242-
fi
243-
244-
# Pattern 7: Memory issues
245-
if grep -Ei "javascript heap out of memory|killed|out of memory" precompile_output.txt; then
246-
echo "::error::FAILURE: Memory-related errors detected."
247-
echo " Sample matching lines:"
248-
grep -Ei "javascript heap out of memory|killed|out of memory" precompile_output.txt | head -3
249-
FAILURES_FOUND=1
250-
fi
251-
252-
# Pattern 8: Check for warnings that might indicate problems
253-
WARNING_COUNT=$(grep -ci "warning" precompile_output.txt || true)
254-
if [ "$WARNING_COUNT" -gt 10 ]; then
255-
echo "::warning::High number of warnings detected: $WARNING_COUNT warnings found. Please review."
256-
echo " Sample warnings:"
257-
grep -i "warning" precompile_output.txt | head -5
258-
fi
259-
260-
# Pattern 9: Deprecation warnings (log for visibility, don't fail)
261-
DEPRECATION_COUNT=$(grep -c "DEPRECATION" precompile_output.txt || true)
262-
if [ "$DEPRECATION_COUNT" -gt 0 ]; then
263-
echo "::warning::Found $DEPRECATION_COUNT deprecation warnings. These may indicate future breakage."
264-
echo " Deprecation messages:"
265-
grep -n "DEPRECATION" precompile_output.txt | head -5
266-
fi
267-
268-
if [ "$FAILURES_FOUND" -eq 1 ]; then
269-
echo ""
270-
echo "=========================================="
271-
echo "PRECOMPILE CHECK FAILED"
272-
echo "=========================================="
273-
echo "Review the output above for details."
274-
exit 1
275-
fi
276-
277-
echo ""
278-
echo "=========================================="
279-
echo "PRECOMPILE CHECK PASSED"
280-
echo "=========================================="
281-
echo "No known failure patterns detected in precompile output."
155+
- name: Validate precompile output
156+
run: script/validate-precompile-output react_on_rails/spec/dummy/precompile_output.txt
282157
- name: Upload precompile output
283158
if: always()
284159
uses: actions/upload-artifact@v4

script/validate-precompile-output

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
#!/bin/bash
2+
#
3+
# Validates assets:precompile output for known failure patterns.
4+
#
5+
# Usage:
6+
# script/validate-precompile-output <output_file>
7+
# RAILS_ENV=production rake assets:precompile 2>&1 | script/validate-precompile-output -
8+
#
9+
# Exit codes:
10+
# 0 - All checks passed
11+
# 1 - One or more failure patterns detected
12+
#
13+
# This script checks for known issues that don't cause precompile to fail
14+
# but indicate bugs like duplicate task execution or missing dependencies.
15+
#
16+
# See: https://github.com/shakacode/react_on_rails/issues/2081
17+
18+
set -e
19+
20+
OUTPUT_FILE="${1:--}"
21+
22+
if [ "$OUTPUT_FILE" = "-" ]; then
23+
# Read from stdin to temp file
24+
TEMP_FILE=$(mktemp)
25+
cat > "$TEMP_FILE"
26+
OUTPUT_FILE="$TEMP_FILE"
27+
trap "rm -f $TEMP_FILE" EXIT
28+
fi
29+
30+
if [ ! -f "$OUTPUT_FILE" ]; then
31+
echo "Error: Output file '$OUTPUT_FILE' not found"
32+
exit 1
33+
fi
34+
35+
echo "Validating assets:precompile output..."
36+
echo ""
37+
38+
FAILURES_FOUND=0
39+
40+
# Helper function to report errors (supports GitHub Actions annotations)
41+
report_error() {
42+
local message="$1"
43+
if [ -n "$GITHUB_ACTIONS" ]; then
44+
echo "::error::$message"
45+
else
46+
echo "ERROR: $message"
47+
fi
48+
}
49+
50+
# Helper function to report warnings
51+
report_warning() {
52+
local message="$1"
53+
if [ -n "$GITHUB_ACTIONS" ]; then
54+
echo "::warning::$message"
55+
else
56+
echo "WARNING: $message"
57+
fi
58+
}
59+
60+
# Pattern 1: Duplicate webpack compilation (indicates rake tasks running twice)
61+
# Look for webpack's "Compiled successfully" message which appears once per compilation
62+
if grep -q "Compiled successfully" "$OUTPUT_FILE"; then
63+
COMPILE_SUCCESS_COUNT=$(grep -c "Compiled successfully" "$OUTPUT_FILE" || true)
64+
if [ "$COMPILE_SUCCESS_COUNT" -gt 1 ]; then
65+
report_error "Detected $COMPILE_SUCCESS_COUNT webpack compilations (expected 1). Tasks may be running twice."
66+
echo " See: https://github.com/shakacode/react_on_rails/pull/2052"
67+
echo " Matching lines:"
68+
grep -n "Compiled successfully" "$OUTPUT_FILE" | head -5
69+
FAILURES_FOUND=1
70+
fi
71+
fi
72+
73+
# Pattern 2: Duplicate task execution messages (generate_packs)
74+
if grep -q "react_on_rails:generate_packs" "$OUTPUT_FILE"; then
75+
GENERATE_PACKS_COUNT=$(grep -c "react_on_rails:generate_packs" "$OUTPUT_FILE" || true)
76+
if [ "$GENERATE_PACKS_COUNT" -gt 1 ]; then
77+
report_error "react_on_rails:generate_packs task ran $GENERATE_PACKS_COUNT times (should only run once)."
78+
echo " Matching lines:"
79+
grep -n "react_on_rails:generate_packs" "$OUTPUT_FILE"
80+
FAILURES_FOUND=1
81+
fi
82+
fi
83+
84+
# Pattern 2b: Duplicate locale generation
85+
if grep -q "react_on_rails:locale" "$OUTPUT_FILE"; then
86+
LOCALE_COUNT=$(grep -c "react_on_rails:locale" "$OUTPUT_FILE" || true)
87+
if [ "$LOCALE_COUNT" -gt 1 ]; then
88+
report_error "react_on_rails:locale task ran $LOCALE_COUNT times (should only run once)."
89+
echo " Matching lines:"
90+
grep -n "react_on_rails:locale" "$OUTPUT_FILE"
91+
FAILURES_FOUND=1
92+
fi
93+
fi
94+
95+
# Pattern 2c: Duplicate webpack builds (check "Built at:" messages)
96+
BUILT_AT_COUNT=$(grep -c "Built at:" "$OUTPUT_FILE" || true)
97+
if [ "$BUILT_AT_COUNT" -gt 1 ]; then
98+
report_error "Detected $BUILT_AT_COUNT webpack builds (expected 1). Tasks may be running twice."
99+
echo " Matching lines:"
100+
grep -n "Built at:" "$OUTPUT_FILE" | head -5
101+
FAILURES_FOUND=1
102+
fi
103+
104+
# Pattern 3: Module not found errors
105+
if grep -Ei "module not found|cannot find module|can't resolve" "$OUTPUT_FILE"; then
106+
report_error "Module resolution errors detected in precompile output."
107+
echo " Sample matching lines:"
108+
grep -Ei "module not found|cannot find module|can't resolve" "$OUTPUT_FILE" | head -3
109+
FAILURES_FOUND=1
110+
fi
111+
112+
# Pattern 3b: ENOENT errors (missing files/directories)
113+
if grep -q "Error: ENOENT" "$OUTPUT_FILE"; then
114+
report_error "Missing file or directory errors detected."
115+
echo " Sample matching lines:"
116+
grep -n "Error: ENOENT" "$OUTPUT_FILE" | head -3
117+
FAILURES_FOUND=1
118+
fi
119+
120+
# Pattern 4: Webpack build errors (use specific webpack error markers)
121+
if grep -Ei "webpack.*error|failed to compile|compilation failed|ERROR in" "$OUTPUT_FILE"; then
122+
report_error "Webpack compilation errors detected."
123+
echo " Sample matching lines:"
124+
grep -Ei "webpack.*error|failed to compile|compilation failed|ERROR in" "$OUTPUT_FILE" | head -3
125+
FAILURES_FOUND=1
126+
fi
127+
128+
# Pattern 5: Ruby/Rails errors during precompile (match error class format)
129+
if grep -E "(NameError|LoadError|NoMethodError|SyntaxError):" "$OUTPUT_FILE"; then
130+
report_error "Ruby errors detected during precompile."
131+
echo " Sample matching lines:"
132+
grep -E "(NameError|LoadError|NoMethodError|SyntaxError):" "$OUTPUT_FILE" | head -3
133+
FAILURES_FOUND=1
134+
fi
135+
136+
# Pattern 6: Asset pipeline errors
137+
if grep -Ei "Sprockets::FileNotFound|Asset.*was not declared" "$OUTPUT_FILE"; then
138+
report_error "Asset pipeline errors detected."
139+
echo " Sample matching lines:"
140+
grep -Ei "Sprockets::FileNotFound|Asset.*was not declared" "$OUTPUT_FILE" | head -3
141+
FAILURES_FOUND=1
142+
fi
143+
144+
# Pattern 7: Memory issues
145+
if grep -Ei "javascript heap out of memory|killed|out of memory" "$OUTPUT_FILE"; then
146+
report_error "Memory-related errors detected."
147+
echo " Sample matching lines:"
148+
grep -Ei "javascript heap out of memory|killed|out of memory" "$OUTPUT_FILE" | head -3
149+
FAILURES_FOUND=1
150+
fi
151+
152+
# Pattern 8: Check for warnings that might indicate problems
153+
WARNING_COUNT=$(grep -ci "warning" "$OUTPUT_FILE" || true)
154+
if [ "$WARNING_COUNT" -gt 10 ]; then
155+
report_warning "High number of warnings detected: $WARNING_COUNT warnings found. Please review."
156+
echo " Sample warnings:"
157+
grep -i "warning" "$OUTPUT_FILE" | head -5
158+
fi
159+
160+
# Pattern 9: Deprecation warnings (log for visibility, don't fail)
161+
DEPRECATION_COUNT=$(grep -c "DEPRECATION" "$OUTPUT_FILE" || true)
162+
if [ "$DEPRECATION_COUNT" -gt 0 ]; then
163+
report_warning "Found $DEPRECATION_COUNT deprecation warnings. These may indicate future breakage."
164+
echo " Deprecation messages:"
165+
grep -n "DEPRECATION" "$OUTPUT_FILE" | head -5
166+
fi
167+
168+
echo ""
169+
if [ "$FAILURES_FOUND" -eq 1 ]; then
170+
echo "=========================================="
171+
echo "PRECOMPILE VALIDATION FAILED"
172+
echo "=========================================="
173+
echo "Review the errors above for details."
174+
exit 1
175+
fi
176+
177+
echo "=========================================="
178+
echo "PRECOMPILE VALIDATION PASSED"
179+
echo "=========================================="
180+
echo "No known failure patterns detected."
181+
exit 0

0 commit comments

Comments
 (0)