-
Notifications
You must be signed in to change notification settings - Fork 967
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0017d8
commit 1d4b4d1
Showing
1 changed file
with
113 additions
and
7 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,18 +1,124 @@ | ||
name: Reviewdog with Vale | ||
name: Lint and Suggest | ||
|
||
on: [pull_request] | ||
on: | ||
pull_request: | ||
paths: | ||
- '**/*.md' | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
reviewdog: | ||
vale: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v2 | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Install Vale | ||
uses: errata-ai/vale-action@v2 | ||
with: | ||
version: latest | ||
|
||
- name: Run Vale | ||
run: vale --output=line . | ||
- 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" | ||
done | ||
echo "Vale outputs:" | ||
ls -l | ||
- name: Apply Vale edits and save originals | ||
run: | | ||
mkdir -p original_files | ||
mkdir -p corrected_files | ||
for file in $(echo ${{ steps.changed-files.outputs.files }} | jq -r '.[]'); 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 | ||
- name: Upload original files | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: original-files | ||
path: original_files/ | ||
|
||
- name: Upload corrected files | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: corrected-files | ||
path: corrected_files/ | ||
|
||
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 original files | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: original-files | ||
|
||
- name: Download corrected files | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: corrected-files | ||
|
||
- name: List downloaded files | ||
run: | | ||
echo "Original files:" | ||
ls -l original_files | ||
echo "Corrected files:" | ||
ls -l corrected_files | ||
- 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 }} |