Skip to content

Commit

Permalink
fix: enables -yes flag on amplify publish (#10774)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshbhu committed Jul 21, 2022
1 parent 88f8738 commit 860a0e5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/amplify-cli/src/commands/publish.ts
@@ -1,7 +1,11 @@
import { run as push } from './push';
import { FrontendBuildError } from 'amplify-cli-core';
import { run as push } from './push';
import { showTroubleshootingURL } from './help';

/**
* Entry point to amplify publish
*/
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const run = async context => {
context.amplify.constructExeInfo(context);
const { amplifyMeta } = context.exeInfo;
Expand Down Expand Up @@ -30,7 +34,9 @@ export const run = async context => {

const didPush = await push(context);

let continueToPublish = didPush;
// added extra check for -y flag as in publish frontend deploy is getting stuck in CICD if backend has no changes

let continueToPublish = didPush || !!context?.exeInfo?.inputParams?.yes;
if (!continueToPublish && isHostingAlreadyPushed) {
context.print.info('');
continueToPublish = await context.amplify.confirmPrompt('Do you still want to publish the frontend?');
Expand All @@ -39,6 +45,7 @@ export const run = async context => {
try {
if (continueToPublish) {
const frontendPlugins = context.amplify.getFrontendPlugins(context);
// eslint-disable-next-line import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires
const frontendHandlerModule = require(frontendPlugins[context.exeInfo.projectConfig.frontend]);
await frontendHandlerModule.publish(context);
}
Expand Down
8 changes: 8 additions & 0 deletions packages/amplify-e2e-core/src/categories/hosting.ts
Expand Up @@ -159,6 +159,14 @@ export function amplifyPublishWithoutUpdate(cwd: string): Promise<void> {
});
}

/**
* executes publish command with yes flag
*/
export const amplifyPublishWithoutUpdateWithYesFlag = async (cwd: string): Promise<void> => {
const chain = spawn(getCLIPath(), ['publish', '-y'], { cwd, stripColors: true });
return chain.runAsync();
};

export function removeHosting(cwd: string): Promise<void> {
return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['remove', 'hosting'], { cwd, stripColors: true })
Expand Down
14 changes: 13 additions & 1 deletion packages/amplify-e2e-tests/src/__tests__/hosting.test.ts
@@ -1,3 +1,4 @@
/* eslint-disable max-lines-per-function */
import {
amplifyPublishWithoutUpdate,
createReactTestProject,
Expand All @@ -11,8 +12,8 @@ import {
deleteS3Bucket,
deleteProjectDir,
getProjectMeta,
amplifyPublishWithoutUpdateWithYesFlag
} from '@aws-amplify/amplify-e2e-core';

import * as fs from 'fs-extra';
import * as path from 'path';

Expand All @@ -34,6 +35,7 @@ describe('amplify add hosting', () => {
if (hostingBucket) {
try {
await deleteS3Bucket(hostingBucket);
// eslint-disable-next-line no-empty
} catch {}
}
deleteProjectDir(projRoot);
Expand All @@ -56,6 +58,16 @@ describe('amplify add hosting', () => {
expect(error).not.toBeDefined();
});

it('publish successfully with yes flag', async () => {
let error;
try {
await amplifyPublishWithoutUpdateWithYesFlag(projRoot);
} catch (err) {
error = err;
}
expect(error).not.toBeDefined();
});

it('publish throws error if build command is missing', async () => {
const currentBuildCommand = resetBuildCommand(projRoot, '');
let error;
Expand Down

0 comments on commit 860a0e5

Please sign in to comment.