Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 48 additions & 23 deletions .github/workflows/aws-cdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'',
'<details>',
`<summary>Full diff${truncationNotice ? ' (truncated)' : ''}</summary>`,
'',
'```',
diff,
'```',
'',
'</details>'
);

return lines.join('\n');
}

lines.push(
'',
'<details>',
'<summary>Full diff</summary>',
'',
'```',
diffContent,
'```',
'',
'</details>'
);

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,
Expand Down