Skip to content

Conversation

@iankhou
Copy link
Contributor

@iankhou iankhou commented Mar 18, 2025

Fixes #192

Description

The bootstrap action in the Toolkit Library currently does not have a returned value. Although there is logged output, the Toolkit instance does not get any information about the result of the bootstrap action.

Solution

Make Toolkit.bootstrap() Return an instance of type Promise<BootstrapResult>, which also uses new type EnvironmentBootstrapResult with metrics for each environment.

Testing

Added unit tests.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@iankhou iankhou self-assigned this Mar 18, 2025
@github-actions github-actions bot added the p2 label Mar 18, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team March 18, 2025 14:46
@codecov-commenter
Copy link

codecov-commenter commented Mar 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.40%. Comparing base (d8eeea8) to head (51dea87).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #249      +/-   ##
==========================================
+ Coverage   85.26%   85.40%   +0.14%     
==========================================
  Files         220      220              
  Lines       36619    36619              
  Branches     4448     4461      +13     
==========================================
+ Hits        31222    31275      +53     
+ Misses       5297     5244      -53     
  Partials      100      100              
Flag Coverage Δ
suite.unit 85.40% <ø> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: github-actions <[email protected]>
@iankhou iankhou changed the title fix(toolkit): add typed return to bootstrap action feat(toolkit): add typed return to bootstrap action Mar 18, 2025
environment: environment.name,
status: bootstrapResult.noOp ? 'no-op' : 'success',
message: bootstrapResult.noOp ? 'No changes required' : 'Successfully bootstrapped',
duration: Date.now() - envStartTime,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duration can be access from the return value of await bootstrapSpan.end();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I've removed this field.

Copy link
Contributor

@mrgrain mrgrain Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have it, let's just don't time twice and instead do

const envTime = await bootstrapSpan.end();
// ...
{ duration: envTime.asMs }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I had misunderstood what you meant, I'll use the time from bootstrapSpan.

Comment on lines 202 to 208
const result: EnvironmentBootstrapResult = {
environment: environment.name,
status: 'failed',
error: e,
message: formatErrorMessage(e),
duration: Date.now() - envStartTime,
};
Copy link
Contributor

@mrgrain mrgrain Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we throw an exception three lines further down, so this will just never be returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, removed this code. I also removed 'failed' as a status case because it throws an error.

environment: string;
status: 'success' | 'failed' | 'no-op';
message?: string;
error?: Error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment, this will just never be returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still there

Copy link
Contributor

@mrgrain mrgrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Let's do a little less and re-use what's already there.

}

export interface EnvironmentBootstrapResult {
environment: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be better types as ?

Suggested change
environment: string;
environment: cxapi.Environment;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced and updated tests as well.


return {
environments: results,
summary,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think let's just loose the summary. If we return, it's successful. If someone really cares about the counts for success vs. no-op, they can do that themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, makes sense. Removed the summary.

export interface EnvironmentBootstrapResult {
environment: cxapi.Environment;
status: 'success' | 'no-op';
error?: Error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
error?: Error;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this, it will never be used.

@iankhou iankhou temporarily deployed to integ-approval March 20, 2025 13:59 — with GitHub Actions Inactive
export interface EnvironmentBootstrapResult {
environment: cxapi.Environment;
status: 'success' | 'no-op';
duration: Number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
duration: Number;
duration: number;

},
);

const envTime = await bootstrapSpan.end();
Copy link
Contributor

@mrgrain mrgrain Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you now have bootstrapSpan.end(); twice, causing the message to be printed twice. your reporting block needs to move to where the original end message was.

@mrgrain mrgrain added the pr/exempt-integ-test Skips the integ test steps if set. label Mar 20, 2025
@aws-cdk-automation aws-cdk-automation added this pull request to the merge queue Mar 20, 2025
Merged via the queue into main with commit b23b2da Mar 20, 2025
11 checks passed
@aws-cdk-automation aws-cdk-automation deleted the iankhou-typed-return-bootstrap branch March 20, 2025 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2 pr/exempt-integ-test Skips the integ test steps if set.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Toolkit Action: typed return for bootstrap

4 participants