-
Notifications
You must be signed in to change notification settings - Fork 951
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'test-vale' into test-vale-pr
- Loading branch information
Showing
1 changed file
with
79 additions
and
42 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,88 @@ | ||
name: Lint Markdown Files | ||
name: Lint and suggest | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '**/*.md' | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
vale: | ||
name: Vale Markdown Lint | ||
vale: # Vale linting job | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Vale | ||
uses: errata-ai/vale-action@v2 | ||
with: | ||
version: 2.17.0 | ||
files: all | ||
reporter: github-pr-check | ||
fail_on_error: true | ||
|
||
- 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: | | ||
echo "[]" > rdjson_output.jsonl | ||
for file in $(echo "${{ steps.changed-files.outputs.files }}" | jq -r '.[]'); do | ||
echo "Running Vale on $file" | ||
vale_output=$(vale --output=JSON "$file") | ||
if [ $? -eq 0 ]; then | ||
echo "$vale_output" | jq -c --arg file "$file" '.[] | {file: $file, line: .Line, column: .Span[0], message: .Message, suggestion: (.Suggestions[0] // "")}' >> rdjson_output.jsonl | ||
else | ||
echo "Error processing $file" | ||
fi | ||
done | ||
echo "Vale output:" | ||
cat rdjson_output.jsonl | ||
- 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 "CHANGED_FILES=$(echo $CHANGED_FILES | jq -R -s -c 'split(\"\n\")[:-1]')" >> $GITHUB_ENV | ||
- name: Print Changed Files | ||
run: echo $CHANGED_FILES | ||
|
||
- name: Run Vale on changed files | ||
run: | | ||
for file in ${{ env.CHANGED_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: Simulate Vale changes | ||
run: | | ||
mkdir -p simulated_changes | ||
for file in $(echo ${{ steps.changed-files.outputs.files }} | jq -r '.[]'); do | ||
cp "$file" "simulated_changes/$(basename "$file")" | ||
vale --output=edit "simulated_changes/$(basename "$file")" | ||
done | ||
- name: Upload Vale results | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: vale-results | ||
path: '*.json' | ||
|
||
- name: Upload simulated changes | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: simulated-changes | ||
path: simulated_changes | ||
|
||
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 simulated changes | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: simulated-changes | ||
|
||
- name: List downloaded files | ||
run: ls -l simulated_changes | ||
|
||
- name: Suggest changes | ||
uses: parkerbxyz/suggest-changes@v1 | ||
with: | ||
comment: 'Please commit the suggested changes from Vale.' |