Update index.mdx #1
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: Harper (grammar + spelling) | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened, ready_for_review] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| harper: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache Cargo | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo- | |
| - name: Install harper-cli | |
| run: | | |
| cargo install --locked --git https://github.com/Automattic/harper.git harper-cli | |
| - name: Write Harper dictionary | |
| env: | |
| XDG_CONFIG_HOME: ${{ github.workspace }}/.xdg | |
| run: | | |
| mkdir -p "$XDG_CONFIG_HOME/harper-ls" | |
| cat > "$XDG_CONFIG_HOME/harper-ls/dictionary.txt" <<'EOF' | |
| AerynOS | |
| astrojs | |
| sha256sum | |
| SHA256 | |
| certutil | |
| hashfile | |
| lastUpdated | |
| EOF | |
| - name: Run Harper on PR-changed files | |
| id: harper | |
| env: | |
| XDG_CONFIG_HOME: ${{ github.workspace }}/.xdg | |
| run: | | |
| set -euo pipefail | |
| BASE="${{ github.event.pull_request.base.sha }}" | |
| HEAD="${{ github.event.pull_request.head.sha }}" | |
| mapfile -t FILES < <(git diff --name-only "$BASE" "$HEAD" -- \ | |
| '*.md' '*.mdx' '*.txt' || true) | |
| : > harper-report.txt | |
| if [ "${#FILES[@]}" -eq 0 ]; then | |
| echo "No matching files changed (.md/.mdx/.txt)." > harper-report.txt | |
| echo "fail=0" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| fail=0 | |
| for f in "${FILES[@]}"; do | |
| if [ ! -f "$f" ]; then | |
| continue | |
| fi | |
| echo "===== $f =====" >> harper-report.txt | |
| echo >> harper-report.txt | |
| out="$(harper-cli lint "$f" || true)" | |
| echo "$out" >> harper-report.txt | |
| echo >> harper-report.txt | |
| after="$(printf '%s\n' "$out" | sed -n 's/.*after overlap removal, \([0-9]\+\) after.*/\1/p' | tail -n 1)" | |
| after="${after:-0}" | |
| if [ "$after" -ne 0 ]; then | |
| fail=1 | |
| fi | |
| done | |
| echo "fail=$fail" >> "$GITHUB_OUTPUT" | |
| - name: Comment on PR with Harper output | |
| if: github.event.pull_request | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const raw = fs.readFileSync('harper-report.txt', 'utf8'); | |
| const limit = 65000; | |
| const clipped = | |
| raw.length > limit | |
| ? raw.slice(0, limit) + "\n\n[truncated]\n" | |
| : raw; | |
| const marker = '<!-- harper-report -->'; | |
| const body = | |
| `${marker}\n` + | |
| `<details>\n` + | |
| `<summary>Harper output</summary>\n\n` + | |
| "```text\n" + | |
| clipped + | |
| "\n```\n" + | |
| `</details>\n`; | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.issue.number; | |
| const comments = await github.rest.issues.listComments({ | |
| owner, | |
| repo, | |
| issue_number, | |
| }); | |
| const existing = comments.data.find(c => | |
| c.body && c.body.includes(marker) | |
| ); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner, | |
| repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number, | |
| body, | |
| }); | |
| } | |
| - name: Fail if Harper found issues | |
| if: steps.harper.outputs.fail == '1' | |
| run: exit 1 |