|
1 |
| -name: Lint and Suggest |
| 1 | +name: Lint and suggest |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | pull_request:
|
5 | 5 | paths:
|
6 | 6 | - '**/*.md'
|
7 | 7 |
|
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + pull-requests: write |
| 11 | + |
8 | 12 | jobs:
|
9 |
| - lint: |
| 13 | + vale: # Vale linting job |
10 | 14 | runs-on: ubuntu-latest
|
11 | 15 |
|
12 | 16 | steps:
|
13 |
| - - name: Checkout code |
14 |
| - uses: actions/checkout@v3 |
15 |
| - with: |
16 |
| - fetch-depth: 0 # Fetch all history so we can access all commits |
17 |
| - |
18 |
| - - name: Install Vale |
19 |
| - uses: errata-ai/vale-action@reviewdog |
20 |
| - with: |
21 |
| - version: 2.17.0 |
22 |
| - files: all |
23 |
| - reporter: github-pr-check |
24 |
| - filter_mode: nofilter |
25 |
| - |
26 |
| - |
27 |
| - - name: Install jq |
28 |
| - run: sudo apt-get install -y jq |
29 |
| - |
30 |
| - - name: Get changed files |
31 |
| - id: changed-files |
32 |
| - run: | |
33 |
| - BASE_SHA=$(git merge-base origin/${{ github.event.pull_request.base.ref }} ${{ github.sha }}) |
34 |
| - CHANGED_FILES=$(git diff --name-only $BASE_SHA ${{ github.sha }} -- '*.md') |
35 |
| - echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV |
36 |
| - echo "CHANGED_FILES=$(echo $CHANGED_FILES | jq -R -s -c 'split(\"\n\")[:-1]')" >> $GITHUB_ENV |
37 |
| -
|
38 |
| - - name: Print Changed Files |
39 |
| - run: echo $CHANGED_FILES |
40 |
| - |
41 |
| - - name: Run Vale on changed files |
42 |
| - run: | |
43 |
| - for file in ${{ env.CHANGED_FILES }}; do |
44 |
| - echo "Running Vale on $file" |
45 |
| - vale --config=vale.ini --output=JSON "$file" > "vale_output_${file//\//_}.json" |
46 |
| - vale --config=vale.ini --output=edit "$file" > "vale_output_${file//\//_}_edit.md" |
47 |
| - done |
48 |
| - shell: bash |
49 |
| - |
50 |
| - - name: Apply Vale edits and save originals |
51 |
| - run: | |
52 |
| - mkdir -p original_files |
53 |
| - mkdir -p corrected_files |
54 |
| - for file in ${{ env.CHANGED_FILES }}; do |
55 |
| - echo "Copying $file to original_files/${file//\//_}.original" |
56 |
| - cp "$file" "original_files/${file//\//_}.original" |
57 |
| - echo "Copying vale_output_${file//\//_}_edit.md to corrected_files/${file//\//_}" |
58 |
| - cp "vale_output_${file//\//_}_edit.md" "corrected_files/${file//\//_}" |
59 |
| - done |
60 |
| - env: |
61 |
| - REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.REVIEWDOG_GITHUB_API_TOKEN }} |
62 |
| - |
63 |
| - - name: Upload original files |
64 |
| - uses: actions/upload-artifact@v3 |
65 |
| - with: |
66 |
| - name: original-files |
67 |
| - path: original_files/ |
68 |
| - |
69 |
| - - name: Upload corrected files |
70 |
| - uses: actions/upload-artifact@v3 |
71 |
| - with: |
72 |
| - name: corrected-files |
73 |
| - path: corrected_files/ |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v3 |
| 19 | + with: |
| 20 | + fetch-depth: 0 # Fetch all history so we can access all commits |
| 21 | + |
| 22 | + - name: Install Vale |
| 23 | + uses: errata-ai/vale-action@v2g |
| 24 | + with: |
| 25 | + version: 2.17.0 |
| 26 | + files: all |
| 27 | + reporter: github-pr-check |
| 28 | + filter_mode: nofilter |
| 29 | + |
| 30 | + - name: Install jq |
| 31 | + run: sudo apt-get install -y jq |
| 32 | + |
| 33 | + - name: Get changed files |
| 34 | + id: changed-files |
| 35 | + run: | |
| 36 | + BASE_SHA=$(git merge-base origin/${{ github.event.pull_request.base.ref }} ${{ github.sha }}) |
| 37 | + CHANGED_FILES=$(git diff --name-only $BASE_SHA ${{ github.sha }} -- '*.md') |
| 38 | + echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV |
| 39 | + echo "CHANGED_FILES=$(echo $CHANGED_FILES | jq -R -s -c 'split(\"\n\")[:-1]')" >> $GITHUB_ENV |
| 40 | +
|
| 41 | + - name: Print Changed Files |
| 42 | + run: echo $CHANGED_FILES |
| 43 | + |
| 44 | + - name: Run Vale on changed files |
| 45 | + run: | |
| 46 | + for file in ${{ env.CHANGED_FILES }}; do |
| 47 | + echo "Running Vale on $file" |
| 48 | + vale --output=JSON $file > "vale_output_${file//\//_}.json" |
| 49 | + vale --output=edit $file > "vale_output_${file//\//_}_edit.md" |
| 50 | + done |
| 51 | + echo "Vale outputs:" |
| 52 | + ls -l |
| 53 | +
|
| 54 | + - name: Simulate Vale changes |
| 55 | + run: | |
| 56 | + mkdir -p simulated_changes |
| 57 | + for file in $(echo ${{ steps.changed-files.outputs.files }} | jq -r '.[]'); do |
| 58 | + cp "$file" "simulated_changes/$(basename "$file")" |
| 59 | + vale --output=edit "simulated_changes/$(basename "$file")" |
| 60 | + done |
| 61 | +
|
| 62 | + - name: Upload Vale results |
| 63 | + uses: actions/upload-artifact@v3 |
| 64 | + with: |
| 65 | + name: vale-results |
| 66 | + path: '*.json' |
| 67 | + |
| 68 | + - name: Upload simulated changes |
| 69 | + uses: actions/upload-artifact@v3 |
| 70 | + with: |
| 71 | + name: simulated-changes |
| 72 | + path: simulated_changes |
74 | 73 |
|
75 | 74 | suggest:
|
76 | 75 | runs-on: ubuntu-latest
|
77 |
| - needs: lint |
| 76 | + needs: vale # This ensures the suggest job runs after the vale job |
78 | 77 |
|
79 | 78 | steps:
|
80 |
| - - name: Checkout code |
81 |
| - uses: actions/checkout@v3 |
82 |
| - |
83 |
| - - name: Download original files |
84 |
| - uses: actions/download-artifact@v3 |
85 |
| - with: |
86 |
| - name: original-files |
87 |
| - |
88 |
| - - name: Download corrected files |
89 |
| - uses: actions/download-artifact@v3 |
90 |
| - with: |
91 |
| - name: corrected-files |
92 |
| - |
93 |
| - - name: List downloaded files |
94 |
| - run: | |
95 |
| - echo "Original files:" |
96 |
| - ls -l original_files |
97 |
| - echo "Corrected files:" |
98 |
| - ls -l corrected_files |
99 |
| -
|
100 |
| - - name: Run Reviewdog Suggestion Action |
101 |
| - uses: reviewdog/action-suggester@v1 |
102 |
| - with: |
103 |
| - github_token: ${{ secrets.REVIEWDOG_GITHUB_API_TOKEN }} |
104 |
| - tool_name: Vale |
105 |
| - level: "warning" |
106 |
| - filter_mode: "diff_context" |
107 |
| - fail_on_error: "false" |
108 |
| - reviewdog_flags: "" |
109 |
| - cleanup: "true" |
110 |
| - |
111 |
| - - name: Run Reviewdog with corrected files |
112 |
| - run: | |
113 |
| - for file in original_files/*.original; do |
114 |
| - original="$file" |
115 |
| - corrected="corrected_files/$(basename "$file" .original)" |
116 |
| - diff_output=$(diff -u "$original" "$corrected") |
117 |
| - if [[ -n "$diff_output" ]]; then |
118 |
| - echo "$diff_output" | reviewdog -f=diff -name="Vale" -reporter=github-pr-review -level=war |
| 79 | + - name: Checkout code |
| 80 | + uses: actions/checkout@v3 |
| 81 | + |
| 82 | + - name: Download simulated changes |
| 83 | + uses: actions/download-artifact@v3 |
| 84 | + with: |
| 85 | + name: simulated-changes |
| 86 | + |
| 87 | + - name: List downloaded files |
| 88 | + run: ls -l simulated_changes |
| 89 | + |
| 90 | + - name: Suggest changes |
| 91 | + uses: parkerbxyz/suggest-changes@v1 |
| 92 | + with: |
| 93 | + comment: 'Please commit the suggested changes from Vale.' |
0 commit comments