Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 26 additions & 68 deletions .github/workflows/linkcheck-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,109 +146,67 @@ jobs:
--base-url ${{ steps.pr-context.outputs.deploy_url || 'https://docs.wandb.ai' }}
${{ steps.changed-files.outputs.all_changed_files || '.' }}

- name: Comment PR with link check results
if: (steps.pr-context.outputs.pr_number != '' || github.event_name == 'pull_request') && (steps.changed-files.outputs.any_changed == 'true' || github.event_name == 'workflow_dispatch')
- name: Comment on PR with results
if: steps.get-pr.outputs.pr_number && (steps.changed-files.outputs.any_changed == 'true' || github.event_name == 'workflow_dispatch')
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const prNumber = parseInt('${{ steps.get-pr.outputs.pr_number }}');
const exitCode = parseInt('${{ steps.lychee.outputs.exit_code }}') || 0;
const deployUrl = '${{ steps.pr-context.outputs.deploy_url || github.event.deployment_status.environment_url }}';

const identifier = '<!-- lychee-link-checker-comment -->';

let commentBody = identifier + '\n';

const isFork = context.payload.pull_request?.head?.repo?.fork || false;
const deployUrl = '${{ steps.pr-context.outputs.deploy_url }}';

if (${{ steps.lychee.outputs.exit_code }} === 0) {

const checkedAgainst = deployUrl || 'https://docs.wandb.ai';

if (exitCode === 0) {
// Success - no broken links
commentBody += '## 🔗 Link Checker Results\n\n';
commentBody += '✅ **All links are valid!**\n\n';
commentBody += 'No broken links were detected in the changed files.\n';
if (isFork && !deployUrl) {
commentBody += '\n_Note: Checked against production site (https://docs.wandb.ai) since preview deployments are not available for forks._\n';
}

// Check if there were redirects in the report
commentBody += 'No broken links were detected.\n';
commentBody += `\n_Checked against: ${checkedAgainst}_\n`;
} else {
// Issues found
try {
const report = fs.readFileSync('./lychee/out.md', 'utf8');
if (report.includes('Redirect') || report.includes('redirect')) {
commentBody += '\n\n> [!TIP]\n';
commentBody += '> **Redirects detected**: If you see redirects for internal docs.wandb.ai links, check if they have trailing slashes.\n';
commentBody += '> \n';
commentBody += '> Mintlify automatically removes trailing slashes, causing redirects like:\n';
commentBody += '> - `https://docs.wandb.ai/models/` → `https://docs.wandb.ai/models`\n';
commentBody += '> \n';
commentBody += '> **Fix**: Remove trailing slashes from links to avoid unnecessary redirects.\n';
}
commentBody += '## 🔗 Link Checker Results\n\n';
commentBody += '⚠️ **Some issues were detected**\n\n';
commentBody += `_Checked against: ${checkedAgainst}_\n\n`;
commentBody += '---\n\n';
commentBody += report;
} catch (e) {
// Ignore if report file doesn't exist
commentBody += '## 🔗 Link Checker Results\n\n';
commentBody += '⚠️ Link checker found issues but could not read report.\n';
}
} else {
// Issues found - include report
const report = fs.readFileSync('./lychee/out.md', 'utf8');

commentBody += '## 🔗 Link Checker Results\n\n';
commentBody += '> [!NOTE]\n';
if (isFork && !deployUrl) {
commentBody += '> This PR is from a fork, so links were checked against the **production site** (https://docs.wandb.ai).\n';
commentBody += '> \n';
commentBody += '> Links to **newly created files** in this PR will be reported as broken until the PR is merged.\n';
} else {
commentBody += '> Links to **newly created files** in this PR may be reported as broken because this checks links against the **preview deployment**.\n';
}
commentBody += '> \n';
commentBody += '> Warnings about **new** files in this PR can be safely ignored.\n\n';

// Add trailing slash tip if redirects are present
if (report.includes('Redirect') || report.includes('redirect')) {
commentBody += '> [!TIP]\n';
commentBody += '> **Redirects detected**: If you see redirects for internal docs.wandb.ai links, check if they have trailing slashes.\n';
commentBody += '> \n';
commentBody += '> Mintlify automatically removes trailing slashes, causing redirects like:\n';
commentBody += '> - `https://docs.wandb.ai/models/` → `https://docs.wandb.ai/models`\n';
commentBody += '> - `/weave/quickstart/` → `/weave/quickstart`\n';
commentBody += '> \n';
commentBody += '> **Fix**: Remove trailing slashes from links to avoid unnecessary redirects.\n\n';
}

commentBody += '---\n\n';
commentBody += report;
}

// Determine PR number
const prNumber = Number('${{ steps.pr-context.outputs.pr_number }}') ||
context.payload.pull_request?.number;

if (!prNumber) {
core.info('No PR number available, skipping comment');
return;
}

// Find existing comment
// Find and update existing comment, or create new one
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});

const existingComment = comments.find(comment =>
comment.body?.includes(identifier) && comment.user?.login === 'github-actions[bot]'
);

if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody
});
core.info(`Updated comment ${existingComment.id} on PR #${prNumber}`);
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody
});
core.info(`Created new comment on PR #${prNumber}`);
}
3 changes: 1 addition & 2 deletions .github/workflows/validate-mdx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ on:
pull_request:
push:
branches:
- '**'
- '!main'
- main
workflow_dispatch:

concurrency:
Expand Down