Skip to content

Commit

Permalink
fix(cli): "fancy" progress reporting not disabled on all CI systems (a…
Browse files Browse the repository at this point in the history
…ws#9516)

Fixes: aws#8696 aws#8893

Detects whether the `CI` environment variable is set and reverts output to `standard` behavior.

The fancy output was especially broken on CircleCI.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
andreialecu authored and misterjoshua committed Aug 19, 2020
1 parent 7732691 commit a59b7e0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/aws-cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function parseCommandLineArguments() {
.option('build-exclude', { type: 'array', alias: 'E', nargs: 1, desc: 'Do not rebuild asset with the given ID. Can be specified multiple times.', default: [] })
.option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only deploy requested stacks, don\'t include dependencies' })
.option('require-approval', { type: 'string', choices: [RequireApproval.Never, RequireApproval.AnyChange, RequireApproval.Broadening], desc: 'What security-sensitive changes need manual approval' })
.option('ci', { type: 'boolean', desc: 'Force CI detection (deprecated)', default: process.env.CI !== undefined })
.option('ci', { type: 'boolean', desc: 'Force CI detection', default: process.env.CI !== undefined })
.option('notification-arns', { type: 'array', desc: 'ARNs of SNS topics that CloudFormation will notify with stack related events', nargs: 1, requiresArg: true })
.option('tags', { type: 'array', alias: 't', desc: 'Tags to add to the stack (KEY=VALUE)', nargs: 1, requiresArg: true })
.option('execute', { type: 'boolean', desc: 'Whether to execute ChangeSet (--no-execute will NOT execute the ChangeSet)', default: true })
Expand Down Expand Up @@ -279,6 +279,7 @@ async function initCommandLine() {
parameters: parameterMap,
usePreviousParameters: args['previous-parameters'],
outputsFile: args.outputsFile,
ci: args.ci,
});

case 'destroy':
Expand Down
8 changes: 8 additions & 0 deletions packages/aws-cdk/lib/api/cloudformation-deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ export interface DeployStackOptions {
* @default true
*/
usePreviousParameters?: boolean;

/**
* Whether we are on a CI system
*
* @default false
*/
readonly ci?: boolean;
}

export interface DestroyStackOptions {
Expand Down Expand Up @@ -156,6 +163,7 @@ export class CloudFormationDeployments {
force: options.force,
parameters: options.parameters,
usePreviousParameters: options.usePreviousParameters,
ci: options.ci,
});
}

Expand Down
7 changes: 7 additions & 0 deletions packages/aws-cdk/lib/api/deploy-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ export interface DeployStackOptions {
* @default false
*/
force?: boolean;

/**
* Whether we are on a CI system
*
* @default false
*/
readonly ci?: boolean;
}

const LARGE_TEMPLATE_SIZE_KB = 50;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ export interface StackActivityMonitorProps {
* @default - Use value from logging.logLevel
*/
readonly logLevel?: LogLevel;

/**
* Whether we are on a CI system
*
* If so, disable the "optimized" stack monitor.
*
* @default false
*/
readonly ci?: boolean;
}

export class StackActivityMonitor {
Expand Down Expand Up @@ -79,7 +88,10 @@ export class StackActivityMonitor {

const isWindows = process.platform === 'win32';
const verbose = options.logLevel ?? logLevel;
const fancyOutputAvailable = !isWindows && stream.isTTY;
// On some CI systems (such as CircleCI) output still reports as a TTY so we also
// need an individual check for whether we're running on CI.
// see: https://discuss.circleci.com/t/circleci-terminal-is-a-tty-but-term-is-not-set/9965
const fancyOutputAvailable = !isWindows && stream.isTTY && !options.ci;

this.printer = fancyOutputAvailable && !verbose
? new CurrentActivityPrinter(props)
Expand Down
8 changes: 8 additions & 0 deletions packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export class CdkToolkit {
force: options.force,
parameters: Object.assign({}, parameterMap['*'], parameterMap[stack.stackName]),
usePreviousParameters: options.usePreviousParameters,
ci: options.ci,
});

const message = result.noOp
Expand Down Expand Up @@ -583,6 +584,13 @@ export interface DeployOptions {
* @default - Outputs are not written to any file
*/
outputsFile?: string;

/**
* Whether we are on a CI system
*
* @default false
*/
readonly ci?: boolean;
}

export interface DestroyOptions {
Expand Down

0 comments on commit a59b7e0

Please sign in to comment.