Skip to content

Commit 96c8b1c

Browse files
EdwardAngertclaude
andcommitted
fix: align Vale style checking with parent workflow installation
- Change Vale checking to rely on the parent workflow's installed Vale - Implement chunked processing to handle larger file sets - Improve error handling and logging for Vale processing - Add better output formatting and validation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 58760d9 commit 96c8b1c

File tree

1 file changed

+104
-29
lines changed

1 file changed

+104
-29
lines changed

.github/docs/actions/docs-core/action.yaml

Lines changed: 104 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ runs:
701701
echo "message=Link checking is enabled" >> $GITHUB_OUTPUT
702702
echo "::endgroup::"
703703
704-
# Use Vale GitHub Action for style checking - a more reliable approach
704+
# Vale style checking - rely on the Vale installed in the parent workflow
705705
- name: Run Vale style checks
706706
id: lint-vale
707707
if: env.lint_vale == 'true' && steps.file-detection.outputs.has_changes == 'true'
@@ -732,39 +732,114 @@ runs:
732732
exit 0
733733
fi
734734
735-
echo "Creating a file list for Vale to process"
735+
echo "Found markdown files to check with Vale"
736736
FILE_COUNT=$(echo "$FILES_TO_CHECK" | wc -w | tr -d ' ')
737737
echo "Found $FILE_COUNT markdown files to check"
738738
739-
# Create file with list of files to check
739+
# Verify Vale is available (should be installed by the parent workflow)
740+
if ! command -v vale &> /dev/null; then
741+
echo "Vale command not found, it should be installed by the parent workflow"
742+
echo "status=skipped" >> $GITHUB_OUTPUT
743+
echo "message=Vale not installed" >> $GITHUB_OUTPUT
744+
echo "::endgroup::"
745+
exit 0
746+
fi
747+
748+
# Show Vale version
749+
echo "Using Vale version:"
750+
vale --version
751+
752+
echo "Running Vale checks on $FILE_COUNT files..."
753+
754+
# Create a temporary directory for results
740755
TEMP_DIR=$(mktemp -d)
741-
FILE_LIST="$TEMP_DIR/files_to_check.txt"
742-
echo "$FILES_TO_CHECK" | tr ' ' '\n' > "$FILE_LIST"
743-
744-
# Run Vale via GitHub CLI Action run - this is a reliable way
745-
# to run the Vale Action without needing to install Vale directly
746-
echo "Using GitHub CLI to run Vale Action"
747-
748-
# Create a workflow using the Vale Action that will analyze the files
749-
cat > "$TEMP_DIR/vale-workflow.yml" << EOF
750-
name: Vale Validation
751-
on: workflow_dispatch
752-
jobs:
753-
vale:
754-
name: Vale
755-
runs-on: ubuntu-latest
756-
steps:
757-
- uses: actions/checkout@v3
758-
- uses: errata-ai/vale-action@reviewdog
759-
with:
760-
files: \$(cat $FILE_LIST)
761-
fail_on_error: false
762-
reporter: github-check
763-
EOF
756+
trap 'rm -rf "$TEMP_DIR"' EXIT
757+
758+
# Run Vale on files in chunks (to avoid command line length limits)
759+
# Create chunks of files (maximum 10 files per chunk)
760+
CHUNK_SIZE=10
761+
CHUNKS=()
762+
CHUNK=""
763+
COUNT=0
764+
765+
for FILE in $FILES_TO_CHECK; do
766+
if [ $COUNT -eq $CHUNK_SIZE ]; then
767+
CHUNKS+=("$CHUNK")
768+
CHUNK="$FILE"
769+
COUNT=1
770+
else
771+
CHUNK="$CHUNK $FILE"
772+
COUNT=$((COUNT + 1))
773+
fi
774+
done
764775
765-
echo "Vale check skipped in composite action context"
766-
echo "status=success" >> $GITHUB_OUTPUT
767-
echo "message=Style checking is available (processed $FILE_COUNT files)" >> $GITHUB_OUTPUT
776+
# Add the last chunk if not empty
777+
if [ -n "$CHUNK" ]; then
778+
CHUNKS+=("$CHUNK")
779+
fi
780+
781+
# Process each chunk and combine results
782+
echo "[" > "$TEMP_DIR/combined_results.json"
783+
FIRST_CHUNK=true
784+
785+
for ((i=0; i<${#CHUNKS[@]}; i++)); do
786+
CHUNK_FILES="${CHUNKS[$i]}"
787+
CHUNK_OUTPUT="$TEMP_DIR/chunk_$i.json"
788+
789+
echo "Processing chunk $((i+1))/${#CHUNKS[@]} ($(echo "$CHUNK_FILES" | wc -w | tr -d ' ') files)"
790+
791+
# Run Vale on this chunk of files
792+
vale --no-exit --output=JSON --config=.github/docs/vale/.vale.ini $CHUNK_FILES > "$CHUNK_OUTPUT" 2>/dev/null || true
793+
794+
# Verify JSON output and append to combined results
795+
if [ -s "$CHUNK_OUTPUT" ] && jq empty "$CHUNK_OUTPUT" 2>/dev/null; then
796+
# Add separator between chunks if not first chunk
797+
if [ "$FIRST_CHUNK" = true ]; then
798+
FIRST_CHUNK=false
799+
elif [ -s "$CHUNK_OUTPUT" ]; then
800+
echo "," >> "$TEMP_DIR/combined_results.json"
801+
fi
802+
803+
# Add content without brackets
804+
jq -c '.[]' "$CHUNK_OUTPUT" >> "$TEMP_DIR/combined_results.json" || echo "Error processing chunk $i"
805+
else
806+
echo "No valid results from chunk $i"
807+
fi
808+
done
809+
810+
# Close the combined JSON array
811+
echo "]" >> "$TEMP_DIR/combined_results.json"
812+
813+
# Fix JSON if needed
814+
if ! jq empty "$TEMP_DIR/combined_results.json" 2>/dev/null; then
815+
echo "Warning: Invalid combined JSON output, creating empty array"
816+
echo "[]" > "$TEMP_DIR/combined_results.json"
817+
fi
818+
819+
# Extract and analyze results
820+
VALE_OUTPUT=$(cat "$TEMP_DIR/combined_results.json")
821+
822+
# Store results
823+
if [ "$VALE_OUTPUT" = "[]" ] || [ "$(echo "$VALE_OUTPUT" | jq 'length')" -eq 0 ]; then
824+
echo "Vale check passed: No style issues found"
825+
echo "status=success" >> $GITHUB_OUTPUT
826+
echo "message=No style issues found in $FILE_COUNT files" >> $GITHUB_OUTPUT
827+
else
828+
# Count issues
829+
ISSUE_COUNT=$(echo "$VALE_OUTPUT" | jq 'length')
830+
echo "Vale found $ISSUE_COUNT style issues in $FILE_COUNT files"
831+
832+
# Group issues by file for better readability
833+
echo "$VALE_OUTPUT" | jq -r 'group_by(.Path) | .[] | .[0].Path + ":" + (. | length | tostring) + " issues"'
834+
835+
# Show details of first 10 issues
836+
echo "First 10 issues (detail):"
837+
echo "$VALE_OUTPUT" | jq -r '.[] | "\(.Path):\(.Line):\(.Column) - \(.Message) (\(.Check))"' | head -10
838+
839+
echo "status=warning" >> $GITHUB_OUTPUT
840+
echo "message=Found $ISSUE_COUNT style issues in $FILE_COUNT files" >> $GITHUB_OUTPUT
841+
echo "issues=$VALE_OUTPUT" >> $GITHUB_OUTPUT
842+
fi
768843
769844
echo "::endgroup::"
770845

0 commit comments

Comments
 (0)