-
Notifications
You must be signed in to change notification settings - Fork 4
103 lines (102 loc) · 3.69 KB
/
Copy pathdocs-quality.yml
File metadata and controls
103 lines (102 loc) · 3.69 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
95
96
97
98
99
100
101
102
103
name: Docs Quality
on:
pull_request:
workflow_dispatch:
jobs:
typos:
name: Spelling (typos-cli)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- uses: crate-ci/typos@master
harper:
name: Grammar and Style Check
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Cache Harper CLI
id: cache-harper
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/harper-cli
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-harper-cli
restore-keys: |
${{ runner.os }}-harper-cli
- name: Report cache status
run: |
echo "cache-hit output: '${{ steps.cache-harper.outputs.cache-hit }}'"
ls -la ~/.cargo/bin/ 2>&1 || echo "~/.cargo/bin does not exist"
if [ -x ~/.cargo/bin/harper-cli ]; then
echo "RESULT: harper-cli binary present and executable"
~/.cargo/bin/harper-cli --version || true
else
echo "RESULT: harper-cli binary NOT present -- full reinstall will run"
fi
- name: Install Harper CLI
if: steps.cache-harper.outputs.cache-hit != 'true'
run: cargo install --locked --git https://github.com/Automattic/harper.git harper-cli
- name: Lint docs with Harper
run: |
set -uo pipefail
ONLY_RULES=(
UseTitleCase
RepeatedWords
MergeWords
ItsContraction
)
ONLY_ARG="--only $(IFS=,; echo "${ONLY_RULES[*]}")"
out="$(mktemp)"
total=0
bad=0
while IFS= read -r -d '' file; do
total=$((total+1))
echo "::group::$file"
if harper-cli lint $ONLY_ARG "$file" 2>&1 | tee -a "$out"; then
:
else
bad=$((bad+1))
fi
echo "::endgroup::"
done < <(
find docs/hpc/harpertestfile.md -type f -print0 2>/dev/null
)
titlecase=$(grep -c 'Capitalization::UseTitleCase' "$out" || true)
{
echo "### Harper summary"
echo "- Files scanned: $total"
echo "- Files with issues: $bad"
echo "- Heading title case violations: $titlecase"
echo ""
echo "### Violations by rule"
echo '```'
grep -oE '\[[A-Za-z]+::[A-Za-z]+\]' "$out" | sort | uniq -c | sort -rn || true
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
echo "== Harper: $bad/$total files with issues; $titlecase UseTitleCase violations =="
[ "$bad" -eq 0 ]
- name: Annotate PR with Harper warnings
if: always()
run: |
set -uo pipefail
ONLY_RULES=(
UseTitleCase
RepeatedWords
MergeWords
ItsContraction
)
ONLY_ARG="--only $(IFS=,; echo "${ONLY_RULES[*]}")"
while IFS= read -r -d '' file; do
if json_out="$(harper-cli lint $ONLY_ARG --format json "$file" 2>/dev/null)"; then
:
else
printf '%s' "$json_out" | FILE="$file" python3 -c "import json,sys,os;d=json.load(sys.stdin);fp=os.environ['FILE'];esc=lambda s: s.replace('%','%25').replace('\r','%0D').replace('\n','%0A');[print('::warning file='+esc(fp)+',line='+str(l.get('line',1))+',col='+str(l.get('column',1))+',title='+esc(l.get('rule','?'))+'::'+esc(l.get('message',''))) for f in d for l in f.get('lints',[])]" || true
fi
done < <(
find docs/hpc/harpertestfile.md -type f -print0 2>/dev/null
)