Skip to content

Add Harper workflow for grammar and style checks #4

Add Harper workflow for grammar and style checks

Add Harper workflow for grammar and style checks #4

Workflow file for this run

name: Docs Quality
on:
pull_request:
workflow_dispatch:
inputs:
allow_failure:
type: boolean
default: false
env:
ALLOW_FAILURE: ${{ github.event_name == 'workflow_dispatch' && inputs.allow_failure }}
jobs:
spelling:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: "20"
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-cspell
restore-keys: ${{ runner.os }}-npm-cspell-
- run: |
npx --yes cspell@9 lint \
"docs/**/*.{md,mdx}" \
"src/pages/**/*.{md,mdx}" \
--config cspell.json \
--no-progress \
--reporter json \
> cspell-report.json || true
- run: |
python - <<'PY'
import json
import os
import sys
try:
with open("cspell-report.json", encoding="utf-8") as f:
content = f.read().strip()
except FileNotFoundError:
content = ""
if not content:
print("::error::cspell-report.json is empty. Check the previous step's log for the actual cspell error (e.g. missing cspell.json or project-words.txt).")
sys.exit(1)
try:
data = json.loads(content)
except json.JSONDecodeError:
print("::error::cspell-report.json is not valid JSON. Raw output was:")
print(content[:2000])
sys.exit(1)
issues = data.get("issues", [])
for issue in issues:
file = issue.get("uri")
line = issue.get("row")
message = issue.get("message") or f"Unknown word: {issue.get('text')!r}"
print(f"::error file={file},line={line}::{message}")
print(f"{len(issues)} spelling issue(s) found.")
allow_failure = os.environ.get("ALLOW_FAILURE") == "true"
sys.exit(1 if issues and not allow_failure else 0)
PY
heading-case:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- run: |
python check_heading_case.py docs src/pages || {
if [ "$ALLOW_FAILURE" = "true" ]; then
exit 0
fi
exit 1
}