diff --git a/.github/workflows/vale.yml b/.github/workflows/vale.yml index b6c4e982b68..3a23164c659 100644 --- a/.github/workflows/vale.yml +++ b/.github/workflows/vale.yml @@ -1,4 +1,4 @@ -name: Vale Linting and Suggestions +name: Lint and suggest on: pull_request: @@ -6,36 +6,121 @@ on: - '**/*.md' jobs: - vale-lint: + vale: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Vale - run: | - curl -sfL https://install.goreleaser.com/github.com/errata-ai/vale.sh | sh -s -- -b $HOME/.local/bin - echo "$HOME/.local/bin" >> $GITHUB_PATH - - - name: Run Vale - run: | - vale --output=JSON . > vale_output.json - - - name: Install jq - run: sudo apt-get install -y jq - - - name: Process Vale Output for Reviewdog - run: | - jq -c '.[] | {file: .Path, line: .Line, column: .Span[0], message: .Message, suggestion: .Suggestions[0], severity: .Severity}' vale_output.json > rdjson_output.jsonl - - - name: Reviewdog - Report results and Suggest changes - uses: reviewdog/action-suggester@v1 - with: - tool_name: vale - level: warning - reporter: github-pr-review - filter_mode: added - fail_on_error: true - input_file: rdjson_output.jsonl - github_token: ${{ secrets.REVIEWDOG_GITHUB_API_TOKEN }} + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - 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 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 + 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: + runs-on: ubuntu-latest + needs: vale + + 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: | + mkdir -p temp_diff + 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" > "temp_diff/$(basename "$file" .original).diff" + fi + done + ls temp_diff/ + for diff_file in temp_diff/*.diff; do + reviewdog -f=diff -name="Vale" -reporter=github-pr-review -level=warning -filter-mode=nofilter < "$diff_file" + done + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.REVIEWDOG_GITHUB_API_TOKEN }}