Skip to content

Commit

Permalink
Merge branch 'master' into lambda-nodejs-tsc-detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] committed Mar 7, 2022
2 parents 79e509d + b3c5fe8 commit 9dd37ec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
16 changes: 9 additions & 7 deletions packages/aws-cdk/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,6 @@ if (!process.stdout.isTTY) {
}

async function initCommandLine() {
void refreshNotices()
.then(_ => debug('Notices refreshed'))
.catch(e => debug(`Notices refresh failed: ${e}`));

const argv = await parseCommandLineArguments();
if (argv.verbose) {
setLogLevel(argv.verbose);
Expand All @@ -254,6 +250,12 @@ async function initCommandLine() {
});
await configuration.load();

if (shouldDisplayNotices()) {
void refreshNotices()
.then(_ => debug('Notices refreshed'))
.catch(e => debug(`Notices refresh failed: ${e}`));
}

const sdkProvider = await SdkProvider.withAwsCliCompatibleDefaults({
profile: configuration.settings.get(['profile']),
ec2creds: argv.ec2creds,
Expand Down Expand Up @@ -326,10 +328,10 @@ async function initCommandLine() {
});
}
}
}

function shouldDisplayNotices(): boolean {
return configuration.settings.get(['notices']) ?? true;
}
function shouldDisplayNotices(): boolean {
return configuration.settings.get(['notices']) ?? true;
}

async function main(command: string, args: any): Promise<number | void> {
Expand Down
14 changes: 6 additions & 8 deletions packages/aws-cdk/lib/notices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ export async function displayNotices(props: DisplayNoticesProps) {

export async function generateMessage(dataSource: NoticeDataSource, props: DisplayNoticesProps) {
const data = await dataSource.fetch();
const individualMessages = formatNotices(filterNotices(data, {
const filteredNotices = filterNotices(data, {
outdir: props.outdir,
acknowledgedIssueNumbers: new Set(props.acknowledgedIssueNumbers),
}));
});

if (individualMessages.length > 0) {
return finalMessage(individualMessages, data[0].issueNumber);
if (filteredNotices.length > 0) {
const individualMessages = formatNotices(filteredNotices);
return finalMessage(individualMessages, filteredNotices[0].issueNumber);
}
return '';
}
Expand Down Expand Up @@ -108,18 +109,15 @@ export class WebsiteNoticeDataSource implements NoticeDataSource {
const timeout = 3000;

return new Promise((resolve) => {
setTimeout(() => resolve([]), timeout);
try {
const req = https.get('https://cli.cdk.dev-tools.aws.dev/notices.json',
{ timeout },
res => {
const startTime = Date.now();
if (res.statusCode === 200) {
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => {
if (Date.now() - startTime > timeout) {
resolve([]);
}
rawData += chunk;
});
res.on('end', () => {
Expand Down
14 changes: 14 additions & 0 deletions packages/aws-cdk/test/integ/cli/cli.integtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,20 @@ integTest('templates on disk contain metadata resource, also in nested assemblie
expect(JSON.parse(nestedTemplateContents).Resources.CDKMetadata).toBeTruthy();
}));

integTest('skips notice refresh', withDefaultFixture(async (fixture) => {
const output = await fixture.cdkSynth({
options: ['--no-notices'],
modEnv: {
INTEG_STACK_SET: 'stage-using-context',
},
allowErrExit: true,
});

// Neither succeeds nor fails, but skips the refresh
await expect(output).not.toContain('Notices refreshed');
await expect(output).not.toContain('Notices refresh failed');
}));

async function listChildren(parent: string, pred: (x: string) => Promise<boolean>) {
const ret = new Array<string>();
for (const child of await fs.readdir(parent, { encoding: 'utf-8' })) {
Expand Down

0 comments on commit 9dd37ec

Please sign in to comment.