Skip to content

Commit 5631014

Browse files
authored
fix(cli): cannot set progress via app or user configuration (#231)
In [v2.172.0](https://github.com/aws/aws-cdk/releases/tag/v2.172.0) (via aws/aws-cdk@069b72c) we accidentally broke the "bar" stack activity progress output mode (*). Turns out no-one noticed. In [v2.1002.0](https://github.com/aws/aws-cdk-cli/releases/tag/aws-cdk%40v2.1002.0) (via 0d9912f) this got unintentionally fixed and the `--progress` was honored again. However the accidental fix didn't consider options set by app or user configuration. Again noone really noticed, until this week a user alerted my to the issue on the cdk.dev Slack. This PR fixes `progress` set via app or user configuration. (*) This line is the culprit: aws/aws-cdk@069b72c#diff-d03bd87f399ba5824d5442aa691df8b6f08f4f8a3848cfc8492c3d52fab5e48bR105 Previously "default" verbosity was a `0`, which meant `verbose = 0` and later on `!verbose` would turn into `true`. The change caused `verbose` to be a value different than `0` and thus turning `!verbose` to be `false` and the code would always assume we are in verbose logging mode and must use the "events" progress. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 3791941 commit 5631014

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

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

+10
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ export class CdkToolkit {
294294
return this.watch(options);
295295
}
296296

297+
// set progress from options, this includes user and app config
298+
if (options.progress) {
299+
this.ioHost.stackProgress = options.progress;
300+
}
301+
297302
const startSynthTime = new Date().getTime();
298303
const stackCollection = await this.selectStacksForDeploy(
299304
options.selector,
@@ -760,6 +765,11 @@ export class CdkToolkit {
760765
public async import(options: ImportOptions) {
761766
const stacks = await this.selectStacksForDeploy(options.selector, true, true, false);
762767

768+
// set progress from options, this includes user and app config
769+
if (options.progress) {
770+
this.ioHost.stackProgress = options.progress;
771+
}
772+
763773
if (stacks.stackCount > 1) {
764774
throw new ToolkitError(
765775
`Stack selection is ambiguous, please choose a specific stack for import [${stacks.stackArtifacts.map((x) => x.id).join(', ')}]`,

packages/aws-cdk/test/cli/cdk-toolkit.test.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import {
9797
restoreSdkMocksToDefault,
9898
} from '../util/mock-sdk';
9999
import { asIoHelper } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private';
100+
import { StackActivityProgress } from '../../lib/commands/deploy';
100101

101102
markTesting();
102103

@@ -615,7 +616,6 @@ describe('deploy', () => {
615616
expect(mockSynthesize).not.toHaveBeenCalled();
616617
});
617618

618-
619619
describe('readCurrentTemplate', () => {
620620
let template: any;
621621
let mockCloudExecutable: MockCloudExecutable;
@@ -1009,6 +1009,36 @@ describe('deploy', () => {
10091009
);
10101010
});
10111011
});
1012+
1013+
test('can set progress via options', async () => {
1014+
const ioHost = CliIoHost.instance();
1015+
1016+
// Ensure environment allows StackActivityProgress.BAR
1017+
ioHost.stackProgress = StackActivityProgress.BAR;
1018+
ioHost.isTTY = true;
1019+
ioHost.isCI = false;
1020+
expect(ioHost.stackProgress).toBe('bar');
1021+
1022+
const toolkit = new CdkToolkit({
1023+
ioHost,
1024+
cloudExecutable,
1025+
configuration: cloudExecutable.configuration,
1026+
sdkProvider: cloudExecutable.sdkProvider,
1027+
deployments: new FakeCloudFormation({}),
1028+
});
1029+
1030+
// check this hasn't changed yet
1031+
expect(ioHost.stackProgress).toBe('bar');
1032+
1033+
await toolkit.deploy({
1034+
progress: StackActivityProgress.EVENTS,
1035+
selector: { patterns: ["**"] },
1036+
hotswap: HotswapMode.FALL_BACK
1037+
});
1038+
1039+
// now expect it to be updated
1040+
expect(ioHost.stackProgress).toBe('events');
1041+
});
10121042
});
10131043

10141044
describe('destroy', () => {

0 commit comments

Comments
 (0)