Repository navigation
94 lines (85 loc) · 4.22 KB
/
Copy pathvale.yml
File metadata and controls
94 lines (85 loc) · 4.22 KB
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
name: Vale Linting
# Trigger on PRs that change Markdown files (but skip run on draft PRs)
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'content/en/docs/**/*.md'
# Fork PRs don't have write permissions, so posting review comments happens in vale-comment.yml after this workflow finishes.
# This workflow only runs Vale and uploads the results as an artifact.
permissions:
contents: read
pull-requests: read
jobs:
vale:
# Only run on Mendix repo, not forks, and not on draft PRs
if: github.repository_owner == 'mendix' && github.event.pull_request.draft == false
runs-on: ubuntu-latest
env:
VALE_VERSION: 3.27.0
# Cancel old runs when new commits are pushed
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
- name: Checkout repo
uses: actions/checkout@v6
with:
sparse-checkout: |
.vale.ini
.vale
content/en/docs
sparse-checkout-cone-mode: false
- name: Get changed files
id: changed-files
run: |
# Also writes the PR number and an empty results file for vale-comment.yml
mkdir -p vale-results
echo "${{ github.event.pull_request.number }}" > vale-results/pr-number
gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files --paginate --jq '.[] | select(.status != "removed") | .filename' | { grep '^content/en/docs/.*\.md$' || true; } > changed-files.txt
: > vale-results/results.rdjsonl
if [ -s changed-files.txt ]; then echo "has_files=true" >> "$GITHUB_OUTPUT"; fi
env:
GH_TOKEN: ${{ github.token }}
- name: Install Vale
if: steps.changed-files.outputs.has_files == 'true'
run: |
cd "$RUNNER_TEMP"
ARCHIVE="vale_${VALE_VERSION}_Linux_64-bit.tar.gz"
BASE_URL="https://github.com/vale-cli/vale/releases/download/v${VALE_VERSION}"
curl -sSfLO "$BASE_URL/$ARCHIVE"
mkdir bin && tar -xzf "$ARCHIVE" -C bin vale
echo "$PWD/bin" >> "$GITHUB_PATH"
cd "$GITHUB_WORKSPACE" && "$RUNNER_TEMP/bin/vale" sync
- name: Run Vale
run: |
if [ -s changed-files.txt ]; then
# Report errors and warnings, not suggestions. Vale exits non-zero on errors; that is expected.
xargs -d '\n' vale --output=JSON --minAlertLevel=warning < changed-files.txt > vale.json || true
# Convert Vale JSON to reviewdog's rdjsonl format. Only errors become review comments.
jq -c 'to_entries[] | .key as $f | .value[] | select(.Severity == "error") | {message: ("[" + .Check + "] " + .Message), location: {path: $f, range: {start: {line: .Line, column: .Span[0]}}}, severity: (.Severity | ascii_upcase)}' vale.json > vale-results/results.rdjsonl
fi
- name: Summarize findings
run: |
# Lists every error and warning Vale found in the changed files, including lines the PR didn't change
if [ -s changed-files.txt ] && [ "$(jq 'length' vale.json)" -gt 0 ]; then
{
echo "## Vale errors and warnings in changed files"
echo
echo "Note: The Vale Comments workflow posts review comments only for errors on lines this PR changed. This table lists all errors and warnings in the changed files."
echo
echo "| File | Line | Severity | Rule | Message |"
echo "| --- | --- | --- | --- | --- |"
jq -r 'to_entries[] | .key as $f | .value[] | "| \($f) | \(.Line) | \(.Severity) | \(.Check) | \(.Message | gsub("[|<>]"; " ")) |"' vale.json
} >> "$GITHUB_STEP_SUMMARY"
elif [ -s changed-files.txt ]; then
echo "No Vale errors or warnings found in the changed files." >> "$GITHUB_STEP_SUMMARY"
else
echo "Vale didn't run because this PR doesn't add or change any Markdown files under content/en/docs." >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload results
uses: actions/upload-artifact@v7
with:
name: vale-results
path: vale-results/
retention-days: 3