-
Notifications
You must be signed in to change notification settings - Fork 7
Add redirect checker to block PRs with deleted pages missing redirects #666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
35b2215
bd52808
f707d4d
a03941d
4142993
ea2aa5c
cc59b74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| name: Check Redirects for Deleted Pages | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| paths: | ||
| - "app/**/*.md" | ||
| - "app/**/*.mdx" | ||
| - "next.config.ts" | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| check-redirects: | ||
| name: Verify Deleted Pages Have Redirects | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 # Full history needed for branch comparison | ||
|
|
||
| - name: Fetch base branch | ||
| run: git fetch origin ${{ github.base_ref }}:${{ github.base_ref }} | ||
|
|
||
| - name: Check for missing redirects | ||
| id: check | ||
| run: | | ||
| chmod +x ./scripts/check-redirects.sh | ||
| ./scripts/check-redirects.sh ${{ github.base_ref }} 2>&1 | tee redirect-check-output.txt | ||
| continue-on-error: true | ||
|
|
||
| - name: Comment on PR if redirects are missing | ||
| if: steps.check.outcome == 'failure' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const output = fs.readFileSync('redirect-check-output.txt', 'utf8'); | ||
|
|
||
| // Extract the missing redirects and suggestions from output | ||
| const body = `## 🔗 Missing Redirects Detected | ||
|
|
||
| This PR deletes markdown files that don't have corresponding redirects in \`next.config.ts\`. | ||
|
|
||
| When you delete a page, you must add a redirect to prevent broken links for users who have bookmarked the old URL. | ||
|
|
||
| <details> | ||
| <summary>📋 View Details</summary> | ||
|
|
||
| \`\`\` | ||
| ${output} | ||
| \`\`\` | ||
|
|
||
| </details> | ||
|
|
||
| ### How to fix | ||
|
|
||
| 1. Open \`next.config.ts\` | ||
| 2. Find the \`redirects()\` function | ||
| 3. Add redirect entries for each deleted file (see suggestions above) | ||
| 4. Push the changes | ||
|
|
||
| --- | ||
| *This check ensures we maintain URL stability for our documentation.*`; | ||
|
|
||
| // Check if we already commented | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| }); | ||
|
|
||
| const botComment = comments.find(comment => | ||
| comment.user.type === 'Bot' && | ||
| comment.body.includes('Missing Redirects Detected') | ||
| ); | ||
|
|
||
| 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: context.issue.number, | ||
| body: body | ||
| }); | ||
| } | ||
|
|
||
| - name: Remove outdated comment if check passes | ||
| if: steps.check.outcome == 'success' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| }); | ||
|
|
||
| const botComment = comments.find(comment => | ||
| comment.user.type === 'Bot' && | ||
| comment.body.includes('Missing Redirects Detected') | ||
| ); | ||
|
|
||
| if (botComment) { | ||
| await github.rest.issues.deleteComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: botComment.id, | ||
| }); | ||
| } | ||
|
|
||
| - name: Fail if redirects are missing | ||
| if: steps.check.outcome == 'failure' | ||
| run: | | ||
| echo "❌ Missing redirects for deleted pages. See PR comment for details." | ||
| exit 1 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -495,6 +495,28 @@ const nextConfig: NextConfig = withLlmsTxt({ | |
| destination: "/:locale/guides/create-tools/:path*", | ||
| permanent: true, | ||
| }, | ||
| // Agent frameworks moved from guides to get-started | ||
| { | ||
| source: "/:locale/guides/agent-frameworks", | ||
| destination: "/:locale/get-started/agent-frameworks", | ||
| permanent: true, | ||
| }, | ||
| { | ||
| source: "/:locale/guides/agent-frameworks/:path*", | ||
| destination: "/:locale/get-started/agent-frameworks/:path*", | ||
| permanent: true, | ||
| }, | ||
| // MCP clients moved from guides/tool-calling to get-started | ||
| { | ||
| source: "/:locale/guides/tool-calling/mcp-clients", | ||
| destination: "/:locale/get-started/mcp-clients", | ||
| permanent: true, | ||
| }, | ||
| { | ||
| source: "/:locale/guides/tool-calling/mcp-clients/:path*", | ||
| destination: "/:locale/get-started/mcp-clients/:path*", | ||
| permanent: true, | ||
| }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New redirects create chains with existing redirect destinationsMedium Severity The new redirects from Additional Locations (2) |
||
| ]; | ||
| }, | ||
| headers: async () => [ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.