Skip to content

Commit

Permalink
fix: remove stale data (#13128)
Browse files Browse the repository at this point in the history
* feat: add getStackBuildCategorySourceDirPath

* feat(amplify-cli-core): remove StackBuildCategorySourceDirPath

* fix(cli-internal): remove-resource test

* test(cli-internal): remove-resource awscloudformation/build

* test(cli-internal): remove-resource awscloudformation/build

* test(amplify-e2e-tests): remove function and layer

* fix: run yarn split-e2e-tests-codebuild

* fix: run yarn split-e2e-tests-codebuild

* chore: rename getStackBuildCategoryResourceDirPath

---------

Co-authored-by: 0.618 <[email protected]>
  • Loading branch information
0618 and 0.618 authored Aug 29, 2023
1 parent d374fee commit 9703223
Show file tree
Hide file tree
Showing 8 changed files with 514 additions and 365 deletions.
611 changes: 305 additions & 306 deletions codebuild_specs/e2e_workflow_generated.yml

Large diffs are not rendered by default.

112 changes: 56 additions & 56 deletions codebuild_specs/wait_for_ids.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,64 @@
[
"l_S3server_api_8_function_8",
"l_amplify_app",
"l_amplify_configure_env_2_init_d",
"l_analytics_kinesis_analytics_pinpoint_flutter_analytics_pinpoint_js",
"l_android_analytics_pinpoint_config_android_notifications_pinpoint_config_flutter_analytics_pinpoint_config",
"l_api_2b_api_6c_api_9a",
"l_api_3_api_6b_api_1",
"l_api_4_containers_api_secrets_storage_4",
"l_api_6a_auth_7b_export_pull_b",
"l_api_6b_api_1_layer_1",
"l_api_6c_api_9a_auth_12",
"l_api_7_export_pull_a_function_9a",
"l_api_graphql_v2_migration_v10",
"l_api_key_migration1_schema_auth_14_api_3",
"l_api_key_migration4_schema_iterative_update_4_function_1",
"l_api_key_migration_2_v8",
"l_api_key_migration_v8",
"l_api_lambda_auth_1_api_key_migration2_schema_searchable",
"l_api_rest_basic_migration_v10",
"l_api_rest_lambda_migration_v10",
"l_api_rest_serverless_migration_v10",
"l_apigw_api_lambda_auth_1_api_key_migration2",
"l_auth_12_auth_2g_auth_2h",
"l_auth_1a_auth_trigger_custom_policies_function",
"l_auth_1b_delete_geo_add_c",
"l_auth_1c_auth_5e_auth_8b",
"l_auth_2a_auth_2b_auth_2d",
"l_auth_2c",
"l_auth_2e",
"l_auth_2f_notifications_lifecycle_notifications_analytics_compatibility_in_app_1",
"l_auth_2g_auth_2h_auth_5g",
"l_auth_3a_auth_3b_auth_4a",
"l_auth_4b_auth_8a_export_pull_d",
"l_auth_4c_auth_5a_auth_5c",
"l_auth_6_function_2a_schema_connection_2",
"l_auth_5g_hosted_ui_user_groups_s3_access",
"l_auth_7a_auth_8c_feature_flags",
"l_auth_9_custom_resources_env_5",
"l_auth_add_all_migration_v10",
"l_auth_app_client_secret_migration_v12",
"l_auth_hosted_ui_lambda_migration_v12",
"l_auth_lambda_callout_migration_rollback_v12",
"l_auth_lambda_callout_migration_v12",
"l_auth_migration_api_2a_api_2b",
"l_auth_migration_amplify_remove_api_2a",
"l_auth_migration_v12",
"l_auth_oauth_lambda_migration_v12",
"l_auth_override_migration_v10",
"l_build_function_custom_resource_with_storage_dynamodb_simulator",
"l_container_hosting_init_b_notifications_apns",
"l_containers_api_1",
"l_containers_api_2",
"l_containers_api_secrets_storage_4_schema_auth_10",
"l_custom_policies_container_function_9b_schema_iterative_update_2",
"l_custom_stack_migration_v10",
"l_datastore_modelgen",
"l_diagnose_hooks_a_mock_api",
"l_dynamodb_simulator_export_pull_c_function_12",
"l_env_1_geo_add_a_init_a",
"l_env_3",
"l_env_4_frontend_config_drift_schema_auth_4d",
"l_export_pull_c_function_12_function_13",
"l_flutter_notifications_pinpoint_config_ios_analytics_pinpoint_config_ios_notifications_pinpoint_config",
"l_flutter_analytics_pinpoint_config_flutter_notifications_pinpoint_config_ios_analytics_pinpoint_config",
"l_function_10_function_9c_function_permissions",
"l_function_14_function_15_function_2d",
"l_function_13_function_14_function_15",
"l_function_1_storage_5",
"l_function_2b_function_7_api_connection_migration2",
"l_function_2c_function_3b_function_4",
"l_function_2d_general_config_headless_init_help",
"l_function_3a_init_special_case_http_migration",
"l_function_6_storage_2_export",
"l_function_7_api_connection_migration2_api_4",
"l_function_9b_schema_iterative_update_2_storage_1a",
"l_function_8_schema_iterative_update_locking_api_lambda_auth_2",
"l_function_migration_update_v8",
"l_general_config_headless_init_help_hooks_c",
"l_geo_add_b_s3_sse_schema_auth_4a",
"l_geo_add_d_geo_import_3_hosting",
"l_geo_add_e",
Expand All @@ -70,7 +67,6 @@
"l_geo_import_1a_geo_import_2_global_sandbox_b",
"l_geo_import_1b_global_sandbox_a_init_e",
"l_geo_migration_v10",
"l_geo_multi_env_searchable_datastore_resolvers",
"l_geo_remove_1",
"l_geo_remove_2",
"l_geo_remove_3",
Expand All @@ -79,7 +75,7 @@
"l_git_clone_attach_init_c_layer_4",
"l_git_clone_migration_tests_v10",
"l_hooks_b_notifications_analytics_compatibility_sms_1_plugin",
"l_hosted_ui_user_groups_s3_access_user_groups",
"l_hooks_c_init_force_push_interactions_1",
"l_hostingPROD",
"l_iam_permissions_boundary_node_function_notifications_sms",
"l_import_auth_1a",
Expand All @@ -97,11 +93,12 @@
"l_import_s3_2c",
"l_import_s3_3",
"l_init_f_auth_5d_configure_project",
"l_init_force_push_interactions_1_interactions_2",
"l_interactions_2_minify_cloudformation_notifications_multi_env",
"l_interactions_schema_model_a_tags",
"l_javascript_analytics_pinpoint_config_javascript_notifications_pinpoint_config_pr_previews_multi_env_1",
"l_ios_notifications_pinpoint_config_javascript_analytics_pinpoint_config_javascript_notifications_pinpoint_config",
"l_layer_1_api_key_migration4_schema_iterative_update_4",
"l_layer_2_schema_auth_13_function_5",
"l_layer_3_api_connection_migration_api_key_migration3",
"l_minify_cloudformation_notifications_multi_env_notifications_sms_update",
"l_notifications_analytics_compatibility_in_app_2_schema_auth_11_c_schema_auth_2b",
"l_notifications_analytics_compatibility_sms_2_analytics_2_global_sandbox_c",
"l_notifications_fcm_notifications_in_app_messaging_env_2_with_babel_config",
Expand All @@ -111,14 +108,16 @@
"l_notifications_migration_4_v8",
"l_notifications_migration_v8",
"l_notifications_sms_pull_pull_auth_10",
"l_opensearch_simulator_parameter_store_1_parameter_store_2",
"l_notifications_sms_update_opensearch_simulator_parameter_store_1",
"l_parameter_store_2_android_analytics_pinpoint_config_android_notifications_pinpoint_config",
"l_pinpoint_region_migration_v10",
"l_pr_previews_multi_env_1_pull_2_push",
"l_predictions_schema_auth_11_b_schema_auth_1b",
"l_pull_2_push_smoketest",
"l_resolvers_schema_key_api_5",
"l_scaffold_v10",
"l_schema_auth_10_geo_multi_env_searchable_datastore",
"l_schema_auth_11_a",
"l_schema_auth_12_schema_auth_3_schema_function_2",
"l_schema_auth_13_function_5_schema_iterative_update_1",
"l_schema_auth_15",
"l_schema_auth_2a_schema_auth_7a_schema_auth_7b",
"l_schema_auth_4b_schema_model_e_schema_versioned",
Expand All @@ -132,59 +131,60 @@
"l_schema_auth_9_b_schema_iterative_rollback_1_predictions_migration",
"l_schema_auth_9_c_storage_3_auth_11",
"l_schema_connection_1",
"l_schema_function_1_api_9b_custom_policies_container",
"l_schema_iterative_update_locking_api_lambda_auth_2_layer_2",
"l_schema_key_api_5_apigw",
"l_schema_connection_2_schema_function_1_api_9b",
"l_schema_iterative_update_1_auth_6_function_2a",
"l_schema_model_b_schema_model_d_auth_5f",
"l_schema_predictions_model_migration_auth_3c",
"l_schema_searchable_api_key_migration1_schema_auth_14",
"l_searchable_migration",
"l_storage_1b_function_11_function_2b",
"l_storage_5",
"l_smoketest_S3server_api_8",
"l_storage_1a_storage_1b_function_11",
"l_storage_migration_v10",
"l_studio_modelgen_custom_transformers_notifications_in_app_messaging_env_1",
"l_uibuilder",
"l_user_groups_build_function_custom_resource_with_storage",
"w_analytics_kinesis_analytics_pinpoint_flutter_analytics_pinpoint_js",
"w_api_10_api_7_export_pull_a",
"w_api_2b_api_6c_api_9a",
"w_api_3_api_6b_api_1",
"w_api_4_containers_api_secrets_storage_4",
"w_api_1_layer_1_api_key_migration4",
"w_api_2a_api_2b_api_6c",
"w_api_5_apigw_api_lambda_auth_1",
"w_api_6a_auth_7b_export_pull_b",
"w_api_9b_custom_policies_container_function_9b",
"w_api_8_schema_iterative_update_locking_api_lambda_auth_2",
"w_api_9a_auth_2h_auth_5g",
"w_api_connection_migration2_api_4_containers_api_secrets",
"w_api_key_migration2_schema_searchable_api_key_migration1",
"w_api_key_migration3_predictions_schema_auth_11_b",
"w_apigw_api_lambda_auth_1_api_key_migration2",
"w_auth_11_auth_1b_delete",
"w_auth_2a_auth_2b_auth_2d",
"w_auth_2c",
"w_auth_2e",
"w_auth_2f_notifications_lifecycle_notifications_analytics_compatibility_in_app_1",
"w_auth_2h_auth_5g_hosted_ui",
"w_auth_4a_auth_7a_auth_8c",
"w_auth_5a_auth_5c_env_1",
"w_auth_5e_auth_8b_geo_add_b",
"w_auth_6_function_2a_schema_connection_2",
"w_auth_8a_export_pull_d_schema_auth_5a",
"w_build_function_dynamodb_simulator_export_pull_c",
"w_configure_project_init_c_layer_4",
"w_containers_api_1",
"w_containers_api_2",
"w_custom_policies_function_storage_2_iam_permissions_boundary",
"w_dynamodb_simulator_export_pull_c_function_12",
"w_env_3",
"w_env_5_function_10_function_9c",
"w_feature_flags_geo_import_1b_global_sandbox_a",
"w_frontend_config_drift_schema_auth_4d_schema_auth_6a",
"w_function_1",
"w_function_11_function_2b_api_connection_migration2",
"w_function_13_function_14_function_2d",
"w_function_2a_schema_connection_2_schema_function_1",
"w_function_12_function_13_function_14",
"w_function_2c_interactions_schema_model_a",
"w_function_5_schema_iterative_update_1_auth_6",
"w_function_2d_general_config_headless_init_help",
"w_function_9a_geo_headless_api_key_migration5",
"w_function_9b_schema_iterative_update_2_storage_1a",
"w_function_permissions_geo_import_1a_geo_import_2",
"w_general_config_headless_init_help_init_force_push",
"w_geo_add_a_init_a_schema_auth_4c",
"w_geo_add_c_geo_add_d_geo_import_3",
"w_geo_remove_1",
"w_global_sandbox_b_schema_auth_5d_schema_auth_6b",
"w_hooks_b_notifications_analytics_compatibility_sms_1_plugin",
"w_hosted_ui_user_groups_s3_access_user_groups",
"w_hostingPROD",
"w_hosting_layer_3_api_connection_migration",
"w_import_dynamodb_1",
Expand All @@ -193,21 +193,20 @@
"w_init_b_notifications_apns_notifications_fcm",
"w_init_d_init_f_auth_5d",
"w_init_e_notifications_analytics_compatibility_in_app_2_schema_auth_11_c",
"w_init_force_push_interactions_1_interactions_2",
"w_init_special_case_http_migration_schema_auth_12",
"w_interactions_1_interactions_2_minify_cloudformation",
"w_layer_1_api_key_migration4_schema_iterative_update_4",
"w_minify_cloudformation_notifications_multi_env_notifications_sms_update",
"w_model_migration_auth_3c_auth_4c",
"w_node_function_notifications_sms_schema_auth_4b",
"w_notifications_analytics_compatibility_sms_2_analytics_2_global_sandbox_c",
"w_notifications_in_app_messaging",
"w_notifications_in_app_messaging_env_2_with_babel_config_amplify_configure",
"w_notifications_multi_env_notifications_sms_update_parameter_store_1",
"w_notifications_sms_pull_auth_10_container_hosting",
"w_parameter_store_2_push_api_8",
"w_resolvers_schema_key_api_5",
"w_parameter_store_1_parameter_store_2_push",
"w_s3_sse_schema_auth_4a_schema_model_b",
"w_schema_auth_10_geo_multi_env_searchable_datastore",
"w_schema_auth_11_a",
"w_schema_auth_13_function_5_schema_iterative_update_1",
"w_schema_auth_14_api_3_api_6b",
"w_schema_auth_15",
"w_schema_auth_1a_schema_auth_5b_schema_auth_8b",
"w_schema_auth_1b_schema_auth_2a_schema_auth_7a",
Expand All @@ -220,14 +219,15 @@
"w_schema_auth_9_a_schema_auth_9_c_storage_3",
"w_schema_connection_1",
"w_schema_data_access_patterns_schema_model_c_schema_predictions",
"w_schema_iterative_update_2_storage_1a_storage_1b",
"w_schema_iterative_update_3_auth_migration_api_2a",
"w_schema_iterative_update_locking_api_lambda_auth_2_schema_auth_13",
"w_schema_function_1_api_9b_custom_policies_container",
"w_schema_iterative_update_3_auth_migration_amplify_remove",
"w_schema_iterative_update_4_function_1",
"w_schema_model_d_auth_5f_env_4",
"w_schema_model_e_schema_versioned_auth_1c",
"w_schema_searchable_api_key_migration1_schema_auth_14",
"w_searchable_datastore_resolvers_schema_key",
"w_searchable_migration",
"w_storage_1b_function_11_function_2b",
"w_storage_4_schema_auth_10_geo_multi_env",
"w_studio_modelgen_custom_transformers_notifications_in_app_messaging_env_1",
"w_tags_auth_1a_auth_trigger",
"w_user_groups_s3_access_user_groups_build_function"
"w_tags_auth_1a_auth_trigger"
]
2 changes: 2 additions & 0 deletions packages/amplify-cli-core/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,8 @@ export class PathManager {
// (undocumented)
getRootStackBuildDirPath: (projectPath: string) => string;
// (undocumented)
getStackBuildCategoryResourceDirPath: (projectPath: string, category: string, resourceName: string) => string;
// (undocumented)
getTagFilePath: (projectPath?: string) => string;
// (undocumented)
getTeamProviderInfoFilePath: (projectPath?: string) => string;
Expand Down
10 changes: 10 additions & 0 deletions packages/amplify-cli-core/src/__tests__/pathManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ describe('test getAmplifyPackageLibDirPath', () => {
}
});
});

describe('test getStackBuildCategoryResourceDirPath', () => {
const category = 'storage';
const resourceName = 'testResource';
const expectedPath = path.join(pathManager.getRootStackBuildDirPath('projectPath'), category, resourceName);

it('should return correct path', () => {
expect(pathManager.getStackBuildCategoryResourceDirPath('projectPath', category, resourceName)).toEqual(expectedPath);
});
});
10 changes: 10 additions & 0 deletions packages/amplify-cli-core/src/state-manager/pathManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ export class PathManager {
PathConstants.BuildDirName,
]);

getStackBuildCategoryResourceDirPath = (projectPath: string, category: string, resourceName: string): string =>
this.constructPath(projectPath, [
PathConstants.AmplifyDirName,
PathConstants.BackendDirName,
PathConstants.ProviderName,
PathConstants.BuildDirName,
category,
resourceName,
]);

getCurrentCloudRootStackDirPath = (projectPath: string): string =>
this.constructPath(projectPath, [
PathConstants.AmplifyDirName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jest.mock('@aws-amplify/amplify-cli-core', () => ({
},
pathManager: {
getResourceDirectoryPath: jest.fn((_, categoryName, resourceName) => path.join('backendDirPath', categoryName, resourceName)),
getStackBuildCategoryResourceDirPath: jest.fn((_, categoryName, resourceName) =>
path.join('backendDirPath/awscloudformation/build/', categoryName, resourceName),
),
},
exitOnNextTick: jest.fn().mockImplementation(() => {
throw 'process.exit mock';
Expand Down Expand Up @@ -198,6 +201,8 @@ describe('remove-resource', () => {
},
});
expect(context.filesystem.remove).toBeCalledWith(path.join('backendDirPath', 'function', 'lambda1'));
expect(context.filesystem.remove).toBeCalledWith(path.join('backendDirPath/awscloudformation/build', 'function', 'lambda1'));
expect(context.filesystem.remove).toBeCalledTimes(2);
expect(removeResourceParameters).toBeCalledWith(context, 'function', 'lambda1');
expect(updateBackendConfigAfterResourceRemove).toBeCalledWith('function', 'lambda1');
expect(printer.success).toBeCalledWith('Successfully removed resource');
Expand Down Expand Up @@ -268,6 +273,7 @@ describe('remove-resource', () => {
},
});
expect(context.filesystem.remove).toBeCalledWith('backendDirPath/function/lambdaLayer1');
expect(context.filesystem.remove).toBeCalledWith('backendDirPath/awscloudformation/build/function/lambdaLayer1');
expect(removeResourceParameters).toBeCalledWith(context, 'function', 'lambdaLayer1');
expect(updateBackendConfigAfterResourceRemove).toBeCalledWith('function', 'lambdaLayer1');
expect(printer.success).toBeCalledWith('Successfully removed resource');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export async function removeResource(
if (resourceNameCallback) {
await resourceNameCallback(resourceName);
}

const resourceDir = pathManager.getResourceDirectoryPath(undefined, category, resourceName);

if (options.headless !== true) {
Expand Down Expand Up @@ -116,14 +115,14 @@ const deleteResourceFiles = async (context: $TSContext, category: string, resour
const { allResources } = await context.amplify.getResourceStatus();
allResources.forEach((resourceItem) => {
if (resourceItem.dependsOn) {
resourceItem.dependsOn.forEach((dependsOnItem) => {
for (const dependsOnItem of resourceItem.dependsOn) {
if (dependsOnItem.category === category && dependsOnItem.resourceName === resourceName) {
throw new AmplifyError('ResourceRemoveError', {
message: 'Resource cannot be removed because it has a dependency on another resource',
details: `Dependency: ${resourceItem.service} - ${resourceItem.resourceName}. Remove the dependency first.`,
});
}
});
}
}
});
}
Expand All @@ -139,7 +138,9 @@ const deleteResourceFiles = async (context: $TSContext, category: string, resour
stateManager.setMeta(undefined, amplifyMeta);

// Remove resource directory from backend/
const stackBuildDir = pathManager.getStackBuildCategoryResourceDirPath('', category, resourceName);
context.filesystem.remove(resourceDir);
context.filesystem.remove(stackBuildDir);

removeResourceParameters(context, category, resourceName);
updateBackendConfigAfterResourceRemove(category, resourceName);
Expand Down
Loading

0 comments on commit 9703223

Please sign in to comment.