From 13c9e77ced522398a3acf69f16e328ea2b585131 Mon Sep 17 00:00:00 2001 From: Matt Linville Date: Fri, 16 Jan 2026 12:33:08 -0800 Subject: [PATCH 1/3] Add PR commenting to link checker workflow This adds functionality to automatically comment on PRs with link checker results when the Mintlify deployment completes. The comment will be updated on subsequent runs and clearly indicates whether all links are valid or if issues were found. --- .github/workflows/linkcheck-pr.yml | 118 ++++++++++++----------------- 1 file changed, 49 insertions(+), 69 deletions(-) diff --git a/.github/workflows/linkcheck-pr.yml b/.github/workflows/linkcheck-pr.yml index e6a473b4b6..78a7c319ef 100644 --- a/.github/workflows/linkcheck-pr.yml +++ b/.github/workflows/linkcheck-pr.yml @@ -87,6 +87,30 @@ jobs: **/*.md **/*.mdx + - name: Get PR number from deployment + id: get-pr + uses: actions/github-script@v8 + with: + script: | + const sha = context.payload.deployment.sha; + + // Find PR(s) associated with this deployment commit SHA + const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ + owner: context.repo.owner, + repo: context.repo.repo, + commit_sha: sha, + }); + + const pr = prs[0]; + if (pr) { + core.info(`Found PR #${pr.number}`); + core.setOutput('pr_number', pr.number); + return pr.number; + } else { + core.warning(`No PR found for commit ${sha}`); + return null; + } + - name: Link Checker id: lychee if: steps.changed-files.outputs.any_changed == 'true' || github.event_name == 'workflow_dispatch' @@ -105,109 +129,65 @@ 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') - uses: actions/github-script@v7 + - name: Comment on PR with results + if: steps.get-pr.outputs.pr_number + uses: actions/github-script@v8 with: script: | const fs = require('fs'); + const prNumber = parseInt('${{ steps.get-pr.outputs.pr_number }}'); + const exitCode = ${{ steps.lychee.outputs.exit_code }}; + const deployUrl = '${{ github.event.deployment_status.environment_url }}'; + const identifier = ''; - 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) { + + 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 deployment: ${deployUrl}_\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 deployment: ${deployUrl}_\n\n`; + commentBody += '---\n\n'; + commentBody += report; } catch (e) { - // Ignore if report file doesn't exist - } - } 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 += '## 🔗 Link Checker Results\n\n'; + commentBody += '⚠️ Link checker found issues but could not read report.\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}`); } From b98b6377ab86808844c5ae283a77376b9070ee8f Mon Sep 17 00:00:00 2001 From: Matt Linville Date: Fri, 16 Jan 2026 12:58:53 -0800 Subject: [PATCH 2/3] Fix syntax errors in link checker PR comment step - Fix JavaScript syntax error when exit_code is empty - Handle both pull_request and deployment_status events properly - Use safe string interpolation for exit code - Fallback to docs.wandb.ai when no deployment URL available --- .github/workflows/linkcheck-pr.yml | 63 +++++++++++++++++++----------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/.github/workflows/linkcheck-pr.yml b/.github/workflows/linkcheck-pr.yml index 78a7c319ef..97e30edec3 100644 --- a/.github/workflows/linkcheck-pr.yml +++ b/.github/workflows/linkcheck-pr.yml @@ -87,29 +87,46 @@ jobs: **/*.md **/*.mdx - - name: Get PR number from deployment + - name: Get PR number id: get-pr uses: actions/github-script@v8 with: script: | - const sha = context.payload.deployment.sha; - - // Find PR(s) associated with this deployment commit SHA - const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ - owner: context.repo.owner, - repo: context.repo.repo, - commit_sha: sha, - }); + // For pull_request events, get PR number directly + if (context.eventName === 'pull_request') { + const prNumber = context.payload.pull_request.number; + core.info(`PR number from pull_request event: ${prNumber}`); + core.setOutput('pr_number', prNumber); + return prNumber; + } - const pr = prs[0]; - if (pr) { - core.info(`Found PR #${pr.number}`); - core.setOutput('pr_number', pr.number); - return pr.number; - } else { - core.warning(`No PR found for commit ${sha}`); - return null; + // For deployment_status events, find PR from commit SHA + if (context.eventName === 'deployment_status') { + const sha = context.payload.deployment?.sha; + if (!sha) { + core.warning('No deployment SHA found'); + return null; + } + + const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ + owner: context.repo.owner, + repo: context.repo.repo, + commit_sha: sha, + }); + + const pr = prs[0]; + if (pr) { + core.info(`Found PR #${pr.number} for deployment`); + core.setOutput('pr_number', pr.number); + return pr.number; + } else { + core.warning(`No PR found for commit ${sha}`); + return null; + } } + + core.warning(`Unsupported event type: ${context.eventName}`); + return null; - name: Link Checker id: lychee @@ -130,31 +147,33 @@ jobs: ${{ steps.changed-files.outputs.all_changed_files || '.' }} - name: Comment on PR with results - if: steps.get-pr.outputs.pr_number + 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 = ${{ steps.lychee.outputs.exit_code }}; - const deployUrl = '${{ github.event.deployment_status.environment_url }}'; + 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 = ''; let commentBody = identifier + '\n'; + 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.\n'; - commentBody += `\n_Checked deployment: ${deployUrl}_\n`; + commentBody += `\n_Checked against: ${checkedAgainst}_\n`; } else { // Issues found try { const report = fs.readFileSync('./lychee/out.md', 'utf8'); commentBody += '## 🔗 Link Checker Results\n\n'; commentBody += '⚠️ **Some issues were detected**\n\n'; - commentBody += `_Checked deployment: ${deployUrl}_\n\n`; + commentBody += `_Checked against: ${checkedAgainst}_\n\n`; commentBody += '---\n\n'; commentBody += report; } catch (e) { From 9f0c7ea3f205a92da4ade907ac88f71c7219830f Mon Sep 17 00:00:00 2001 From: Matt Linville Date: Fri, 16 Jan 2026 13:06:45 -0800 Subject: [PATCH 3/3] Prevent duplicate MDX validation runs on PR branches Change push trigger to only run on main branch. This prevents duplicate workflow runs when pushing to PR branches (which triggers both push and pull_request events). Now: - PRs: validated via pull_request trigger - Main branch: validated via push trigger - Manual: workflow_dispatch still available --- .github/workflows/validate-mdx.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/validate-mdx.yml b/.github/workflows/validate-mdx.yml index a16888bd65..8738c6b091 100644 --- a/.github/workflows/validate-mdx.yml +++ b/.github/workflows/validate-mdx.yml @@ -3,8 +3,7 @@ on: pull_request: push: branches: - - '**' - - '!main' + - main workflow_dispatch: concurrency: