1313 - name : Checkout
1414 uses : actions/checkout@v6
1515
16+ - name : Cache Cargo
17+ uses : actions/cache@v4
18+ with :
19+ path : |
20+ ~/.cargo/bin
21+ ~/.cargo/registry
22+ ~/.cargo/git
23+ target
24+ key : ${{ runner.os }}-cargo-harper-${{ hashFiles('.github/workflows/harper.yml') }}
25+ restore-keys : |
26+ ${{ runner.os }}-cargo-harper-
27+
1628 - name : Install Harper CLI
17- run : cargo install --git https://github.com/Automattic/harper harper-cli --locked
29+ run : |
30+ if ! command -v harper-cli >/dev/null 2>&1; then
31+ cargo install --git https://github.com/Automattic/harper harper-cli --locked
32+ else
33+ echo "Harper CLI found in cache."
34+ fi
1835
1936 - name : Generate Harper JSON Report
2037 run : |
@@ -41,20 +58,16 @@ jobs:
4158 if word:
4259 words.add(word)
4360
44- with open("dictionary-candidates.txt", "w", encoding="utf-8") as out:
45- out.write("Suggested dictionary candidates:\n")
46- for word in sorted(words, key=str.lower):
47- out.write(word + "\n")
48-
49- print(open("dictionary-candidates.txt", encoding="utf-8").read())
61+ print("Suggested dictionary candidates:")
62+ for word in sorted(words, key=str.lower):
63+ print(word)
5064 PY
5165
5266 - name : Check Selected Harper Rules
5367 run : |
5468 python - <<'PY'
5569 import json
5670 import sys
57- from pathlib import Path
5871
5972 with open("harper-report.json", encoding="utf-8") as f:
6073 reports = json.load(f)
6376
6477 for report in reports:
6578 file = report.get("file")
66- path = Path(file) if file else None
67- lines = path.read_text(encoding="utf-8", errors="ignore").splitlines() if path and path.exists() else []
6879
6980 for lint in report.get("lints", []):
7081 kind = lint.get("kind")
@@ -73,39 +84,16 @@ jobs:
7384 message = lint.get("message")
7485 text = lint.get("matched_text")
7586
76- keep = False
77-
7887 if kind in {"Spelling", "Grammar", "Repetition"}:
79- keep = True
80-
81- if kind == "Capitalization" and rule == "UseTitleCase":
82- if line_no and 1 <= line_no <= len(lines):
83- if lines[line_no - 1].lstrip().startswith("#"):
84- keep = True
85-
86- if keep:
8788 selected.append(
8889 f"{file}:{line_no}: [{kind}::{rule}] {text!r} - {message}"
8990 )
9091
91- with open("filtered-harper-report.txt", "w", encoding="utf-8") as out:
92- for item in selected:
93- out.write(item + "\n")
94-
9592 if selected:
9693 print("Selected Harper lints found:")
97- print(open("filtered-harper-report.txt", encoding="utf-8").read())
94+ for item in selected:
95+ print(item)
9896 sys.exit(1)
9997
10098 print("No selected Harper lints found.")
10199 PY
102-
103- - name : Upload Harper Reports
104- if : always()
105- uses : actions/upload-artifact@v6
106- with :
107- name : harper-reports
108- path : |
109- harper-report.json
110- filtered-harper-report.txt
111- dictionary-candidates.txt
0 commit comments