Skip to content

Commit a9e2789

Browse files
feat(cli): add diff message on the number of stacks with differences (#26297)
Reported issue with `diff` is that it treats the fail return status for cases when there are actual diffs, making it hard to know what happened with pipeline automations. The proposed solution adds a logging statement with a similar format that is used for deploy (but here the total time is reported) specifying how many stacks have differences, as presented below. As a result, it will be possible to check in pipelines for this logging statement to correctly detect situation when there are no actual changes, when there are changes, and when there are failures, since on failures this statement will not be present: Case of no changes: ✨ Number of stacks with differences: 0 Case of changes in 5 stacks: ✨ Number of stacks with differences: 5 Closes #10417. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 1820fc9 commit a9e2789

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/aws-cdk/lib/cdk-toolkit.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ export class CdkToolkit {
143143
}
144144
}
145145

146+
stream.write(format('\n✨ Number of stacks with differences: %s\n', diffs));
147+
146148
return diffs && options.fail ? 1 : 0;
147149
}
148150

packages/aws-cdk/test/diff.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ describe('non-nested stacks', () => {
8181
expect(plainTextOutput).toContain('Stack A');
8282
expect(plainTextOutput).toContain('Stack B');
8383

84+
expect(buffer.data.trim()).toContain('✨ Number of stacks with differences: 2');
8485
expect(exitCode).toBe(0);
8586
});
8687

@@ -96,6 +97,7 @@ describe('non-nested stacks', () => {
9697
});
9798

9899
// THEN
100+
expect(buffer.data.trim()).toContain('✨ Number of stacks with differences: 1');
99101
expect(exitCode).toBe(1);
100102
});
101103

@@ -121,6 +123,7 @@ describe('non-nested stacks', () => {
121123
});
122124

123125
// THEN
126+
expect(buffer.data.trim()).toContain('✨ Number of stacks with differences: 1');
124127
expect(exitCode).toBe(1);
125128
});
126129

@@ -255,7 +258,10 @@ Resources
255258
└─ [~] .Properties:
256259
└─ [~] .Prop:
257260
├─ [-] old-value
258-
└─ [+] new-value`);
261+
└─ [+] new-value
262+
263+
264+
✨ Number of stacks with differences: 3`);
259265

260266
expect(exitCode).toBe(0);
261267
});

0 commit comments

Comments
 (0)