-
Notifications
You must be signed in to change notification settings - Fork 4
129 lines (128 loc) · 4.42 KB
/
Copy pathdocs-quality.yml
File metadata and controls
129 lines (128 loc) · 4.42 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
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
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[*]}")"
mdxtmp="$(mktemp -d)"
out="$(mktemp)"
total=0
bad=0
while IFS= read -r -d '' file; do
total=$((total+1))
case "$file" in
*.mdx)
target="$mdxtmp/${file}.md"
mkdir -p "$(dirname "$target")"
cp "$file" "$target"
;;
*)
target="$file"
;;
esac
echo "::group::$file"
if harper-cli lint $ONLY_ARG "$target" 2>&1 | tee -a "$out"; then
:
else
bad=$((bad+1))
fi
echo "::endgroup::"
done < <(
find docs src/pages \
-type f \( -name "*.md" -o -name "*.mdx" \) \
-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[*]}")"
mdxtmp="$(mktemp -d)"
while IFS= read -r -d '' file; do
case "$file" in
*.mdx)
target="$mdxtmp/${file}.md"
mkdir -p "$(dirname "$target")"
cp "$file" "$target"
;;
*)
target="$file"
;;
esac
if json_out="$(harper-cli lint $ONLY_ARG --format json "$target" 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 src/pages \
-type f \( -name "*.md" -o -name "*.mdx" \) \
-print0 2>/dev/null
)