Skip to content

Commit 44a38fd

Browse files
EdwardAngertclaude
andcommitted
docs: add test script for Vale integration
- Add comprehensive Vale integration test script to verify workflow functionality - Create README with testing documentation and explanation - Support local testing of Vale processing approach - Simulate workflow environment for reliable validation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 96c8b1c commit 44a38fd

File tree

2 files changed

+262
-0
lines changed

2 files changed

+262
-0
lines changed

.github/docs/testing/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Documentation Workflow Testing
2+
3+
This directory contains utilities for testing the documentation validation workflows locally.
4+
5+
## Vale Testing
6+
7+
The `test-vale.sh` script is designed to validate that the Vale integration in the unified documentation workflow functions correctly. This script simulates the GitHub Actions environment and tests the full Vale style checking approach, including:
8+
9+
1. Installation of Vale using the same method as the workflow
10+
2. Basic Vale execution and verification
11+
3. JSON output format validation
12+
4. Chunked processing of multiple files (as implemented in the workflow)
13+
14+
### Running the Test
15+
16+
To run the Vale integration test:
17+
18+
```bash
19+
cd .github/docs/testing
20+
./test-vale.sh
21+
```
22+
23+
### What the Test Covers
24+
25+
- Validates that Vale can be properly installed and run
26+
- Confirms that Vale produces valid JSON output
27+
- Tests the chunked processing approach used in the workflow
28+
- Verifies the JSON results combination logic
29+
30+
### When to Run This Test
31+
32+
Run this test when:
33+
34+
1. Making changes to the Vale integration in the docs-core action
35+
2. Upgrading the Vale version used in the workflow
36+
3. Modifying the Vale configuration or style rules
37+
4. Troubleshooting Vale-related issues in the GitHub Actions environment
38+
39+
## Implementation Notes
40+
41+
The Vale integration in our workflow has two components:
42+
43+
1. Installation in the parent workflow (`docs-unified.yaml`)
44+
2. Execution in the docs-core composite action
45+
46+
This approach ensures that Vale is properly installed and accessible to the composite action without requiring it to download and install Vale itself, which could be unreliable within the composite action context.

.github/docs/testing/test-vale.sh

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
#!/bin/bash
2+
# Test script for Vale integration in docs workflow
3+
set -e
4+
5+
echo "Testing Vale integration in docs workflow"
6+
echo "----------------------------------------"
7+
8+
# Function to clean up on exit
9+
cleanup() {
10+
echo "Cleaning up..."
11+
rm -rf "$TEMP_DIR"
12+
}
13+
14+
# Create temporary directory
15+
TEMP_DIR=$(mktemp -d)
16+
trap cleanup EXIT
17+
18+
# Setup environment to match GitHub Actions
19+
export HOME_BIN="$TEMP_DIR/home/bin"
20+
mkdir -p "$HOME_BIN"
21+
export PATH="$HOME_BIN:$PATH"
22+
23+
# Create sample files for testing
24+
DOCS_DIR="$TEMP_DIR/docs"
25+
mkdir -p "$DOCS_DIR"
26+
VALE_DIR="$TEMP_DIR/.github/docs/vale"
27+
mkdir -p "$VALE_DIR/styles/Vale"
28+
29+
# Create a sample markdown file with potential Vale issues
30+
cat > "$DOCS_DIR/sample.md" << EOF
31+
# Sample Document
32+
33+
This is a simple document for testing Vale integration.
34+
35+
We shoud use active voice and avoid passive constructions.
36+
37+
The error was detected by the system. # Passive voice example
38+
39+
This line is to longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg and should trigger style checks.
40+
EOF
41+
42+
# Create a simple Vale config
43+
cat > "$VALE_DIR/.vale.ini" << EOF
44+
StylesPath = styles
45+
MinAlertLevel = suggestion
46+
47+
[*]
48+
BasedOnStyles = Vale
49+
EOF
50+
51+
# Create a simple Vale rule file
52+
cat > "$VALE_DIR/styles/Vale/Passive.yml" << EOF
53+
extends: existence
54+
message: "Use active voice instead of passive voice."
55+
link: https://example.com/active-voice
56+
level: warning
57+
ignorecase: true
58+
raw:
59+
- \b(am|are|were|being|is|been|was|be)\b\s*(\w+ed|\w+ing|\w+en)
60+
EOF
61+
62+
echo "=== PHASE 1: Testing Vale installation ==="
63+
echo "-----------------------------------------"
64+
65+
# Install Vale using the same method as the workflow
66+
os=$(uname -s | tr '[:upper:]' '[:lower:]')
67+
arch=$(uname -m)
68+
if [ "$arch" = "x86_64" ]; then
69+
arch="64-bit"
70+
elif [[ "$arch" =~ ^(arm|aarch).* ]]; then
71+
arch="arm64"
72+
fi
73+
74+
echo "Downloading Vale for $os-$arch to $HOME_BIN"
75+
curl -sfL "https://github.com/errata-ai/vale/releases/download/v2.30.0/vale_2.30.0_${os}_${arch}.tar.gz" | tar xz -C "$HOME_BIN" vale
76+
chmod +x "$HOME_BIN/vale"
77+
78+
# Verify Vale installation
79+
if command -v vale &> /dev/null; then
80+
echo "✅ Vale installed successfully"
81+
vale --version
82+
else
83+
echo "❌ Vale installation failed"
84+
exit 1
85+
fi
86+
87+
echo
88+
echo "=== PHASE 2: Testing Vale basic execution ==="
89+
echo "--------------------------------------------"
90+
91+
# Run Vale on the sample file
92+
echo "Running Vale check on sample file..."
93+
vale --no-exit --output=line --config="$VALE_DIR/.vale.ini" "$DOCS_DIR/sample.md" || echo "✅ Vale found issues as expected"
94+
95+
echo
96+
echo "=== PHASE 3: Testing Vale JSON output format ==="
97+
echo "----------------------------------------------"
98+
99+
# Run Vale with JSON output
100+
echo "Testing Vale JSON output format..."
101+
VALE_OUTPUT=$(vale --no-exit --output=JSON --config="$VALE_DIR/.vale.ini" "$DOCS_DIR/sample.md")
102+
echo "$VALE_OUTPUT" > "$TEMP_DIR/vale-output.json"
103+
104+
# Verify JSON output
105+
if echo "$VALE_OUTPUT" | jq . > /dev/null 2>&1; then
106+
echo "✅ Vale produces valid JSON output"
107+
echo "Found $(echo "$VALE_OUTPUT" | jq 'length') issues"
108+
else
109+
echo "❌ Vale JSON output is not valid"
110+
cat "$TEMP_DIR/vale-output.json"
111+
exit 1
112+
fi
113+
114+
echo
115+
echo "=== PHASE 4: Testing the chunked processing approach ==="
116+
echo "-----------------------------------------------------"
117+
118+
# Create more test files for chunk testing
119+
for i in {1..15}; do
120+
cp "$DOCS_DIR/sample.md" "$DOCS_DIR/sample_$i.md"
121+
done
122+
123+
echo "Created 16 test files for chunk processing"
124+
125+
# Function to run vale on files in chunks (similar to our actual workflow)
126+
process_files_in_chunks() {
127+
local files="$1"
128+
local chunk_size="$2"
129+
local output_dir="$3"
130+
131+
echo "Processing $(echo "$files" | wc -w | tr -d ' ') files in chunks of $chunk_size"
132+
133+
# Create chunks of files
134+
CHUNKS=()
135+
CHUNK=""
136+
COUNT=0
137+
138+
for FILE in $files; do
139+
if [ $COUNT -eq $chunk_size ]; then
140+
CHUNKS+=("$CHUNK")
141+
CHUNK="$FILE"
142+
COUNT=1
143+
else
144+
CHUNK="$CHUNK $FILE"
145+
COUNT=$((COUNT + 1))
146+
fi
147+
done
148+
149+
# Add the last chunk if not empty
150+
if [ -n "$CHUNK" ]; then
151+
CHUNKS+=("$CHUNK")
152+
fi
153+
154+
echo "Created ${#CHUNKS[@]} chunks"
155+
156+
# Process each chunk
157+
echo "[" > "$output_dir/combined_results.json"
158+
FIRST_CHUNK=true
159+
160+
for ((i=0; i<${#CHUNKS[@]}; i++)); do
161+
CHUNK_FILES="${CHUNKS[$i]}"
162+
CHUNK_OUTPUT="$output_dir/chunk_$i.json"
163+
164+
echo "Processing chunk $((i+1))/${#CHUNKS[@]} ($(echo "$CHUNK_FILES" | wc -w | tr -d ' ') files)"
165+
166+
# Run Vale on this chunk of files
167+
vale --no-exit --output=JSON --config="$VALE_DIR/.vale.ini" $CHUNK_FILES > "$CHUNK_OUTPUT" 2>/dev/null || true
168+
169+
# Verify JSON output and append to combined results
170+
if [ -s "$CHUNK_OUTPUT" ] && jq empty "$CHUNK_OUTPUT" 2>/dev/null; then
171+
# Add separator between chunks if not first chunk
172+
if [ "$FIRST_CHUNK" = true ]; then
173+
FIRST_CHUNK=false
174+
elif [ -s "$CHUNK_OUTPUT" ]; then
175+
echo "," >> "$output_dir/combined_results.json"
176+
fi
177+
178+
# Add content without brackets
179+
jq -c '.[]' "$CHUNK_OUTPUT" >> "$output_dir/combined_results.json" || echo "Error processing chunk $i"
180+
else
181+
echo "No valid results from chunk $i"
182+
fi
183+
done
184+
185+
# Close the combined JSON array
186+
echo "]" >> "$output_dir/combined_results.json"
187+
188+
# Fix JSON if needed
189+
if ! jq empty "$output_dir/combined_results.json" 2>/dev/null; then
190+
echo "Warning: Invalid combined JSON output, creating empty array"
191+
echo "[]" > "$output_dir/combined_results.json"
192+
fi
193+
194+
return 0
195+
}
196+
197+
# Find all markdown files
198+
MD_FILES=$(find "$DOCS_DIR" -name "*.md" | tr '\n' ' ')
199+
200+
# Process files in chunks
201+
process_files_in_chunks "$MD_FILES" 5 "$TEMP_DIR"
202+
203+
# Validate the combined results
204+
COMBINED_OUTPUT="$TEMP_DIR/combined_results.json"
205+
if [ -f "$COMBINED_OUTPUT" ] && jq empty "$COMBINED_OUTPUT" 2>/dev/null; then
206+
ISSUES=$(jq 'length' "$COMBINED_OUTPUT")
207+
echo "✅ Chunked processing successful - found $ISSUES issues total"
208+
else
209+
echo "❌ Chunked processing failed"
210+
exit 1
211+
fi
212+
213+
echo
214+
echo "=== TEST SUMMARY ==="
215+
echo "All Vale tests completed successfully! 🎉"
216+
echo "The implementation should work in GitHub Actions workflows"

0 commit comments

Comments
 (0)