diff --git a/.github/workflows/linkcheck-pr.yml b/.github/workflows/linkcheck-pr.yml index a0afa9f342..ce178b37df 100644 --- a/.github/workflows/linkcheck-pr.yml +++ b/.github/workflows/linkcheck-pr.yml @@ -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 = ''; - 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}`); } 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: