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

fix: eliminate circular dependency when generating CMS assets #11304

Merged
merged 4 commits into from
Nov 3, 2022

Conversation

edwardfoyle
Copy link
Contributor

@edwardfoyle edwardfoyle commented Nov 1, 2022

Description of changes

When Amplify Studio is enabled on a project, after push, the CLI calls AmplifyBackend.generateBackendAPIModels. This in turn would execute some codegen commands via the CLI running in Studio and upload output assets to S3. This generated a circular dependency which apart from being a confusing antipattern also caused failures like #11284.

This PR fixes the issue by removing the call to AmplifyBackend.generateBackendAPIModels altogether. Instead after push the CLI invokes the necessary codegen commands and uploads the assets to S3 directly.

While this simplifies the overall architecture of this code path, this implementation required a few hacks:

  1. The codegen assets need to be generated in JS so there is logic to overwrite the project config to force JS output, then reset the project config at the end
  2. The codegen commands being run produce duplicate and confusing output so stdout is reassigned to a file to suppress the confusing output and then restored at the end

Additionally, there is tight coupling between Studio CMS and the CLI via the expected S3 paths of the CMS assets. However, this tight coupling is not new, it's just been moved from Studio to the CLI.

Issue #, if available

fixes #11284

Description of how you validated changes

Validated manually, added unit tests and e2e test

Checklist

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

@codecov-commenter
Copy link

Codecov Report

Merging #11304 (5313a86) into dev (fda7872) will increase coverage by 0.01%.
The diff coverage is 13.33%.

@@            Coverage Diff             @@
##              dev   #11304      +/-   ##
==========================================
+ Coverage   49.60%   49.61%   +0.01%     
==========================================
  Files         683      682       -1     
  Lines       32840    32827      -13     
  Branches     6700     6693       -7     
==========================================
- Hits        16290    16287       -3     
+ Misses      15070    15061       -9     
+ Partials     1480     1479       -1     
Impacted Files Coverage Δ
...y-provider-awscloudformation/src/admin-modelgen.ts 20.00% <13.33%> (-3.41%) ⬇️
...loudformation/src/aws-utils/aws-amplify-backend.ts
...li/src/domain/amplify-usageData/getUsageDataUrl.ts 100.00% <0.00%> (+12.50%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -72,9 +78,20 @@ export const getBucketKeys = async (params: S3.ListObjectsRequest) => {
}
};

export const getDeploymentBucketObject = async (projectRoot: string, objectKey: string) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only functional change in this file. Everything else is lint fixes

@edwardfoyle edwardfoyle marked this pull request as ready for review November 2, 2022 20:55
@edwardfoyle edwardfoyle requested a review from a team as a code owner November 2, 2022 20:55
jhockett
jhockett previously approved these changes Nov 2, 2022
@lazpavel lazpavel merged commit 2d7e8d0 into aws-amplify:dev Nov 3, 2022
@edwardfoyle edwardfoyle deleted the api-models branch November 4, 2022 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants