diff --git a/.github/workflows/aws-cdk.yml b/.github/workflows/aws-cdk.yml
index f609d10..e60e0a6 100644
--- a/.github/workflows/aws-cdk.yml
+++ b/.github/workflows/aws-cdk.yml
@@ -613,31 +613,56 @@ 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,
- '```',
- '',
- ' '
- );
-
- const commentBody = lines.join('\n');
+ let commentBody = buildBody(diffContent, null);
+
+ 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}).`,
+ ].join(' ');
+ 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,