Merge branch 'test-vale' into test-vale-pr #162
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Lint and suggest | ||
on: | ||
pull_request: | ||
paths: | ||
- '**/*.md' | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
jobs: | ||
vale: # Combined Vale linting and suggestion job | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # Fetch all history so we can access all commits | ||
- name: Install Vale | ||
uses: errata-ai/vale-action@v2 | ||
- name: Install jq | ||
run: sudo apt-get install -y jq | ||
- name: Get Changed Files | ||
id: get_changed_files | ||
uses: tj-actions/changed-files@v44 | ||
with: | ||
files: | | ||
**/*.md | ||
separator: "," | ||
- name: Print Changed Markdown Files | ||
run: echo "Changed markdown files: ${{ steps.get_changed_files.outputs.all_changed_files }}" | ||
- name: Run Vale on changed files | ||
run: | | ||
IFS="," read -r -a files <<< "${{ steps.get_changed_files.outputs.all_changed_files }}" | ||
for file in "${files[@]}"; do | ||
echo "Running Vale on $file" | ||
vale --output=JSON "$file" > "vale_output_${file//\//_}.json" | ||
vale --output=edit "$file" > "vale_output_${file//\//_}_edit.md" | ||
done | ||
echo "Vale outputs:" | ||
ls -l | ||
- name: Apply Vale edits and save originals | ||
run: | | ||
mkdir -p original_files | ||
mkdir -p corrected_files | ||
IFS="," read -r -a files <<< "${{ steps.get_changed_files.outputs.all_changed_files }}" | ||
for file in "${files[@]}"; do | ||
echo "Copying $file to original_files/${file//\//_}.original" | ||
cp "$file" "original_files/${file//\//_}.original" | ||
echo "Copying vale_output_${file//\//_}_edit.md to corrected_files/${file//\//_}" | ||
cp "vale_output_${file//\//_}_edit.md" "corrected_files/${file//\//_}" | ||
done | ||
echo "Original files:" | ||
ls -l original_files | ||
echo "Corrected files:" | ||
ls -l corrected_files | ||
env: | ||
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.REVIEWDOG_GITHUB_API_TOKEN }} | ||
- name: Run Reviewdog Suggestion Action | ||
uses: reviewdog/action-suggester@v1 | ||
with: | ||
github_token: ${{ secrets.REVIEWDOG_GITHUB_API_TOKEN }} | ||
tool_name: Vale | ||
level: "warning" | ||
filter_mode: "diff_context" | ||
fail_on_error: "false" | ||
reviewdog_flags: "" | ||
cleanup: "true" | ||
- name: Run Reviewdog with corrected files | ||
run: | | ||
for file in original_files/*.original; do | ||
original="$file" | ||
corrected="corrected_files/$(basename "$file" .original)" | ||
diff_output=$(diff -u "$original" "$corrected") | ||
if [[ -n "$diff_output" ]]; then | ||
echo "$diff_output" | reviewdog -f=diff -name="Vale" -reporter=github-pr-review -level=warning -filter-mode=nofilter | ||
fi | ||
done | ||
env: | ||
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.REVIEWDOG_GITHUB_API_TOKEN }} |