From 6144a758a274b2ac87577f5985463714187d68b8 Mon Sep 17 00:00:00 2001 From: aaronmedina-dev Date: Mon, 20 Apr 2026 15:15:05 +0930 Subject: [PATCH 1/2] Truncate CDK diff PR comment when over GitHub's 65536-char limit When a CDK diff is very large (e.g. broad IAM pipeline changes), the generated PR comment body exceeds GitHub's 65536-character issue comment limit, and the Post diff to PR comment step fails with 'Body is too long'. The full diff is already uploaded as a workflow artifact, so when the comment body exceeds the safe limit it is now truncated and a notice linking to the workflow run artifacts is included instead of failing the job. --- .github/workflows/aws-cdk.yml | 65 +++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/.github/workflows/aws-cdk.yml b/.github/workflows/aws-cdk.yml index f609d10..4d6943e 100644 --- a/.github/workflows/aws-cdk.yml +++ b/.github/workflows/aws-cdk.yml @@ -613,31 +613,52 @@ jobs: const statusIcon = hasChanges ? '⚠️' : '✅'; const statusText = hasChanges ? 'Infrastructure changes detected' : 'No infrastructure changes detected'; - const lines = [ - `## ${commentHeader}`, - '', - `${statusIcon} **${statusText}**`, - '', - `**Stack:** \`${stackName}\``, - ]; - - if (environment) { - lines.push(`**Environment:** ${environment}`); + const GITHUB_COMMENT_LIMIT = 65536; + const SAFE_LIMIT = 60000; + const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${context.runId}`; + + function buildBody(diff, truncationNotice) { + const lines = [ + `## ${commentHeader}`, + '', + `${statusIcon} **${statusText}**`, + '', + `**Stack:** \`${stackName}\``, + ]; + + if (environment) { + lines.push(`**Environment:** ${environment}`); + } + + if (truncationNotice) { + lines.push('', truncationNotice); + } + + lines.push( + '', + '
', + `Full diff${truncationNotice ? ' (truncated)' : ''}`, + '', + '```', + diff, + '```', + '', + '
' + ); + + return lines.join('\n'); } - lines.push( - '', - '
', - 'Full diff', - '', - '```', - diffContent, - '```', - '', - '
' - ); + let commentBody = buildBody(diffContent, null); - const commentBody = lines.join('\n'); + if (commentBody.length > SAFE_LIMIT) { + const originalLength = commentBody.length; + const truncationNotice = `**Note:** Diff output exceeded GitHub's ${GITHUB_COMMENT_LIMIT}-character comment limit (${originalLength} chars). Download the full diff from the [workflow run artifacts](${runUrl}).`; + const overhead = buildBody('', truncationNotice).length; + const availableForDiff = Math.max(0, SAFE_LIMIT - overhead - 20); + const truncatedDiff = diffContent.slice(0, availableForDiff) + '\n...[truncated]'; + commentBody = buildBody(truncatedDiff, truncationNotice); + } const comments = await github.rest.issues.listComments({ owner, repo, issue_number, From f73a72bdbe3cd79f6140d4519ba3ffc424be7375 Mon Sep 17 00:00:00 2001 From: aaronmedina-dev Date: Mon, 20 Apr 2026 15:23:42 +0930 Subject: [PATCH 2/2] Split long truncation notice line to satisfy yamllint 120-char limit --- .github/workflows/aws-cdk.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/aws-cdk.yml b/.github/workflows/aws-cdk.yml index 4d6943e..e60e0a6 100644 --- a/.github/workflows/aws-cdk.yml +++ b/.github/workflows/aws-cdk.yml @@ -653,7 +653,11 @@ jobs: if (commentBody.length > SAFE_LIMIT) { const originalLength = commentBody.length; - const truncationNotice = `**Note:** Diff output exceeded GitHub's ${GITHUB_COMMENT_LIMIT}-character comment limit (${originalLength} chars). Download the full diff from the [workflow run artifacts](${runUrl}).`; + const truncationNotice = [ + `**Note:** Diff output exceeded GitHub's ${GITHUB_COMMENT_LIMIT}-character`, + `comment limit (${originalLength} chars).`, + `Download the full diff from the [workflow run artifacts](${runUrl}).`, + ].join(' '); const overhead = buildBody('', truncationNotice).length; const availableForDiff = Math.max(0, SAFE_LIMIT - overhead - 20); const truncatedDiff = diffContent.slice(0, availableForDiff) + '\n...[truncated]';