test vale gha pr #106
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: | |
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: changed-files | |
run: | | |
BASE_SHA=$(git merge-base origin/${{ github.event.pull_request.base.ref }} ${{ github.sha }}) | |
CHANGED_FILES=$(git diff --name-only $BASE_SHA ${{ github.sha }} -- '*.md') | |
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV | |
echo "::set-output name=files::$(echo $CHANGED_FILES | jq -R -s -c 'split(\"\\n\")[:-1]')" | |
- name: Print Changed Files | |
run: echo $CHANGED_FILES | |
- name: Run Vale on changed files | |
run: | | |
for file in $(echo ${{ steps.changed-files.outputs.files }} | jq -r '.[]'); 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 | |
run: | | |
for file in $(echo ${{ steps.changed-files.outputs.files }} | jq -r '.[]'); do | |
mv $file "${file}.original" | |
vale --output=edit $file > $file | |
done | |
- name: Upload Vale results | |
uses: actions/upload-artifact@v3 | |
with: | |
name: vale-results | |
path: '*.json' | |
- name: Upload corrected files | |
uses: actions/upload-artifact@v3 | |
with: | |
name: corrected-files | |
path: '*.md' | |
suggest: | |
runs-on: ubuntu-latest | |
needs: vale # This ensures the suggest job runs after the vale job | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Download corrected files | |
uses: actions/download-artifact@v3 | |
with: | |
name: corrected-files | |
- name: List downloaded files | |
run: ls -l | |
- name: Suggest changes | |
uses: parkerbxyz/suggest-changes@v1 | |
with: | |
comment: 'Please commit the suggested changes from Vale.' |