Skip to content

Commit 1dead7f

Browse files
author
Kill_Me_I_Noobs
authored
linkchecker fix (space-station-lore#46)
1 parent a586059 commit 1dead7f

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

.github/workflows/link-checker.yml

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,74 +24,87 @@ jobs:
2424
runs-on: ubuntu-latest
2525

2626
steps:
27-
# Проверка репозитория
2827
- name: Checkout repository
2928
uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Fetch PR head branch
33+
run: |
34+
git remote add pr "${{ github.event.pull_request.head.repo.clone_url }}"
35+
git fetch pr "${{ github.event.pull_request.head.ref }}"
3036
31-
# Установка lychee
32-
- name: Установка Lychee
33-
run: cargo install lychee
37+
- name: Extract added lines from changed Markdown files
38+
run: |
39+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
40+
HEAD_REF="${{ github.event.pull_request.head.ref }}"
41+
# Сравнение базовой ветки с PR-веткой только для Markdown файлов
42+
git diff "$BASE_SHA" "pr/$HEAD_REF" -- "*.md" > diff.txt
43+
# Извлекаем только строки, добавленные в PR (начинаются с '+' но не с '+++')
44+
grep '^+' diff.txt | grep -v '^+++' > added-links.md
45+
echo "Содержимое добавленных строк:"
46+
cat added-links.md
3447
35-
# Запуск проверки ссылок
36-
- name: Проверка ссылок в Markdown
37-
id: link-check
38-
run: lychee --output json --dump ./lychee-output.json "**/*.md" || echo "Обнаружены проблемы со ссылками."
48+
- name: Run lychee on added links
49+
id: run-lychee
50+
run: |
51+
if [ ! -s added-links.md ]; then
52+
echo "No added lines found."
53+
# Создаем пустой JSON, чтобы дальнейший шаг мог корректно отработать
54+
echo '{"links": []}' > lychee-output.json
55+
else
56+
# Передаем содержимое файла через STDIN в lychee
57+
cat added-links.md | lychee --output json --dump ./lychee-output.json || echo "Обнаружены проблемы со ссылками."
58+
fi
3959
40-
# Отправка комментария к PR
41-
- name: Комментарий к PR с результатами
60+
- name: Post PR comment with link check results
4261
if: always()
4362
uses: actions/github-script@v6
4463
with:
4564
script: |
4665
const fs = require('fs');
4766
const outputFile = './lychee-output.json';
48-
4967
if (!fs.existsSync(outputFile)) {
50-
github.rest.issues.createComment({
68+
await github.rest.issues.createComment({
5169
issue_number: context.payload.pull_request.number,
5270
owner: context.repo.owner,
5371
repo: context.repo.repo,
5472
body: 'Не удалось создать отчет о проверке ссылок. Убедитесь, что Markdown файлы доступны для проверки.',
5573
});
5674
return;
5775
}
58-
5976
const output = JSON.parse(fs.readFileSync(outputFile, 'utf8'));
6077
if (!output.links || output.links.length === 0) {
61-
github.rest.issues.createComment({
78+
await github.rest.issues.createComment({
6279
issue_number: context.payload.pull_request.number,
6380
owner: context.repo.owner,
6481
repo: context.repo.repo,
65-
body: '🔍 В файлах Markdown не обнаружено ссылок.',
82+
body: '🔍 В добавленном тексте не обнаружено ссылок или все ссылки корректны.',
6683
});
6784
return;
6885
}
69-
7086
const failedLinks = output.links.filter(link => link.status !== 'Ok');
7187
if (failedLinks.length === 0) {
72-
github.rest.issues.createComment({
88+
await github.rest.issues.createComment({
7389
issue_number: context.payload.pull_request.number,
7490
owner: context.repo.owner,
7591
repo: context.repo.repo,
76-
body: '✅ Все ссылки в файлах Markdown корректны!',
92+
body: '✅ Все ссылки в добавленном тексте корректны!',
7793
});
7894
return;
7995
}
80-
8196
const errorDetails = failedLinks
8297
.map(link => `- [${link.uri}](${link.uri}) (Файл: ${link.source}) → Статус: ${link.status}`)
8398
.join('\n');
84-
8599
const issueComment = `
86-
### Отчет о проверке ссылок
87-
Обнаружены следующие проблемы со ссылками:
100+
### Отчет о проверке ссылок
101+
Обнаружены следующие проблемы со ссылками в добавленном тексте:
88102

89-
${errorDetails}
103+
${errorDetails}
90104

91-
Пожалуйста, исправьте их перед слиянием.
105+
Пожалуйста, исправьте их перед слиянием.
92106
`;
93-
94-
github.rest.issues.createComment({
107+
await github.rest.issues.createComment({
95108
issue_number: context.payload.pull_request.number,
96109
owner: context.repo.owner,
97110
repo: context.repo.repo,

0 commit comments

Comments
 (0)