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: misleading publish errors #769

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"scripts": {
"postpack": "rm -f oclif.manifest.json",
"lint": "eslint src test",
"lint-fix": "npm run lint -- --fix",
"prepack": "oclif manifest && oclif readme --no-aliases",
"test": "npm run unit-tests && npm run lint",
"unit-tests": "jest -c jest.config.js",
Expand Down
16 changes: 10 additions & 6 deletions src/commands/app/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ class Deploy extends BuildCommand {
}
}

// 2. Bail if workspace is production and application status is PUBLISHED, honor force-deploy
if (!isStandaloneApp && aioConfig?.project?.workspace?.name === 'Production' && !flags['force-deploy']) {
// 2. If workspace is prod and has extensions, check if the app is published
if (!isStandaloneApp && aioConfig?.project?.workspace?.name === 'Production') {
const extension = await this.getApplicationExtension(libConsoleCLI, aioConfig)
spinner.info(chalk.dim(JSON.stringify(extension)))
if (extension && extension.status === 'PUBLISHED') {
spinner.info(chalk.red('This application is published and the current workspace is Production, deployment will be skipped. You must first retract this application in Adobe Exchange to deploy updates.'))
return
flags.publish = false // if the app is production and published, then skip publish later on
// if the app is published and no force-deploy flag is set, then skip deployment
if (!flags['force-deploy']) {
spinner.info(chalk.red('This application is published and the current workspace is Production, deployment will be skipped. You must first retract this application in Adobe Exchange to deploy updates.'))
return
}
}
}

Expand Down Expand Up @@ -342,7 +345,8 @@ Deploy.flags = {
}),
'force-deploy': Flags.boolean({
description: '[default: false] Force deploy changes, regardless of production Workspace being published in Exchange.',
default: false
default: false,
exclusive: ['publish', 'force-publish'] // publish is skipped if force-deploy is set and prod app is published
}),
'force-publish': Flags.boolean({
description: '[default: false] Force publish extension(s) to Exchange, delete previously published extension points',
Expand Down
90 changes: 81 additions & 9 deletions test/commands/app/deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ const mockExtRegExcShellPayload = () => {
mockLibConsoleCLI.updateExtensionPoints.mockReturnValueOnce(payload)
}

const mockExtRegExcShellPayloadFailure = () => {
const payload = {
endpoints: {
'dx/excshell/1': {
view: [
{ metadata: {} }
]
}
}
}
helpers.buildExtensionPointPayloadWoMetadata.mockReturnValueOnce(payload)
mockLibConsoleCLI.updateExtensionPointsWithoutOverwrites.mockRejectedValueOnce(new Error('mock error'))
}

const mockExtRegExcShellAndNuiPayload = () => {
const payload = {
endpoints: {
Expand All @@ -100,22 +114,22 @@ const mockGetExtensionPointsRetractedApp = () => {
status: 'RETRACTED',
appId: '1234'
}]
mockLibConsoleCLI.getApplicationExtensions.mockReturnValueOnce(payload)
mockLibConsoleCLI.getApplicationExtensions.mockReturnValue(payload)
}

const mockGetExtensionPointsPublishedApp = () => {
const payload = [{
status: 'PUBLISHED',
appId: '1234'
}]
mockLibConsoleCLI.getApplicationExtensions.mockReturnValueOnce(payload)
mockLibConsoleCLI.getApplicationExtensions.mockReturnValue(payload)
}

const mockGetProject = () => {
const payload = {
appId: '1234'
}
mockLibConsoleCLI.getProject.mockReturnValueOnce(payload)
mockLibConsoleCLI.getProject.mockReturnValue(payload)
}

const mockLibConsoleCLI = {
Expand Down Expand Up @@ -614,6 +628,18 @@ describe('run', () => {

test('deploy (--no-actions and --no-web-assets) for application - nothing to be done', async () => {
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig))
command.getFullConfig.mockResolvedValue({
aio: {
project: {
workspace: {
name: 'Production'
},
org: {
id: '1111'
}
}
}
})
const noScriptFound = undefined
helpers.runInProcess
.mockResolvedValueOnce(noScriptFound) // pre-app-deploy
Expand All @@ -628,12 +654,17 @@ describe('run', () => {
})

test('deploy (--no-actions and --no-web-assets) for extension - publish', async () => {
mockGetProject()
mockGetExtensionPointsRetractedApp()
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig, 'exc'))
command.getFullConfig.mockResolvedValue({
aio: {
project: {
workspace: {
name: 'foo'
},
org: {
id: '1111'
}
}
}
Expand Down Expand Up @@ -837,12 +868,40 @@ describe('run', () => {
command.argv = ['--force-deploy']
await command.run()

expect(mockLibConsoleCLI.getProject).toHaveBeenCalledTimes(0)
expect(mockLibConsoleCLI.getApplicationExtensions).toHaveBeenCalledTimes(0)
expect(mockLibConsoleCLI.getProject).toHaveBeenCalledTimes(1)
expect(mockLibConsoleCLI.getApplicationExtensions).toHaveBeenCalledTimes(1)
expect(mockWebLib.deployWeb).toHaveBeenCalledTimes(1)
expect(mockRuntimeLib.deployActions).toHaveBeenCalledTimes(1)
expect(mockLibConsoleCLI.updateExtensionPoints).toHaveBeenCalledTimes(0)
expect(mockLibConsoleCLI.updateExtensionPointsWithoutOverwrites).toHaveBeenCalledTimes(1)
expect(mockLibConsoleCLI.updateExtensionPointsWithoutOverwrites).toHaveBeenCalledTimes(0)
})

test('deploy for PUBLISHED Production extension - force deploy, fails to publish', async () => {
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig, 'exc'))
mockGetExtensionPointsPublishedApp()
mockGetProject()
command.getFullConfig.mockResolvedValue({
aio: {
project: {
workspace: {
name: 'Production'
},
org: {
id: '1111'
}
}
}
})
mockExtRegExcShellPayloadFailure()
command.argv = ['--force-deploy']
await command.run()

expect(mockLibConsoleCLI.getProject).toHaveBeenCalledTimes(1)
expect(mockLibConsoleCLI.getApplicationExtensions).toHaveBeenCalledTimes(1)
expect(mockWebLib.deployWeb).toHaveBeenCalledTimes(1)
expect(mockRuntimeLib.deployActions).toHaveBeenCalledTimes(1)
expect(mockLibConsoleCLI.updateExtensionPoints).toHaveBeenCalledTimes(0)
expect(mockLibConsoleCLI.updateExtensionPointsWithoutOverwrites).toHaveBeenCalledTimes(0)
})

test('deploy for Production legacy app', async () => {
Expand Down Expand Up @@ -871,11 +930,9 @@ describe('run', () => {
})

test('deploy for RETRACTED Production extension - publish', async () => {
mockLibConsoleCLI.getApplicationExtensions.mockReset()

command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig, 'exc'))
mockGetExtensionPointsRetractedApp()
mockGetProject()
mockGetExtensionPointsRetractedApp()
command.getFullConfig.mockResolvedValue({
aio: {
project: {
Expand All @@ -900,12 +957,17 @@ describe('run', () => {
})

test('publish phase (no force, exc+nui payload)', async () => {
mockGetProject()
mockGetExtensionPointsRetractedApp()
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig, 'app-exc-nui'))
command.getFullConfig.mockResolvedValue({
aio: {
project: {
workspace: {
name: 'foo'
},
org: {
id: '1111'
}
}
}
Expand All @@ -920,12 +982,17 @@ describe('run', () => {
})

test('publish phase (no force, nui payload + no view operation)', async () => {
mockGetProject()
mockGetExtensionPointsRetractedApp()
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig, 'app-exc-nui'))
command.getFullConfig.mockResolvedValue({
aio: {
project: {
workspace: {
name: 'foo'
},
org: {
id: '1111'
}
}
}
Expand All @@ -950,12 +1017,17 @@ describe('run', () => {
})

test('publish phase (--force-publish, exc+nui payload)', async () => {
mockGetProject()
mockGetExtensionPointsRetractedApp()
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig, 'exc'))
command.getFullConfig.mockResolvedValue({
aio: {
project: {
workspace: {
name: 'foo'
},
org: {
id: '1111'
}
}
}
Expand Down
Loading