|
61 | 61 | - name: Build Hugo (generate pageurls) |
62 | 62 | if: steps.changed.outputs.any_changed == 'true' |
63 | 63 | run: | |
| 64 | + # Debug: Check what ref we're building |
| 65 | + echo "Current branch: $(git branch --show-current)" |
| 66 | + echo "HEAD commit: $(git rev-parse HEAD)" |
| 67 | + echo "PR head SHA: ${{ github.event.pull_request.head.sha }}" |
| 68 | + |
64 | 69 | hugo --minify |
65 | 70 | test -f public/pageurls.json && echo "Found pageurls.json" || (echo "Missing pageurls.json" && ls -la public || true) |
| 71 | + |
| 72 | + # Debug: Check a specific file's title in the generated JSON |
| 73 | + if [ -f public/pageurls.json ]; then |
| 74 | + echo "Checking for public-api entries in pageurls.json:" |
| 75 | + jq '.[] | select(.path | contains("public-api"))' public/pageurls.json || true |
| 76 | + fi |
66 | 77 |
|
67 | 78 | - name: Create or find preview comment |
68 | 79 | if: steps.changed.outputs.any_changed == 'true' |
@@ -287,13 +298,20 @@ jobs: |
287 | 298 | const rel = (p.path || '').replace(/^\/+/, '').replace(/\\/g, '/'); |
288 | 299 | const withLang = lang && !rel.startsWith(lang + '/') ? `${lang}/${rel}` : rel; |
289 | 300 | const withoutLang = lang && rel.startsWith(lang + '/') ? rel.slice(lang.length + 1) : rel; |
| 301 | + |
| 302 | + // Create all possible key variations |
290 | 303 | const keys = new Set([ |
291 | 304 | rel, |
292 | 305 | withLang, |
293 | 306 | withoutLang, |
294 | 307 | path.posix.join('content', withLang), |
295 | 308 | path.posix.join('content', withoutLang), |
| 309 | + path.posix.join('content', rel), |
| 310 | + // Add explicit handling for language in path |
| 311 | + path.posix.join('content', lang, rel), |
| 312 | + path.posix.join('content', lang, withoutLang), |
296 | 313 | ].filter(Boolean).map(k => k.replace(/\\/g, '/'))); |
| 314 | + |
297 | 315 | for (const k of keys) byPath.set(k, p); |
298 | 316 | } |
299 | 317 |
|
@@ -457,25 +475,91 @@ jobs: |
457 | 475 | return rows; |
458 | 476 | } |
459 | 477 |
|
460 | | - const addedRows = buildRows(added); |
461 | | - const modifiedRows = buildRows(modified); |
462 | | - const deletedRows = buildRows(deleted); |
| 478 | + // Calculate file sizes/changes for sorting by delta |
| 479 | + function getFileStats(files) { |
| 480 | + const { execSync } = require('child_process'); |
| 481 | + return files.map(fp => { |
| 482 | + let size = 0; |
| 483 | + try { |
| 484 | + // Use git to get the number of changed lines |
| 485 | + // For added files, count all lines; for modified, count insertions + deletions |
| 486 | + const diffStat = execSync(`git diff --numstat origin/${{ github.base_ref }}...HEAD -- "${fp}" 2>/dev/null || echo "0 0 ${fp}"`, { encoding: 'utf8' }).trim(); |
| 487 | + const parts = diffStat.split(/\s+/); |
| 488 | + if (parts.length >= 2) { |
| 489 | + const insertions = parseInt(parts[0]) || 0; |
| 490 | + const deletions = parseInt(parts[1]) || 0; |
| 491 | + size = insertions + deletions; |
| 492 | + } |
| 493 | + } catch (e) { |
| 494 | + // If git diff fails, try file size as fallback |
| 495 | + try { |
| 496 | + if (fs.existsSync(fp)) { |
| 497 | + const stats = fs.statSync(fp); |
| 498 | + size = stats.size; |
| 499 | + } |
| 500 | + } catch (e2) { |
| 501 | + // Ignore errors |
| 502 | + } |
| 503 | + } |
| 504 | + return { path: fp, size }; |
| 505 | + }); |
| 506 | + } |
| 507 | +
|
| 508 | + // Sort files by size (as a proxy for change delta) and limit to maxRows |
| 509 | + function limitAndSortFiles(files, maxRows = 20) { |
| 510 | + if (files.length <= maxRows) { |
| 511 | + return { files: files.sort(), truncated: false }; |
| 512 | + } |
| 513 | + |
| 514 | + // Get file stats and sort by size descending |
| 515 | + const stats = getFileStats(files); |
| 516 | + stats.sort((a, b) => b.size - a.size); |
| 517 | + |
| 518 | + // Take top maxRows files |
| 519 | + const topFiles = stats.slice(0, maxRows).map(s => s.path); |
| 520 | + // Sort alphabetically for consistent display |
| 521 | + topFiles.sort(); |
| 522 | + |
| 523 | + return { files: topFiles, truncated: true, total: files.length }; |
| 524 | + } |
| 525 | +
|
| 526 | + const MAX_ROWS_PER_TABLE = 20; |
| 527 | + const addedInfo = limitAndSortFiles(added, MAX_ROWS_PER_TABLE); |
| 528 | + const modifiedInfo = limitAndSortFiles(modified, MAX_ROWS_PER_TABLE); |
| 529 | + const deletedInfo = limitAndSortFiles(deleted, MAX_ROWS_PER_TABLE); |
| 530 | +
|
| 531 | + const addedRows = buildRows(addedInfo.files); |
| 532 | + const modifiedRows = buildRows(modifiedInfo.files); |
| 533 | + const deletedRows = buildRows(deletedInfo.files); |
463 | 534 |
|
464 | 535 | const header = '<!-- docs-preview-links -->\n<!-- preview-base: ' + (previewBase || '') + ' -->\n**PR Preview: Changed content**' + (previewBase ? `\n\nBase preview: ${previewBase}` : '\n\n⏳ *Links will be added automatically when Cloudflare Pages finishes deploying (typically 2-5 minutes)*'); |
465 | 536 | if (!previewBase) { |
466 | 537 | core.info('Preview base URL not available yet. Comment will be automatically updated when Cloudflare posts the Branch Preview URL.'); |
467 | 538 | } |
468 | | - function section(title, rows) { |
469 | | - if (rows.length === 0) return ''; |
470 | | - return `\n\n### ${title}\n\n| Title | Path |\n| --- | --- |\n${rows.join('\n')}`; |
| 539 | + |
| 540 | + function section(title, rows, info) { |
| 541 | + if (rows.length === 0 && !info.truncated) return ''; |
| 542 | + |
| 543 | + let sectionTitle = title; |
| 544 | + if (info.truncated) { |
| 545 | + sectionTitle += ` (showing ${rows.length} of ${info.total} files with largest changes)`; |
| 546 | + } |
| 547 | + |
| 548 | + return `\n\n### ${sectionTitle}\n\n| Title | Path |\n| --- | --- |\n${rows.join('\n')}`; |
471 | 549 | } |
472 | 550 |
|
473 | 551 | const body = [ |
474 | 552 | header, |
475 | | - section('Added', addedRows), |
476 | | - section('Modified', modifiedRows), |
477 | | - section('Deleted', deletedRows), |
| 553 | + section('Added', addedRows, addedInfo), |
| 554 | + section('Modified', modifiedRows, modifiedInfo), |
| 555 | + section('Deleted', deletedRows, deletedInfo), |
478 | 556 | ].join(''); |
| 557 | + |
| 558 | + // Check if body exceeds GitHub's limit |
| 559 | + const MAX_COMMENT_SIZE = 65536; |
| 560 | + if (body.length > MAX_COMMENT_SIZE) { |
| 561 | + core.warning(`Preview comment size (${body.length}) exceeds GitHub's limit (${MAX_COMMENT_SIZE}). This should not happen with row limits in place.`); |
| 562 | + } |
479 | 563 |
|
480 | 564 | // Update the existing comment |
481 | 565 | const commentId = process.env.COMMENT_ID; |
|
0 commit comments