-
Notifications
You must be signed in to change notification settings - Fork 12
99 lines (85 loc) · 3.66 KB
/
link-checker.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
name: "Link Checker"
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'
jobs:
link-check:
runs-on: ubuntu-latest
steps:
# Проверка репозитория
- name: Checkout repository
uses: actions/checkout@v3
# Установка lychee
- name: Установка Lychee
run: cargo install lychee
# Запуск проверки ссылок
- name: Проверка ссылок в Markdown
id: link-check
run: lychee --output json --dump ./lychee-output.json "**/*.md" || echo "Обнаружены проблемы со ссылками."
# Отправка комментария к PR
- name: Комментарий к PR с результатами
if: always()
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const outputFile = './lychee-output.json';
if (!fs.existsSync(outputFile)) {
github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Не удалось создать отчет о проверке ссылок. Убедитесь, что Markdown файлы доступны для проверки.',
});
return;
}
const output = JSON.parse(fs.readFileSync(outputFile, 'utf8'));
if (!output.links || output.links.length === 0) {
github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '🔍 В файлах Markdown не обнаружено ссылок.',
});
return;
}
const failedLinks = output.links.filter(link => link.status !== 'Ok');
if (failedLinks.length === 0) {
github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '✅ Все ссылки в файлах Markdown корректны!',
});
return;
}
const errorDetails = failedLinks
.map(link => `- [${link.uri}](${link.uri}) (Файл: ${link.source}) → Статус: ${link.status}`)
.join('\n');
const issueComment = `
### Отчет о проверке ссылок
Обнаружены следующие проблемы со ссылками:
${errorDetails}
Пожалуйста, исправьте их перед слиянием.
`;
github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: issueComment,
});