-
Notifications
You must be signed in to change notification settings - Fork 12
171 lines (144 loc) · 6.03 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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;
}
const files = suggestions.split('--------------------------------\n');
const comments = [];
for (const fileData of files) {
if (!fileData.trim()) continue;
const lines = fileData.trim().split('\n');
const fileNameMatch = lines[0].match(/Проверка файла: (.*)/);
if (!fileNameMatch) continue;
const fileName = fileNameMatch[1];
const content = lines.slice(2).join('\n');
if (content.trim()) {
const commentBody = `<details><summary>Грамматические замечания для <code>${fileName}</code></summary>\n\n\`\`\`\n${content.trim()}\n\`\`\`\n</details>`;
comments.push(commentBody);
}
}
// Ограничение на количество комментариев (50)
const maxComments = 50;
let currentComment = "";
let commentCounter = 0;
for (const comment of comments) {
if (commentCounter < maxComments){
currentComment += comment + "\n\n";
}
else {
const body = `## LanguageTool (RU) — Проверка грамматики\n\n${currentComment}`
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
currentComment = comment + "\n\n"
commentCounter = 0;
}
commentCounter++;
}
if (currentComment) {
const body = `## LanguageTool (RU) — Проверка грамматики\n\n${currentComment}`
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
}