Skip to content

Commit

Permalink
fix(cli): cannot set environment variable CI=false (#32749)
Browse files Browse the repository at this point in the history
We check the `$CI` environment variable for its presence, not for its value. This means that setting `CI=false` enables CI mode instead of disabling it.

This is unexpected. Fix it.

We could have checked for `CI=true` or `CI=1`, but the current behavior is backwards compatible with crazy things users might already be doing.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Jan 6, 2025
1 parent bd38861 commit 26b361d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/util/yargs-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function yargsNegativeAlias<T extends { [x in S | L]: boolean | undefined
* @returns true if the current process is running in a CI environment
*/
export function isCI(): boolean {
return process.env.CI !== undefined;
return process.env.CI !== undefined && process.env.CI !== 'false' && process.env.CI !== '0';
}

/**
Expand Down
14 changes: 14 additions & 0 deletions packages/aws-cdk/test/util/yargs-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { isCI } from '../../lib/util/yargs-helpers';

test.each([
['true', true],
['1', true],
['false', false],
['0', false],
// The following ones are unexpected but this is the legacy behavior we're preserving.
['banana', true],
['', true],
])('test parsing of falsey CI values: %p parses as %p', (envvar, ci) => {
process.env.CI = envvar;
expect(isCI()).toEqual(ci);
});

0 comments on commit 26b361d

Please sign in to comment.