Skip to content

Commit 150bf83

Browse files
committed
chore: add broken-links check
1 parent f6a6b2a commit 150bf83

File tree

3 files changed

+129
-2
lines changed

3 files changed

+129
-2
lines changed

.github/workflows/broken-links.yml

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