Skip to content

Commit

Permalink
feat(cli): disable version check (#10975)
Browse files Browse the repository at this point in the history
If AWS_CDK_DISABLE_VERSION_CHECK is defined, skip checking for newer
versions.

fixes #10974


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
christophgysin authored Oct 26, 2020
1 parent cacabec commit 575e47e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/aws-cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,10 @@ Some of the interesting keys that can be used in the JSON configuration files:
"versionReporting": false, // Opt-out of version reporting (--no-version-reporting)
}
```

#### Environment

The following environment variables affect aws-cdk:

- `CDK_DISABLE_VERSION_CHECK`: If set, disable automatic check for newer versions.
- `CDK_NEW_BOOTSTRAP`: use the modern bootstrapping stack.
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function latestVersionIfHigher(currentVersion: string, cacheFile: V
}

export async function displayVersionMessage(): Promise<void> {
if (!process.stdout.isTTY) {
if (!process.stdout.isTTY || process.env.CDK_DISABLE_VERSION_CHECK) {
return;
}

Expand Down
11 changes: 10 additions & 1 deletion packages/aws-cdk/test/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { setTimeout as _setTimeout } from 'timers';
import { promisify } from 'util';
import * as fs from 'fs-extra';
import * as sinon from 'sinon';
import { latestVersionIfHigher, VersionCheckTTL } from '../lib/version';
import * as logging from '../lib/logging';
import { latestVersionIfHigher, VersionCheckTTL, displayVersionMessage } from '../lib/version';

const setTimeout = promisify(_setTimeout);

Expand Down Expand Up @@ -72,3 +73,11 @@ test('No Version specified for storage in the TTL file', async () => {
const storedVersion = fs.readFileSync(cacheFile, 'utf8');
expect(storedVersion).toBe('');
});

test('Skip version check if environment variable is set', async () => {
process.stdout.isTTY = true;
process.env.CDK_DISABLE_VERSION_CHECK = '1';
const printStub = sinon.stub(logging, 'print');
await displayVersionMessage();
expect(printStub.called).toEqual(false);
});

0 comments on commit 575e47e

Please sign in to comment.