feat(toolkit): add typed return to bootstrap action#249
feat(toolkit): add typed return to bootstrap action#249aws-cdk-automation merged 12 commits intomainfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: github-actions <github-actions@github.com>
| environment: environment.name, | ||
| status: bootstrapResult.noOp ? 'no-op' : 'success', | ||
| message: bootstrapResult.noOp ? 'No changes required' : 'Successfully bootstrapped', | ||
| duration: Date.now() - envStartTime, |
There was a problem hiding this comment.
duration can be access from the return value of await bootstrapSpan.end();
There was a problem hiding this comment.
I see, I've removed this field.
There was a problem hiding this comment.
We can have it, let's just don't time twice and instead do
const envTime = await bootstrapSpan.end();
// ...
{ duration: envTime.asMs }There was a problem hiding this comment.
Sorry, I had misunderstood what you meant, I'll use the time from bootstrapSpan.
| const result: EnvironmentBootstrapResult = { | ||
| environment: environment.name, | ||
| status: 'failed', | ||
| error: e, | ||
| message: formatErrorMessage(e), | ||
| duration: Date.now() - envStartTime, | ||
| }; |
There was a problem hiding this comment.
we throw an exception three lines further down, so this will just never be returned.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
See other comment, this will just never be returned.
mrgrain
left a comment
There was a problem hiding this comment.
Looks good! Let's do a little less and re-use what's already there.
| } | ||
|
|
||
| export interface EnvironmentBootstrapResult { | ||
| environment: string; |
There was a problem hiding this comment.
Would this be better types as ?
| environment: string; | |
| environment: cxapi.Environment; |
There was a problem hiding this comment.
Replaced and updated tests as well.
|
|
||
| return { | ||
| environments: results, | ||
| summary, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yup, makes sense. Removed the summary.
…d of string environment
| export interface EnvironmentBootstrapResult { | ||
| environment: cxapi.Environment; | ||
| status: 'success' | 'no-op'; | ||
| error?: Error; |
There was a problem hiding this comment.
| error?: Error; |
There was a problem hiding this comment.
Removed this, it will never be used.
| export interface EnvironmentBootstrapResult { | ||
| environment: cxapi.Environment; | ||
| status: 'success' | 'no-op'; | ||
| duration: Number; |
There was a problem hiding this comment.
| duration: Number; | |
| duration: number; |
| }, | ||
| ); | ||
|
|
||
| const envTime = await bootstrapSpan.end(); |
There was a problem hiding this comment.
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.
Fixes #192
Description
The
bootstrapaction in the Toolkit Library currently does not have a returned value. Although there is logged output, theToolkitinstance does not get any information about the result of the bootstrap action.Solution
Make
Toolkit.bootstrap()Return an instance of typePromise<BootstrapResult>, which also uses new typeEnvironmentBootstrapResultwith 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