-
Notifications
You must be signed in to change notification settings - Fork 12
135 lines (114 loc) · 4.55 KB
/
grammar-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: "Grammar & Punctuation Check (RU)"
on:
pull_request:
paths:
- '00_Правила_оформления/**/*.md'
- '01_Вселенная/**/*.md'
- '02_Станция/**/*.md'
- '03_Государства/**/*.md'
- '04_Корпорации/**/*.md'
- '05_Организации/**/*.md'
- '06_Расы/**/*.md'
- '07_Существа/**/*.md'
- '08_Технологии/**/*.md'
- '09_Вооружение/**/*.md'
- '10_Явления/**/*.md'
- '11_Товары/**/*.md'
- '12_Другое/**/*.md'
- '13_Истории/**/*.md'
- '14_Повседневность/**/*.md'
- 'README.md'
- 'LICENSE.md'
jobs:
grammar-check:
runs-on: ubuntu-latest
steps:
# 1. Клонируем репозиторий, но с полным fetch
- name: Check out the code
uses: actions/checkout@v3
with:
fetch-depth: 0
# 2. Устанавливаем Java
- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
# 3. Устанавливаем Pandoc
- name: Install Pandoc
run: |
sudo apt-get update
sudo apt-get install -y pandoc
# 4. Скачиваем LanguageTool (v6.5)
- name: Download LanguageTool
run: |
wget https://languagetool.org/download/LanguageTool-6.5.zip -O lt.zip
unzip lt.zip -d lt
# 5. Отключаем экранирование путей в Git (важно для кириллических файлов!)
- name: Disable Git path quoting
run: git config core.quotepath off
# 6. Собственно проверка .md-файлов
- name: Run grammar check (RU) with Pandoc
id: run_languagetool
run: |
# SHAs для diff
BASE_SHA=${{ github.event.pull_request.base.sha }}
HEAD_SHA=${{ github.event.pull_request.head.sha }}
# Получаем список изменённых .md-файлов
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT $BASE_SHA $HEAD_SHA | grep '\.md$' || true)
if [ -z "$CHANGED_FILES" ]; then
echo "No changed .md files to check."
echo "" > grammar_output.txt
exit 0
fi
echo "Changed markdown files:"
echo "$CHANGED_FILES"
# Очищаем/создаём общий файл вывода
rm -f grammar_output.txt
touch grammar_output.txt
for FILE in $CHANGED_FILES; do
echo "--------------------------------" >> grammar_output.txt
echo "Проверка файла: $FILE" >> grammar_output.txt
echo "" >> grammar_output.txt
# 1) MD -> plain text (Pandoc)
pandoc "$FILE" -t plain -o /tmp/conversion.txt
# 2) Запуск LanguageTool CLI
java -jar lt/LanguageTool-6.5/languagetool-commandline.jar \
--language ru \
--mothertongue ru \
/tmp/conversion.txt \
>> grammar_output.txt \
|| true
echo "" >> grammar_output.txt
done
# 7. Публикуем результаты в PR
- name: Create PR comment with suggestions
if: always()
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const path = 'grammar_output.txt';
if (!fs.existsSync(path)) {
core.setOutput('No grammar output file found.');
return;
}
const suggestions = fs.readFileSync(path, 'utf8');
if (!suggestions.trim()) {
core.setOutput('No grammar issues found.');
return;
}
// Ограничение на размер комментария (60к символов)
const maxLength = 60000;
let trimmed = suggestions;
if (trimmed.length > maxLength) {
trimmed = trimmed.substring(0, maxLength) +
"\n\n[...ВЫВОД ОТРЕЗАН ПОСЛЕ 60К СИМВОЛОВ...]";
}
const body = `## LanguageTool (RU) — Проверка грамматики\n\n\`\`\`\n${trimmed}\n\`\`\``;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});