Skip to content

Commit

Permalink
feat(cli): add diff message on the number of stacks with differences (#…
Browse files Browse the repository at this point in the history
…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*
  • Loading branch information
krzysztof-slowinski authored Jul 21, 2023
1 parent 1820fc9 commit a9e2789
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 7 additions & 1 deletion packages/aws-cdk/test/diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

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

// THEN
expect(buffer.data.trim()).toContain('✨ Number of stacks with differences: 1');
expect(exitCode).toBe(1);
});

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

// THEN
expect(buffer.data.trim()).toContain('✨ Number of stacks with differences: 1');
expect(exitCode).toBe(1);
});

Expand Down Expand Up @@ -255,7 +258,10 @@ Resources
└─ [~] .Properties:
└─ [~] .Prop:
├─ [-] old-value
└─ [+] new-value`);
└─ [+] new-value
✨ Number of stacks with differences: 3`);

expect(exitCode).toBe(0);
});
Expand Down

0 comments on commit a9e2789

Please sign in to comment.