From a9e2789d2f927c26db0aee4ce7cb2cc073a99bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20S=C5=82owi=C5=84ski?= <30654022+krzysztof-slowinski@users.noreply.github.com> Date: Fri, 21 Jul 2023 16:48:51 +0200 Subject: [PATCH] feat(cli): add diff message on the number of stacks with differences (#26297) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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* --- packages/aws-cdk/lib/cdk-toolkit.ts | 2 ++ packages/aws-cdk/test/diff.test.ts | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk/lib/cdk-toolkit.ts b/packages/aws-cdk/lib/cdk-toolkit.ts index 70d7650f58f7b..e5ff7cc642af3 100644 --- a/packages/aws-cdk/lib/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cdk-toolkit.ts @@ -143,6 +143,8 @@ export class CdkToolkit { } } + stream.write(format('\n✨ Number of stacks with differences: %s\n', diffs)); + return diffs && options.fail ? 1 : 0; } diff --git a/packages/aws-cdk/test/diff.test.ts b/packages/aws-cdk/test/diff.test.ts index 128c933dad245..ad8202a64db63 100644 --- a/packages/aws-cdk/test/diff.test.ts +++ b/packages/aws-cdk/test/diff.test.ts @@ -81,6 +81,7 @@ describe('non-nested stacks', () => { expect(plainTextOutput).toContain('Stack A'); expect(plainTextOutput).toContain('Stack B'); + expect(buffer.data.trim()).toContain('✨ Number of stacks with differences: 2'); expect(exitCode).toBe(0); }); @@ -96,6 +97,7 @@ describe('non-nested stacks', () => { }); // THEN + expect(buffer.data.trim()).toContain('✨ Number of stacks with differences: 1'); expect(exitCode).toBe(1); }); @@ -121,6 +123,7 @@ describe('non-nested stacks', () => { }); // THEN + expect(buffer.data.trim()).toContain('✨ Number of stacks with differences: 1'); expect(exitCode).toBe(1); }); @@ -255,7 +258,10 @@ Resources └─ [~] .Properties: └─ [~] .Prop: ├─ [-] old-value - └─ [+] new-value`); + └─ [+] new-value + + +✨ Number of stacks with differences: 3`); expect(exitCode).toBe(0); });