Skip to content

Commit 99404df

Browse files
authored
Update checkspelling.yml
1 parent 8d60764 commit 99404df

1 file changed

Lines changed: 40 additions & 135 deletions

File tree

Lines changed: 40 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,59 @@
1-
name: Harper (grammar + spelling)
1+
# .github/workflows/grammar.yml
2+
name: Grammar Check (PR Changes Only)
23

34
on:
45
pull_request:
5-
types: [opened, synchronize, reopened, ready_for_review]
6-
7-
permissions:
8-
contents: read
9-
pull-requests: write
106

117
jobs:
12-
harper:
8+
grammar:
139
runs-on: ubuntu-latest
14-
1510
steps:
16-
- name: Checkout
17-
uses: actions/checkout@v4
11+
- uses: actions/checkout@v3
12+
13+
- name: Get changed markdown files
14+
id: changed
15+
uses: tj-actions/changed-files@v39
1816
with:
19-
fetch-depth: 0
17+
files: |
18+
**/*.md
19+
**/*.mdx
2020
21-
- name: Set up Rust
22-
uses: dtolnay/rust-toolchain@stable
21+
- name: Skip if no docs changed
22+
if: steps.changed.outputs.any_changed != 'true'
23+
run: echo "No .md or .mdx files changed."
2324

24-
- name: Cache Cargo
25-
uses: actions/cache@v4
25+
- name: Set up Node
26+
if: steps.changed.outputs.any_changed == 'true'
27+
uses: actions/setup-node@v3
2628
with:
27-
path: |
28-
~/.cargo/registry
29-
~/.cargo/git
30-
target
31-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
32-
restore-keys: |
33-
${{ runner.os }}-cargo-
29+
node-version: 18
3430

35-
- name: Install harper-cli
31+
- name: Install MDX cleaner
32+
if: steps.changed.outputs.any_changed == 'true'
3633
run: |
37-
cargo install --locked --git https://github.com/Automattic/harper.git harper-cli
34+
npm install remark remark-mdx strip-markdown
35+
mkdir -p dist
36+
for file in ${{ steps.changed.outputs.all_changed_files }}; do
37+
node scripts/clean-mdx.js "$file" > "dist/${file//\//_}.txt"
38+
done
3839
39-
- name: Write Harper dictionary
40-
env:
41-
XDG_CONFIG_HOME: ${{ github.workspace }}/.xdg
40+
- name: Download LanguageTool CLI
41+
if: steps.changed.outputs.any_changed == 'true'
4242
run: |
43-
mkdir -p "$XDG_CONFIG_HOME/harper-ls"
44-
cat > "$XDG_CONFIG_HOME/harper-ls/dictionary.txt" <<'EOF'
45-
AerynOS
46-
astrojs
47-
sha256sum
48-
SHA256
49-
certutil
50-
hashfile
51-
lastUpdated
52-
EOF
43+
curl -L -o lt.zip https://languagetool.org/download/LanguageTool-stable.zip
44+
unzip lt.zip
45+
echo "LT_PATH=$(pwd)/LanguageTool-*/languagetool-commandline.jar" >> $GITHUB_ENV
5346
54-
- name: Run Harper on PR-changed files
55-
id: harper
47+
- name: Run LanguageTool with reviewdog
48+
if: steps.changed.outputs.any_changed == 'true'
5649
env:
57-
XDG_CONFIG_HOME: ${{ github.workspace }}/.xdg
50+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5851
run: |
59-
set -euo pipefail
60-
61-
BASE="${{ github.event.pull_request.base.sha }}"
62-
HEAD="${{ github.event.pull_request.head.sha }}"
63-
64-
mapfile -t FILES < <(git diff --name-only "$BASE" "$HEAD" -- \
65-
'*.md' '*.mdx' '*.txt' || true)
66-
67-
: > harper-report.txt
68-
69-
if [ "${#FILES[@]}" -eq 0 ]; then
70-
echo "No matching files changed (.md/.mdx/.txt)." > harper-report.txt
71-
echo "fail=0" >> "$GITHUB_OUTPUT"
72-
exit 0
73-
fi
74-
75-
fail=0
76-
for f in "${FILES[@]}"; do
77-
if [ ! -f "$f" ]; then
78-
continue
79-
fi
80-
81-
echo "===== $f =====" >> harper-report.txt
82-
echo >> harper-report.txt
83-
84-
out="$(harper-cli lint "$f" || true)"
85-
echo "$out" >> harper-report.txt
86-
echo >> harper-report.txt
87-
88-
after="$(printf '%s\n' "$out" | sed -n 's/.*after overlap removal, \([0-9]\+\) after.*/\1/p' | tail -n 1)"
89-
after="${after:-0}"
90-
91-
if [ "$after" -ne 0 ]; then
92-
fail=1
93-
fi
52+
for f in dist/*.txt; do
53+
java -jar $LT_PATH -l en-US "$f" |
54+
reviewdog -efm="%f: Line %l: %m" \
55+
-name="LanguageTool" \
56+
-reporter=github-pr-review \
57+
-filter-mode=added \
58+
-fail-on-error=false
9459
done
95-
96-
echo "fail=$fail" >> "$GITHUB_OUTPUT"
97-
98-
- name: Comment on PR with Harper output
99-
if: github.event.pull_request
100-
uses: actions/github-script@v7
101-
with:
102-
script: |
103-
const fs = require('fs');
104-
105-
const raw = fs.readFileSync('harper-report.txt', 'utf8');
106-
107-
const limit = 65000;
108-
const clipped =
109-
raw.length > limit
110-
? raw.slice(0, limit) + "\n\n[truncated]\n"
111-
: raw;
112-
113-
const marker = '<!-- harper-report -->';
114-
const body =
115-
`${marker}\n` +
116-
`<details>\n` +
117-
`<summary>Harper output</summary>\n\n` +
118-
"```text\n" +
119-
clipped +
120-
"\n```\n" +
121-
`</details>\n`;
122-
123-
const { owner, repo } = context.repo;
124-
const issue_number = context.issue.number;
125-
126-
const comments = await github.rest.issues.listComments({
127-
owner,
128-
repo,
129-
issue_number,
130-
});
131-
132-
const existing = comments.data.find(c =>
133-
c.body && c.body.includes(marker)
134-
);
135-
136-
if (existing) {
137-
await github.rest.issues.updateComment({
138-
owner,
139-
repo,
140-
comment_id: existing.id,
141-
body,
142-
});
143-
} else {
144-
await github.rest.issues.createComment({
145-
owner,
146-
repo,
147-
issue_number,
148-
body,
149-
});
150-
}
151-
152-
- name: Fail if Harper found issues
153-
if: steps.harper.outputs.fail == '1'
154-
run: exit 1

0 commit comments

Comments
 (0)