Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): notices on bootstrap version #31555

Merged
merged 30 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/aws-cdk/lib/api/environment-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as cxapi from '@aws-cdk/cx-api';
import { ISDK } from './aws-auth';
import { EcrRepositoryInfo, ToolkitInfo } from './toolkit-info';
import { debug, warning } from '../logging';
import { Notices } from '../notices';

/**
* Registry class for `EnvironmentResources`.
Expand Down Expand Up @@ -108,6 +109,8 @@ export class EnvironmentResources {
if (defExpectedVersion > version) {
throw new Error(`This CDK deployment requires bootstrap stack version '${expectedVersion}', found '${version}'. Please run 'cdk bootstrap'.`);
}
const notices = Notices.get();
notices.enqueuePrint(notices.forBootstrapVersion({ bootstrapVersion: version }));
iliapolo marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
58 changes: 31 additions & 27 deletions packages/aws-cdk/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { MIGRATE_SUPPORTED_LANGUAGES, getMigrateScanType } from '../lib/commands
import { RequireApproval } from '../lib/diff';
import { availableInitLanguages, cliInit, printAvailableTemplates } from '../lib/init';
import { data, debug, error, print, setLogLevel, setCI } from '../lib/logging';
import { displayNotices, refreshNotices } from '../lib/notices';
import { Notices } from '../lib/notices';
import { Command, Configuration, Settings } from '../lib/settings';
import * as version from '../lib/version';

Expand Down Expand Up @@ -367,9 +367,9 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
});
await configuration.load();

if (shouldDisplayNotices()) {
void refreshNotices()
.catch(e => debug(`Could not refresh notices: ${e}`));
const notices = Notices.create({ configuration });
if (notices.shouldDisplay()) {
void notices.refresh().catch(e => debug(`Could not refresh notices: ${e}`));
iliapolo marked this conversation as resolved.
Show resolved Hide resolved
}

const sdkProvider = await SdkProvider.withAwsCliCompatibleDefaults({
Expand Down Expand Up @@ -440,34 +440,38 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
// Do PSAs here
await version.displayVersionMessage();

if (shouldDisplayNotices()) {
if (cmd === 'notices' && argv.unacknowledged === true) {
await displayNotices({
outdir: configuration.settings.get(['output']) ?? 'cdk.out',
acknowledgedIssueNumbers: configuration.context.get('acknowledged-issue-numbers') ?? [],
ignoreCache: true,
unacknowledged: true,
});
} else if (cmd === 'notices') {
await displayNotices({
outdir: configuration.settings.get(['output']) ?? 'cdk.out',
acknowledgedIssueNumbers: [],
ignoreCache: true,
});
if (notices.shouldDisplay()) {
iliapolo marked this conversation as resolved.
Show resolved Hide resolved

// note that any bootstrap version related notices are not enqueued here (because we don't know the bootstrap version number here).
// they are enqueued to the same `Notices` instance deep inside our 'cdk deploy' call stack.

if (cmd === 'notices') {
// we force cache refresh because when user explicitly asks
// to see notices, we assume they want us to consider ALL possible notices.
await notices.refresh({ force: true });
notices.enqueuePrint([
...notices.forCliVersion({ onlyUnacknowledged: argv.unacknowledged }),
...notices.forFrameworkVersion({ onlyUnacknowledged: argv.unacknowledged }),
]);

// we only show the total in this case because the message it prints is specific for "unacknowledged" notices.
// unfortunate, but it was introduced this way so we preserve it for now.
// see https:/aws/aws-cdk/issues/31250
notices.print({ showTotal: argv.unacknowledged });

} else if (cmd !== 'version') {
await displayNotices({
outdir: configuration.settings.get(['output']) ?? 'cdk.out',
acknowledgedIssueNumbers: configuration.context.get('acknowledged-issue-numbers') ?? [],
ignoreCache: false,
});
// here we don't force refresh because its not an explicit ask
// to see notices - so we let the cache play its part.
await notices.refresh();
notices.enqueuePrint([
...notices.forCliVersion({ onlyUnacknowledged: true }),
...notices.forFrameworkVersion({ onlyUnacknowledged: true }),
]);
notices.print();
}
}
}

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

async function main(command: string, args: any): Promise<number | void> {
const toolkitStackName: string = ToolkitInfo.determineName(configuration.settings.get(['toolkitStackName']));
debug(`Toolkit stack: ${chalk.bold(toolkitStackName)}`);
Expand Down
Loading
Loading