-
Notifications
You must be signed in to change notification settings - Fork 969
121 lines (103 loc) · 3.64 KB
/
vale.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: Lint and suggest
on:
pull_request:
paths:
- '**/*.md'
jobs:
vale: # Vale linting 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: 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: Apply Vale edits and save originals
run: |
mkdir -p original_files
mkdir -p corrected_files
for file in ${{ env.CHANGED_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: 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: # Reviewdog suggestion job
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 }}