-
Notifications
You must be signed in to change notification settings - Fork 13
215 lines (197 loc) · 7.64 KB
/
validate-documentation.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Validate documentation
on:
pull_request:
paths: ["docs/sources/**", "vale/**"]
workflow_dispatch:
jobs:
doc-validator:
if: ${{ github.repository == 'grafana/writers-toolkit' }}
runs-on: ubuntu-latest
container:
image: grafana/doc-validator:v4.0.0
steps:
- uses: actions/checkout@v4
- name: Run doc-validator tool
run: >
doc-validator
'--skip-checks=^image.+$'
docs/sources
/docs/writers-toolkit
| grep -v sources/shared
| reviewdog
-f=rdjsonl
--fail-on-error
--filter-mode=nofilter
--name=doc-validator
--reporter=github-pr-review
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
prettier:
if: ${{ github.repository == 'grafana/writers-toolkit' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: >
curl
--location
--output reviewdog.tar.gz
https://github.com/jdbaldry/reviewdog/releases/download/v0.18.0-rc.1/reviewdog_0.18.0-rc.1_Linux_x86_64.tar.gz
- run: |
tar zxf reviewdog.tar.gz reviewdog
sudo cp reviewdog /usr/local/bin/
rm -f reviewdog.tar.gz
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install prettier
- run: >
reviewdog
--filter-mode=nofilter
--runners prettier
--tee
- run: >
git diff
| reviewdog
--f diff
--fail-on-error
--filter-mode nofilter
--reporter=github-pr-review
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
test:
if: ${{ github.repository == 'grafana/writers-toolkit' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build website
run: |
docker run -v ${PWD}/docs/sources:/hugo/content/docs/writers-toolkit -e HUGO_REFLINKSERRORLEVEL=ERROR --rm grafana/docs-base:nightly /bin/bash -c 'make hugo'
vale:
runs-on: ubuntu-latest
container:
image: grafana/vale:latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Sync packages
run: vale sync
- name: Run linter
run: >
vale
'--glob=*.md'
--minAlertLevel=warning
--output=/etc/vale/rdjsonl.tmpl
docs/sources
| reviewdog
-f=rdjsonl
--fail-on-error
--name=vale
--reporter=github-pr-review
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
report-readability:
if: ${{ github.repository == 'grafana/writers-toolkit' }}
name: Report readability
runs-on: ubuntu-latest
steps:
- name: Install Vale
run: |
mkdir src
cd src
wget https://github.com/errata-ai/vale/releases/download/v2.28.0/vale_2.28.0_Linux_64-bit.tar.gz
tar zxf vale_2.28.0_Linux_64-bit.tar.gz vale
sudo cp vale /usr/local/bin/
cd ..
rm -rf src
- name: Check out repository with history
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run tool
run: |
touch .output.txt
for file in $(git --no-pager diff --name-only --diff-filter=ACMRT origin/main -- docs/sources); do
./scripts/readability "${file}" origin/main ${{ github.event.pull_request.head.sha }} >> .output.txt
done
- uses: actions/github-script@v7
with:
script: |
const fs = require("fs");
const measures = [
"AutomatedReadability",
"ColemanLiau",
"FleschKincaid",
"FleschReadingEase",
"GunningFog ",
"LIX",
"SMOG",
];
let body = "### Readability report\n";
body += `| File | ${measures.join(" | ")} |\n`;
body += `| - |${" - |".repeat(measures.length)}\n`;
let i = 0;
const output = fs.readFileSync(".output.txt", "utf-8")
if (output !== "") {
output.split("\n").forEach((line) => {
// docs/sources/_index.md Grafana.ReadabilityAutomatedReadability 8.99 (Δ+0.84) aim for below 8.
const re = new RegExp(
"^(?<file>[^\t]+?)\t(?<rule>[^\t]+?)\t(?<score>[^\t]+?)\t(?<delta>[^\t]+?)\t(?<guide>[^\t]+?)$",
);
const result = re.exec(line);
if (result !== null) {
const { file, rule, score, delta, guide } = result.groups;
if (i === 0) {
body += `| ${file} |`;
}
let color = "green";
const fl = parseFloat(delta.replace(new RegExp("\\(Δ(.+)\\)"), "$1"));
if (
(rule !== "Grafana.ReadabilityFleschReadingEase" && fl > 0) ||
(rule === "Grafana.ReadabilityFleschReadingEase" && fl < 0)
) {
color = "red";
}
if (fl === 0) {
color = "black";
}
body += " $${" + score + "\\space\\color{" + color + "}" + delta + "}$$ |";
if (i === measures.length - 1) {
body += "\n";
}
i = (i + 1) % measures.length;
}
});
body += `<details>
<summary>View metric targets</summary>
| Metric | Range | Ideal score |
| --- | --- | --- |
| [AutomatedReadability](https://en.wikipedia.org/wiki/Automated_readability_index) | 6 (very easy read) to 14 (extremely difficult read) | 8 or less |
| [ColemanLiau](https://en.wikipedia.org/wiki/Coleman%E2%80%93Liau_index) | 6 (very easy read) to 17 (extremely difficult read) | 9 or less |
| [FleschKincaid](https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests) | 6 (very easy read) to 17 (extremely difficult read) | 8 or less |
| [FleschReadingEase](https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests) | 100 (very easy read) to 0 (extremely difficult read) | 70 or more |
| [GunningFog](https://en.wikipedia.org/wiki/Gunning_fog_index) | 6 (very easy read) to 17 (extremely difficult read) | 10 or less |
| [LIX](https://en.wikipedia.org/wiki/Lix_(readability_test)) | 20 (very easy read) to 60+ (extremely difficult read) | 35 or less |
| [SMOG](https://en.wikipedia.org/wiki/SMOG) | 6 (very easy read) to 17 (extremely difficult read) | 10 or less |
</details>`;
const {data: comments} = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const existing = comments.filter((comment) => comment.body.match(new RegExp("^### Readability report")))
if (existing.length > 0) {
github.rest.issues.updateComment({
comment_id: existing[0].id,
owner: context.repo.owner,
repo: context.repo.repo,
body,
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
})
}
}