forked from langchain-ai/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-removed-pages-redirects.yml
More file actions
113 lines (96 loc) · 3.35 KB
/
check-removed-pages-redirects.yml
File metadata and controls
113 lines (96 loc) · 3.35 KB
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
---
name: Check removed pages have redirects
on:
pull_request:
branches: [main]
jobs:
check-redirects:
name: Verify docs.json (redirects + pages exist)
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Fetch base branch
run: git fetch origin "${{ github.base_ref }}"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Get base branch docs.json
run: |
BASE_REF="${{ github.event.pull_request.base.sha }}"
if [ -z "$BASE_REF" ]; then
BASE_REF="origin/${{ github.base_ref }}"
fi
git show "${BASE_REF}:src/docs.json" > base_docs.json
- name: Run docs.json checks
id: check
run: |
set +e
python scripts/check_removed_pages_redirects.py base_docs.json src/docs.json 2> check_output.txt
EXIT_CODE=$?
set -e
echo "exit_code=${EXIT_CODE}" >> $GITHUB_OUTPUT
if [ $EXIT_CODE -eq 0 ]; then
echo "✅ All pages exist and removed pages have redirects"
else
cat check_output.txt
fi
- name: Comment on PR on failure
if: steps.check.outputs.exit_code == '1'
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
let output = '';
try {
output = fs.readFileSync('check_output.txt', 'utf8');
output = output.replace(/[^\x20-\x7E\n\r\t]/g, '');
if (output.length > 32000) {
output = output.substring(0, 32000) + '\n... (truncated)';
}
} catch (error) {
output = 'Error reading check output';
}
const body = `## ❌ docs.json validation failed
This PR has issues with \`docs.json\`: either pages were removed without redirects, or some pages reference non-existent source files.
\`\`\`
${output}
\`\`\`
`;
const prNumber = context.payload.pull_request.number;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const botComment = comments.data.find(comment =>
comment.user?.type === 'Bot' &&
comment.body.includes('docs.json validation failed')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body
});
}
- name: Fail if docs.json validation failed
if: steps.check.outputs.exit_code == '1'
run: |
echo "❌ Please fix docs.json issues (see PR comment for details)"
exit 1