Skip to content

Commit

Permalink
fix(cli): add specific check for cd branches when running `amplify pu…
Browse files Browse the repository at this point in the history
…blish`

fix aws-amplify#7486
  • Loading branch information
Bentheburrito committed Aug 3, 2021
1 parent fbc7ff1 commit cbf8234
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 21 deletions.
70 changes: 50 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1243,30 +1243,38 @@ jobs:
environment:
TEST_SUITE: src/__tests__/frontend_config_drift.test.ts
CLI_REGION: eu-west-2
container-hosting-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_5
environment:
TEST_SUITE: src/__tests__/container-hosting.test.ts
CLI_REGION: eu-central-1
configure-project-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_5
environment:
TEST_SUITE: src/__tests__/configure-project.test.ts
CLI_REGION: eu-central-1
CLI_REGION: ap-northeast-1
auth_6-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_5
environment:
TEST_SUITE: src/__tests__/auth_6.test.ts
CLI_REGION: ap-northeast-1
CLI_REGION: ap-southeast-1
api_4-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_5
environment:
TEST_SUITE: src/__tests__/api_4.test.ts
CLI_REGION: ap-southeast-1
CLI_REGION: ap-southeast-2
schema-iterative-update-4-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
Expand Down Expand Up @@ -1997,6 +2005,16 @@ jobs:
TEST_SUITE: src/__tests__/frontend_config_drift.test.ts
CLI_REGION: eu-west-2
steps: *ref_6
container-hosting-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/container-hosting.test.ts
CLI_REGION: eu-central-1
steps: *ref_6
configure-project-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
Expand All @@ -2005,7 +2023,7 @@ jobs:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/configure-project.test.ts
CLI_REGION: eu-central-1
CLI_REGION: ap-northeast-1
steps: *ref_6
auth_6-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
Expand All @@ -2015,7 +2033,7 @@ jobs:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/auth_6.test.ts
CLI_REGION: ap-northeast-1
CLI_REGION: ap-southeast-1
steps: *ref_6
api_4-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
Expand All @@ -2025,7 +2043,7 @@ jobs:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/api_4.test.ts
CLI_REGION: ap-southeast-1
CLI_REGION: ap-southeast-2
steps: *ref_6
workflows:
version: 2
Expand Down Expand Up @@ -2144,19 +2162,19 @@ workflows:
- schema-predictions-amplify_e2e_tests
- amplify-configure-amplify_e2e_tests
- migration-node-function-amplify_e2e_tests
- configure-project-amplify_e2e_tests
- container-hosting-amplify_e2e_tests
- interactions-amplify_e2e_tests
- datastore-modelgen-amplify_e2e_tests
- layer-2-amplify_e2e_tests
- auth_6-amplify_e2e_tests
- configure-project-amplify_e2e_tests
- schema-data-access-patterns-amplify_e2e_tests
- init-special-case-amplify_e2e_tests
- iam-permissions-boundary-amplify_e2e_tests
- api_4-amplify_e2e_tests
- feature-flags-amplify_e2e_tests
- auth_6-amplify_e2e_tests
- schema-versioned-amplify_e2e_tests
- plugin-amplify_e2e_tests
- function_7-amplify_e2e_tests
- api_4-amplify_e2e_tests
- done_with_pkg_linux_e2e_tests:
requires:
- analytics-amplify_e2e_tests_pkg_linux
Expand All @@ -2174,19 +2192,19 @@ workflows:
- schema-predictions-amplify_e2e_tests_pkg_linux
- amplify-configure-amplify_e2e_tests_pkg_linux
- migration-node-function-amplify_e2e_tests_pkg_linux
- configure-project-amplify_e2e_tests_pkg_linux
- container-hosting-amplify_e2e_tests_pkg_linux
- interactions-amplify_e2e_tests_pkg_linux
- datastore-modelgen-amplify_e2e_tests_pkg_linux
- layer-2-amplify_e2e_tests_pkg_linux
- auth_6-amplify_e2e_tests_pkg_linux
- configure-project-amplify_e2e_tests_pkg_linux
- schema-data-access-patterns-amplify_e2e_tests_pkg_linux
- init-special-case-amplify_e2e_tests_pkg_linux
- iam-permissions-boundary-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux
- feature-flags-amplify_e2e_tests_pkg_linux
- auth_6-amplify_e2e_tests_pkg_linux
- schema-versioned-amplify_e2e_tests_pkg_linux
- plugin-amplify_e2e_tests_pkg_linux
- function_7-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux
- amplify_migration_tests_latest:
context:
- amplify-ecr-image-pull
Expand Down Expand Up @@ -2600,7 +2618,7 @@ workflows:
filters: *ref_10
requires:
- schema-iterative-update-1-amplify_e2e_tests
- configure-project-amplify_e2e_tests:
- container-hosting-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2666,7 +2684,7 @@ workflows:
filters: *ref_10
requires:
- function_3-amplify_e2e_tests
- auth_6-amplify_e2e_tests:
- configure-project-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2732,7 +2750,7 @@ workflows:
filters: *ref_10
requires:
- auth_5-amplify_e2e_tests
- api_4-amplify_e2e_tests:
- auth_6-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2798,6 +2816,12 @@ workflows:
filters: *ref_10
requires:
- auth_1-amplify_e2e_tests
- api_4-amplify_e2e_tests:
context: *ref_8
post-steps: *ref_9
filters: *ref_10
requires:
- feature-flags-amplify_e2e_tests
- schema-iterative-update-4-amplify_e2e_tests_pkg_linux:
context: &ref_11
- amplify-ecr-image-pull
Expand Down Expand Up @@ -3082,7 +3106,7 @@ workflows:
filters: *ref_13
requires:
- schema-iterative-update-1-amplify_e2e_tests_pkg_linux
- configure-project-amplify_e2e_tests_pkg_linux:
- container-hosting-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
Expand Down Expand Up @@ -3152,7 +3176,7 @@ workflows:
filters: *ref_13
requires:
- function_3-amplify_e2e_tests_pkg_linux
- auth_6-amplify_e2e_tests_pkg_linux:
- configure-project-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
Expand Down Expand Up @@ -3222,7 +3246,7 @@ workflows:
filters: *ref_13
requires:
- auth_5-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux:
- auth_6-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
Expand Down Expand Up @@ -3292,3 +3316,9 @@ workflows:
filters: *ref_13
requires:
- auth_1-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux:
context: *ref_11
post-steps: *ref_12
filters: *ref_13
requires:
- feature-flags-amplify_e2e_tests_pkg_linux
12 changes: 11 additions & 1 deletion packages/amplify-cli/src/commands/publish.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { run as push } from './push';
import { FrontendBuildError } from 'amplify-cli-core';
import { hasCdBranches } from '../utils/check-hosting';

export const run = async context => {
context.amplify.constructExeInfo(context);
const { amplifyMeta } = context.exeInfo;
const isHostingAdded = amplifyMeta.hosting && Object.keys(amplifyMeta.hosting).length > 0;

if (!isHostingAdded) {
// Stop if the user has Continuous Deployment set up in the Amplify Console.
if (await hasCdBranches(context)) {
context.print.info('');
context.print.error(
'You have already connected branches to your Amplify Console app. Please visit the Amplify Console to manage your branches.',
);
context.print.info('');
return;
// Otherwise, stop if the user has not added the hosting category.
} else if (!isHostingAdded) {
context.print.info('');
context.print.error('Please add hosting to your project before publishing your project');
context.print.info('Command: amplify hosting add');
Expand Down
10 changes: 10 additions & 0 deletions packages/amplify-cli/src/utils/check-hosting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { getPluginInstance } from '../extensions/amplify-helpers/get-plugin-instance';

export async function hasCdBranches(context) {
const appId = context.exeInfo.amplifyMeta.providers.awscloudformation.AmplifyAppId;
const awsCloudPlugin = getPluginInstance(context, 'awscloudformation');
const amplifyClient = await awsCloudPlugin.getConfiguredAmplifyClient(context, {});
const result = await amplifyClient.listBranches({ appId }).promise();

return result.branches.length > 0;
}

0 comments on commit cbf8234

Please sign in to comment.