Skip to content

Commit

Permalink
feat(cli): Support disabling version check
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 aws#10974
  • Loading branch information
christophgysin committed Oct 20, 2020
1 parent aa3f3fd commit f682f48
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/aws-cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,9 @@ 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:

- `AWS_CDK_DISABLE_VERSION_CHECK`: If set, disable automatic check for newer versions.
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.AWS_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.AWS_CDK_DISABLE_VERSION_CHECK = '1';
const printStub = sinon.stub(logging, 'print');
await displayVersionMessage();
expect(printStub.called).toEqual(false);
});

0 comments on commit f682f48

Please sign in to comment.