File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed
Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ name : LanguageTool (PR)
2+
3+ on :
4+ pull_request :
5+ types : [opened, synchronize, reopened, ready_for_review]
6+
7+ jobs :
8+ languagetool :
9+ runs-on : ubuntu-latest
10+
11+ steps :
12+ - name : Checkout
13+ uses : actions/checkout@v4
14+ with :
15+ fetch-depth : 0
16+
17+ - name : Set up Java
18+ uses : actions/setup-java@v4
19+ with :
20+ distribution : temurin
21+ java-version : " 17"
22+
23+ - name : Download LanguageTool
24+ run : |
25+ set -euo pipefail
26+ LT_VERSION="6.4"
27+ curl -fsSL -o LT.zip "https://languagetool.org/download/LanguageTool-${LT_VERSION}.zip"
28+ unzip -q LT.zip
29+ echo "LT_DIR=LanguageTool-${LT_VERSION}" >> "$GITHUB_ENV"
30+
31+ - name : Run LanguageTool on changed files
32+ env :
33+ BASE_SHA : ${{ github.event.pull_request.base.sha }}
34+ HEAD_SHA : ${{ github.event.pull_request.head.sha }}
35+ run : |
36+ set -euo pipefail
37+
38+ echo "Base: $BASE_SHA"
39+ echo "Head: $HEAD_SHA"
40+
41+ # Adjust file types as you like:
42+ mapfile -t FILES < <(git diff --name-only "$BASE_SHA" "$HEAD_SHA" \
43+ | grep -E '\.(md|rst|txt)$' || true)
44+
45+ if [ "${#FILES[@]}" -eq 0 ]; then
46+ echo "No matching files changed. Skipping."
47+ exit 0
48+ fi
49+
50+ echo "Files to check:"
51+ printf ' - %s\n' "${FILES[@]}"
52+
53+ JAR="$(ls -1 "$LT_DIR"/languagetool-commandline.jar)"
54+
55+ # Pick your language here:
56+ LANG="en-US"
57+
58+ issues=0
59+ for f in "${FILES[@]}"; do
60+ echo "-----"
61+ echo "Checking: $f"
62+ # LanguageTool returns 0 even with matches, so we count output ourselves.
63+ out="$(java -jar "$JAR" -l "$LANG" "$f" || true)"
64+ if [ -n "$out" ]; then
65+ issues=1
66+ echo "$out"
67+ else
68+ echo "OK"
69+ fi
70+ done
71+
72+ if [ "$issues" -ne 0 ]; then
73+ echo "LanguageTool found issues."
74+ exit 1
75+ fi
76+
77+ echo "No LanguageTool issues found."
You can’t perform that action at this time.
0 commit comments