Skip to content

Commit 06b0d6b

Browse files
committed
chore: add broken-links check
1 parent f6a6b2a commit 06b0d6b

File tree

3 files changed

+130
-2
lines changed

3 files changed

+130
-2
lines changed

.github/workflows/broken-links.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
# Filter out /api-reference/ false positives
47+
grep -v "/api-reference/" broken-links-output.txt > filtered-output.txt || true
48+
49+
# Count non-empty lines in filtered output (excluding the header and empty lines)
50+
filtered_line_count=$(grep -c . filtered-output.txt || echo "0")
51+
52+
# Check if there are any remaining broken links
53+
# We need to account for the "Checking for broken links..." line and count line
54+
if [ "$filtered_line_count" -gt 2 ]; then
55+
echo "has_broken_links=true" >> $GITHUB_OUTPUT
56+
echo "FILTERED_OUTPUT<<EOF" >> $GITHUB_OUTPUT
57+
cat filtered-output.txt >> $GITHUB_OUTPUT
58+
echo "EOF" >> $GITHUB_OUTPUT
59+
else
60+
echo "has_broken_links=false" >> $GITHUB_OUTPUT
61+
echo "FILTERED_OUTPUT=✅ No broken links found (after filtering out /api-reference/ paths)" >> $GITHUB_OUTPUT
62+
fi
63+
64+
- name: Comment on PR
65+
uses: actions/github-script@v7
66+
with:
67+
script: |
68+
const hasBrokenLinks = '${{ steps.broken-links.outputs.has_broken_links }}' === 'true';
69+
const filteredOutput = `${{ steps.broken-links.outputs.FILTERED_OUTPUT }}`;
70+
71+
let body;
72+
if (hasBrokenLinks) {
73+
body = `## 🔗 Broken Links Check Failed
74+
75+
The following broken links were found in the MDX files (after filtering out \`/api-reference/\` paths):
76+
77+
\`\`\`
78+
${filteredOutput}
79+
\`\`\`
80+
81+
Please fix these broken links before merging.
82+
83+
> **Note**: Links under \`/api-reference/\` are automatically filtered out as they may be false positives.`;
84+
} else {
85+
body = `## ✅ Broken Links Check Passed
86+
87+
${filteredOutput}
88+
89+
All MDX files in the \`mintlify/\` directory have been checked for broken links.
90+
91+
> **Note**: Links under \`/api-reference/\` are automatically filtered out as they may be false positives.`;
92+
}
93+
94+
// Find existing comment
95+
const comments = await github.rest.issues.listComments({
96+
owner: context.repo.owner,
97+
repo: context.repo.repo,
98+
issue_number: context.issue.number,
99+
});
100+
101+
const existingComment = comments.data.find(comment =>
102+
comment.user.login === 'github-actions[bot]' &&
103+
comment.body.includes('Broken Links Check')
104+
);
105+
106+
if (existingComment) {
107+
// Update existing comment
108+
await github.rest.issues.updateComment({
109+
owner: context.repo.owner,
110+
repo: context.repo.repo,
111+
comment_id: existingComment.id,
112+
body: body
113+
});
114+
} else {
115+
// Create new comment
116+
await github.rest.issues.createComment({
117+
owner: context.repo.owner,
118+
repo: context.repo.repo,
119+
issue_number: context.issue.number,
120+
body: body
121+
});
122+
}
123+
124+
- name: Fail if broken links found
125+
if: steps.broken-links.outputs.has_broken_links == 'true'
126+
run: |
127+
echo "Broken links found after filtering out /api-reference/ paths!"
128+
exit 1

mintlify/change-database/troubleshoot.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Troubleshoot
66

77
This happens if a migration version has already completed successfully and you are trying to apply the same version. Once the migration is successful, its version string is occupied and can't be reused. You can still retry the failed migration.
88

9-
This error is more common in GitOps flow when you try to modify an existing migration file. Refer to the [GitOps troubleshoot](/change-database/troubleshoot#duplicate-version)
9+
This error is more common in GitOps flow when you try to modify an existing migration file. Refer to the [GitOps troubleshoot](/change-database/troubleshoot1#duplicate-version)
1010
to learn the correct workflow.
1111

1212
## PostgreSQL

mintlify/snippets/install/install-upgrade.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Install and Upgrade
44

55
## ⚙️ Install and Upgrade
66

7-
- Fresh install: [/get-started/self-host/deploy-with-docker](/get-started/self-host/deploy-with-docker)
7+
- Fresh install: [/get-started/self-host/deploy-with-docker](/get-started/self-2host/deploy-with-docker)
88

99
- Upgrade: [/get-started/self-host/upgrade](/get-started/self-host/upgrade)
1010

0 commit comments

Comments
 (0)