Add Harper workflow for grammar and style checks #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 -p cspell@9 -p @cspell/cspell-json-reporter cspell lint \ | |
| "docs/**/*.{md,mdx}" \ | |
| "src/pages/**/*.{md,mdx}" \ | |
| --config cspell.json \ | |
| --no-progress \ | |
| --reporter "@cspell/cspell-json-reporter" \ | |
| > 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: | |
| uri = issue.get("uri", "") | |
| file = uri.replace("file://", "") | |
| if "/rts-docs/" in file: | |
| file = file.split("/rts-docs/", 1)[-1] | |
| line = issue.get("row") | |
| message = issue.get("message") or f"Unknown word: {issue.get('text')!r}" | |
| print(f"{file}:{line}: {message}") | |
| 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 | |
| } |