Skip to content

Commit 91a43cf

Browse files
committed
chore: add broken-links check
1 parent f6a6b2a commit 91a43cf

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

.github/workflows/broken-links.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Check Broken Links in MDX Files
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'mintlify/**/*.mdx'
7+
8+
permissions:
9+
contents: read
10+
pull-requests: write
11+
12+
jobs:
13+
check-broken-links:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '18'
24+
25+
- name: Install Mintlify CLI
26+
run: npm install -g mintlify
27+
28+
- name: Run broken links check
29+
id: broken-links
30+
working-directory: mintlify
31+
run: |
32+
echo "Running mint broken-links in mintlify directory..."
33+
34+
# Run broken links check and capture both stdout and stderr
35+
set +e # Don't exit on error
36+
mint broken-links &> broken-links-output.txt
37+
mint_exit_code=$?
38+
set -e # Re-enable exit on error
39+
40+
echo "mint_exit_code=$mint_exit_code" >> $GITHUB_OUTPUT
41+
42+
# Show original output for debugging
43+
echo "Original mint output:"
44+
cat broken-links-output.txt
45+
46+
# Always report success and pass through the raw output
47+
echo "has_broken_links=false" >> $GITHUB_OUTPUT
48+
echo "RAW_OUTPUT<<EOF" >> $GITHUB_OUTPUT
49+
cat broken-links-output.txt >> $GITHUB_OUTPUT
50+
echo "EOF" >> $GITHUB_OUTPUT
51+
52+
- name: Comment on PR
53+
uses: actions/github-script@v7
54+
with:
55+
script: |
56+
const rawOutput = `${{ steps.broken-links.outputs.RAW_OUTPUT }}`;
57+
58+
const body = `## 📝 Broken Links Check Report
59+
60+
The following is the output from the broken links check:
61+
62+
\`\`\`
63+
${rawOutput}
64+
\`\`\`
65+
66+
> **Note**: Entries under \`/api-reference/\` are likely false positives and can be ignored.`;
67+
68+
// Find existing comment
69+
const comments = await github.rest.issues.listComments({
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
issue_number: context.issue.number,
73+
});
74+
75+
const existingComment = comments.data.find(comment =>
76+
comment.user.login === 'github-actions[bot]' &&
77+
comment.body.includes('Broken Links Check')
78+
);
79+
80+
if (existingComment) {
81+
// Update existing comment
82+
await github.rest.issues.updateComment({
83+
owner: context.repo.owner,
84+
repo: context.repo.repo,
85+
comment_id: existingComment.id,
86+
body: body
87+
});
88+
} else {
89+
// Create new comment
90+
await github.rest.issues.createComment({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
issue_number: context.issue.number,
94+
body: body
95+
});
96+
}

0 commit comments

Comments
 (0)