test vale gha pr #46
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
name: Vale Lint | |
on: | |
pull_request: | |
paths: | |
- '**/*.md' | |
jobs: | |
vale: | |
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: Setup Cache for Dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cache | |
/usr/local/bin/vale | |
/usr/local/bin/reviewdog | |
key: ${{ runner.os }}-vale-reviewdog-${{ hashFiles('**/*.md') }} | |
- 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: Install Vale | |
uses: errata-ai/vale-action@v2 | |
- name: Create RDJSON Conversion Script | |
run: | | |
cat << 'EOF' > convert-to-rdjson.jq | |
to_entries[] | .value[] | { | |
message: .Message, | |
location: { | |
path: .file, | |
range: { | |
start: { line: .Line, column: (.Span[0] + 1) }, | |
end: { line: .Line, column: (.Span[1] + 1) } | |
} | |
}, | |
severity: .Severity, | |
code: { value: .Check, url: .Link } | |
} | |
EOF | |
- name: Run Vale and Reviewdog on Changed Files | |
run: | | |
for file in $CHANGED_FILES; do | |
/home/runner/vale --output=JSON $file > vale_output.json | |
jq --arg file "$file" '[.[$file][] | .file = $file]' vale_output.json > rdjson_output.json | |
cat rdjson_output.json | |
/home/runner/reviewdog -f=rdjson -name="Vale" -reporter=github-pr-review -level=warning -filter-mode=nofilter < rdjson_output.json | |
done | |
env: | |
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.SNIPPET_VALIDATION }} | |
- name: Install Reviewdog Suggestion Action | |
uses: reviewdog/action-suggester@v1 | |
with: | |
github_token: ${{ secrets.SNIPPET_VALIDATION }} | |
- name: Run Reviewdog Suggestion | |
run: | | |
git diff > diff_output.txt | |
reviewdog -f=diff -f.diff.strip=1 -reporter=github-pr-review < diff_output.txt |