Skip to content

feat: refactor execution #516

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

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft

Conversation

otaviomacedo
Copy link
Contributor

@otaviomacedo otaviomacedo commented May 21, 2025

Overview

This change introduces the creation and execution of stack refactors. It builds on previous work that put all the pieces in place (mapping computation, mapping file reading, exclude lists, dry-run etc). The following flowcharts summarize the behavior in interactive and non-interactive modes:

Non-interactive case

flowchart LR
    mapping{Refactor file present?}
    empty{Empty mapping?}
    dryrun{--dry-run?}
    compute[Compute mapping]
    use[Use mapping]
    print[Print mapping]
    mapping ---|No| compute
    mapping ---|Yes| use
    compute --- empty
    use --- empty
    empty ---|Yes| Exit
    empty ---|No| print
    print --- dryrun
    dryrun ---|Yes| Exit
    dryrun ---|No| Refactor
    Refactor --- Exit
Loading

Interactive case

flowchart LR
    mapping{Refactor file present?}
    empty{Empty mapping?}
    dryrun{--dry-run?}
    force{--force?}
    compute[Compute mapping]
    use[Use mapping]
    print[Print mapping]
    ask[Ask user]
    mapping ---|No| compute
    mapping ---|Yes| use
    compute --- empty
    use --- empty
    empty ---|Yes| Exit
    empty ---|No| print
    print --- dryrun
    dryrun ---|Yes| Exit
    dryrun ---|No| force
    force ---|Yes| Refactor
    force ---|No| ask
    ask ---|Yes| Refactor
    ask ---|No| Exit
    Refactor --- Exit
Loading

There is one use case that is explicitly not supported: when a resource is being referenced by an output. This is because cross-stack references cannot be directly refactored using the CloudFormation API, and there is some work to do on the CDK side.

Implementation notes

The most important pieces to review are:

  • The StackContainer class, that controls the execution flow for each environment.
  • The executeRefactor function, that interacts with the CFN API to make the refactor happen.

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

# Conflicts:
#	packages/@aws-cdk/toolkit-lib/lib/actions/refactor/index.ts
#	packages/@aws-cdk/toolkit-lib/lib/api/refactoring/index.ts
#	packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts
#	packages/@aws-cdk/toolkit-lib/test/actions/refactor.test.ts
#	packages/aws-cdk/lib/cli/cdk-toolkit.ts
#	packages/aws-cdk/lib/cli/cli-config.ts
#	packages/aws-cdk/lib/cli/cli.ts
#	packages/aws-cdk/lib/cli/convert-to-user-input.ts
#	packages/aws-cdk/lib/cli/parse-command-line-arguments.ts
#	packages/aws-cdk/lib/cli/user-input.ts
@github-actions github-actions bot added the p2 label May 21, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team May 21, 2025 08:50
@codecov-commenter
Copy link

codecov-commenter commented May 21, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 78.97%. Comparing base (1445ba1) to head (6b19940).
Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
packages/aws-cdk/lib/cli/cdk-toolkit.ts 88.88% 1 Missing ⚠️
packages/aws-cdk/lib/cli/cli.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #516      +/-   ##
==========================================
- Coverage   78.98%   78.97%   -0.01%     
==========================================
  Files          46       46              
  Lines        6994     6986       -8     
  Branches      775      776       +1     
==========================================
- Hits         5524     5517       -7     
+ Misses       1452     1450       -2     
- Partials       18       19       +1     
Flag Coverage Δ
suite.unit 78.97% <80.00%> (-0.01%) ⬇️

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants