Skip to content

Commit 515db83

Browse files
committed
chore: add broken-links check
1 parent f6a6b2a commit 515db83

File tree

3 files changed

+148
-2
lines changed

3 files changed

+148
-2
lines changed

.github/workflows/broken-links.yml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: Check Broken Links
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'mintlify/**/*.mdx'
7+
types: [opened, synchronize, reopened]
8+
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
13+
jobs:
14+
check-broken-links:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
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: Check for broken links
29+
id: broken-links
30+
working-directory: mintlify
31+
run: |
32+
echo "🔍 Running mint broken-links check..."
33+
echo "📂 Current working directory: $(pwd)"
34+
echo "📋 Files in current directory:"
35+
ls -la
36+
echo "---"
37+
38+
# Check if docs.json exists
39+
if [ -f "docs.json" ]; then
40+
echo "✅ docs.json found"
41+
else
42+
echo "❌ docs.json NOT found"
43+
fi
44+
45+
# Run mint broken-links and capture output and exit code
46+
set +e # Allow command to fail without exiting script
47+
OUTPUT=$(mint broken-links 2>&1)
48+
MINT_EXIT_CODE=$?
49+
set -e # Re-enable exit on error
50+
51+
echo "🔢 Mint exit code: $MINT_EXIT_CODE"
52+
53+
echo "📋 Raw mint output:"
54+
echo "$OUTPUT"
55+
echo "---"
56+
57+
# Filter out /api-reference/ false positives
58+
FILTERED_OUTPUT=$(echo "$OUTPUT" | grep -v "/api-reference/" || true)
59+
60+
echo "📋 Filtered output (excluding /api-reference/):"
61+
echo "$FILTERED_OUTPUT"
62+
echo "---"
63+
64+
# Count real broken links (excluding the summary line)
65+
BROKEN_LINES=$(echo "$FILTERED_OUTPUT" | grep -E "^\s+/" || true)
66+
echo "📋 Lines matching broken link pattern:"
67+
echo "'$BROKEN_LINES'"
68+
echo "---"
69+
70+
# More robust counting logic
71+
if [ -z "$BROKEN_LINES" ] || [ "$BROKEN_LINES" = "" ]; then
72+
BROKEN_COUNT=0
73+
echo "🔢 No broken link lines found, count: 0"
74+
else
75+
BROKEN_COUNT=$(echo "$BROKEN_LINES" | wc -l | tr -d ' ')
76+
echo "🔢 Raw count from wc -l: '$BROKEN_COUNT'"
77+
fi
78+
79+
echo "🔢 Final broken link count: '$BROKEN_COUNT'"
80+
81+
# Save results to GitHub outputs
82+
echo "broken_count=$BROKEN_COUNT" >> $GITHUB_OUTPUT
83+
84+
# Save filtered output to file for PR comment
85+
if [ "$BROKEN_COUNT" -gt 0 ]; then
86+
echo "❌ Found $BROKEN_COUNT broken link(s)"
87+
echo "$FILTERED_OUTPUT" > broken_links_output.txt
88+
echo "has_broken_links=true" >> $GITHUB_OUTPUT
89+
else
90+
echo "✅ No broken links found"
91+
echo "✅ No broken links found" > broken_links_output.txt
92+
echo "has_broken_links=false" >> $GITHUB_OUTPUT
93+
fi
94+
95+
- name: Comment on PR
96+
uses: actions/github-script@v7
97+
with:
98+
script: |
99+
const fs = require('fs');
100+
const brokenCount = '${{ steps.broken-links.outputs.broken_count }}';
101+
const hasBrokenLinks = '${{ steps.broken-links.outputs.has_broken_links }}' === 'true';
102+
103+
let comment;
104+
if (hasBrokenLinks) {
105+
const output = fs.readFileSync('mintlify/broken_links_output.txt', 'utf8');
106+
comment = `## 🔗 Broken Links Found\n\n${brokenCount} broken link(s) detected:\n\n\`\`\`\n${output}\`\`\`\n\n⚠️ Please fix these broken links before merging.`;
107+
} else {
108+
const output = fs.readFileSync('mintlify/broken_links_output.txt', 'utf8');
109+
comment = `## ✅ Link Check Passed\n\n${output}`;
110+
}
111+
112+
// Find existing comment
113+
const { data: comments } = await github.rest.issues.listComments({
114+
owner: context.repo.owner,
115+
repo: context.repo.repo,
116+
issue_number: context.issue.number,
117+
});
118+
119+
const existingComment = comments.find(comment =>
120+
comment.body.includes('🔗 Broken Links Found') ||
121+
comment.body.includes('✅ Link Check Passed')
122+
);
123+
124+
if (existingComment) {
125+
// Update existing comment
126+
await github.rest.issues.updateComment({
127+
owner: context.repo.owner,
128+
repo: context.repo.repo,
129+
comment_id: existingComment.id,
130+
body: comment
131+
});
132+
} else {
133+
// Create new comment
134+
await github.rest.issues.createComment({
135+
owner: context.repo.owner,
136+
repo: context.repo.repo,
137+
issue_number: context.issue.number,
138+
body: comment
139+
});
140+
}
141+
142+
- name: Fail if broken links found
143+
if: steps.broken-links.outputs.has_broken_links == 'true'
144+
run: |
145+
echo "❌ ${{ steps.broken-links.outputs.broken_count }} broken link(s) found"
146+
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)