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

SALTO-7102: Supporting multiple "start" statuses in CLI deploy #7004

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
35 changes: 18 additions & 17 deletions packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
formatGroups,
deployErrorsOutput,
formatDeploymentSummary,
formatActionUpdate,
} from '../formatter'
import Prompts from '../prompts'
import { getUserBooleanInput } from '../callbacks'
Expand Down Expand Up @@ -141,21 +142,26 @@ const deployPlan = async (
}
}

const errorAction = (itemName: string, details: string | Progress): void => {
const errorAction = (itemName: string, details: string): void => {
const action = actions[itemName]
if (action !== undefined) {
errorOutputLine(formatItemError(itemName, _.isString(details) ? details : details.message), output)
errorOutputLine(formatItemError(itemName, details), output)
if (action.intervalId) {
clearInterval(action.intervalId)
}
}
}

const cancelAction = (itemName: string, details: string | Progress): void => {
outputLine(formatCancelAction(itemName, _.isString(details) ? details : details.message), output)
const cancelAction = (itemName: string, details: string): void => {
outputLine(formatCancelAction(itemName, details), output)
}

const startAction = (itemName: string, item: PlanItem): void => {
const startAction = (itemName: string, item: PlanItem, details?: string): void => {
if (actions[itemName] && details) {
outputLine(formatActionUpdate(itemName, details), output)
return
}

const startTime = new Date()
const intervalId = setInterval(() => {
outputLine(formatActionInProgress(itemName, item.action, startTime), output)
Expand All @@ -172,14 +178,15 @@ const deployPlan = async (
const updateAction = (item: PlanItem, status: ItemStatus, details?: string | Progress): void => {
const itemName = item.groupKey
if (itemName) {
const detailsString = _.isString(details) ? details : details?.message
if (status === 'started') {
startAction(itemName, item)
startAction(itemName, item, detailsString)
} else if (actions[itemName] !== undefined && status === 'finished') {
endAction(itemName)
} else if (actions[itemName] !== undefined && status === 'error' && details !== undefined) {
errorAction(itemName, details)
} else if (status === 'cancelled' && details) {
cancelAction(itemName, details)
} else if (actions[itemName] !== undefined && status === 'error' && detailsString !== undefined) {
errorAction(itemName, detailsString)
} else if (status === 'cancelled' && detailsString) {
cancelAction(itemName, detailsString)
}
}
}
Expand All @@ -188,13 +195,7 @@ const deployPlan = async (
.flatMap(item => Array.from(item.changes()))
.map(change => applyFunctionToChangeDataSync(change, element => element.clone()))

const result = await deploy(
workspace,
actionPlan,
(item: PlanItem, step: ItemStatus, details?: string | Progress) => updateAction(item, step, details),
accounts,
checkOnly,
)
const result = await deploy(workspace, actionPlan, updateAction, accounts, checkOnly)

const summary = summarizeDeployChanges(requestedChanges, result.appliedChanges ?? [])
const nonErroredActions = Object.keys(actions).filter(
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ export const formatActionStart = (action: PlanItem): string => {
return elements.join('\n')
}

export const formatActionUpdate = (itemName: string, details: string): string => {
const styledItemName = formatItemName(itemName)
return body(`${styledItemName} ${details}\n`)
}

export const formatActionInProgress = (itemName: string, actionName: ActionName, start: Date): string => {
const elapsed = getElapsedTime(start)
const styledItemName = formatItemName(itemName)
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/test/commands/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ describe('deploy command', () => {
})
})
describe('when there are deploy actions', () => {
const testDeployActionsVisability = async (userBooleanInput: boolean): Promise<void> => {
const testDeployActionsVisibility = async (userBooleanInput: boolean): Promise<void> => {
mockGetUserBooleanInput.mockResolvedValueOnce(userBooleanInput)
await action({
...cliCommandArgs,
Expand Down Expand Up @@ -482,10 +482,10 @@ describe('deploy command', () => {
expect(mockedDeploy.shouldDeploy).toHaveBeenCalled()
}
it('should print deploy actions when deploy is done', async () => {
await testDeployActionsVisability(true)
await testDeployActionsVisibility(true)
})
it('should print deploy actions when deploy is canceled', async () => {
await testDeployActionsVisability(false)
await testDeployActionsVisibility(false)
})
})
describe('Using environment variable', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/salesforce-adapter/src/adapter_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export const createDeployProgressReporter = async (
suffix = args.suffix
if (!wasDeploymentIdReported && deployResult.id) {
wasDeploymentIdReported = true
const message = `Deployment with ID ${deployResult.id} was created in Salesforce.`
const message = `Deployment with ID ${deployResult.id} was created in Salesforce.`
log.debug(message)
progressReporter.reportProgress({
message,
Expand Down