Skip to content

Commit d6139de

Browse files
authored
Update deploy logic with latest activity children (#868)
1 parent 75f429f commit d6139de

File tree

9 files changed

+71
-37
lines changed

9 files changed

+71
-37
lines changed

src/commands/AzureWizardActivityOutputExecuteStep.ts

Whitespace-only changes.

src/commands/StartingResourcesLogStep.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { LocationListStep, type ILocationWizardContext } from "@microsoft/vscode
99
import { ActivityChildItem, ActivityChildType, activityInfoIcon, AzureWizardPromptStep, createContextValue, type ExecuteActivityContext, type IActionContext } from "@microsoft/vscode-azext-utils";
1010
import { activityInfoContext } from "../constants";
1111
import { ext } from "../extensionVariables";
12+
import { prependOrInsertAfterLastInfoChild } from "../utils/activityUtils";
1213
import { localize } from "../utils/localize";
1314

1415
type StartingResourcesLogContext = IActionContext & Partial<ExecuteActivityContext> & ILocationWizardContext & {
@@ -50,7 +51,7 @@ export class StartingResourcesLogStep<T extends StartingResourcesLogContext> ext
5051

5152
protected async logStartingResources(context: T): Promise<void> {
5253
if (context.resourceGroup) {
53-
context.activityChildren?.push(
54+
prependOrInsertAfterLastInfoChild(context,
5455
new ActivityChildItem({
5556
contextValue: createContextValue([startingResourcesContext, activityInfoContext]),
5657
label: localize('useResourceGroup', 'Use resource group "{0}"', context.resourceGroup.name),
@@ -62,7 +63,7 @@ export class StartingResourcesLogStep<T extends StartingResourcesLogContext> ext
6263
}
6364

6465
if (context.managedEnvironment) {
65-
context.activityChildren?.push(
66+
prependOrInsertAfterLastInfoChild(context,
6667
new ActivityChildItem({
6768
label: localize('useManagedEnvironment', 'Use managed environment "{0}"', context.managedEnvironment.name),
6869
contextValue: createContextValue([startingResourcesContext, activityInfoContext]),
@@ -74,7 +75,7 @@ export class StartingResourcesLogStep<T extends StartingResourcesLogContext> ext
7475
}
7576

7677
if (context.containerApp) {
77-
context.activityChildren?.push(
78+
prependOrInsertAfterLastInfoChild(context,
7879
new ActivityChildItem({
7980
label: localize('useContainerApp', 'Use container app "{0}"', context.containerApp.name),
8081
contextValue: createContextValue([startingResourcesContext, activityInfoContext]),

src/commands/deployWorkspaceProject/deploymentConfiguration/workspace/azureResources/AzureResourceVerifyStepBase.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ export abstract class AzureResourceVerifyStepBase<T extends WorkspaceDeploymentC
6262
};
6363
}
6464

65-
// Todo: Verify if we need progress output
66-
6765
public createFailOutput(context: T): ExecuteActivityOutput {
6866
return {
6967
item: new ActivityChildItem({

src/commands/deployWorkspaceProject/internal/deployWorkspaceProjectInternal.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ActivityChildItem, ActivityChildType, AzureWizard, activityInfoContext,
99
import { ProgressLocation, window } from "vscode";
1010
import { appProvider, managedEnvironmentsId } from "../../../constants";
1111
import { ext } from "../../../extensionVariables";
12-
import { createActivityContext } from "../../../utils/activityUtils";
12+
import { createActivityContext, prependOrInsertAfterLastInfoChild } from "../../../utils/activityUtils";
1313
import { getVerifyProvidersStep } from "../../../utils/getVerifyProvidersStep";
1414
import { localize } from "../../../utils/localize";
1515
import { ContainerAppCreateStep } from "../../createContainerApp/ContainerAppCreateStep";
@@ -69,8 +69,7 @@ export async function deployWorkspaceProjectInternal(
6969
if (options.suppressActivity) {
7070
activityContext = { suppressNotification: true };
7171
} else {
72-
activityContext = await createActivityContext();
73-
activityContext.activityChildren = [];
72+
activityContext = await createActivityContext({ withChildren: true });
7473
}
7574

7675
// Show loading indicator while we configure starting values
@@ -114,7 +113,7 @@ export async function deployWorkspaceProjectInternal(
114113

115114
const resourceGroupName: string = nonNullValueAndProp(wizardContext.resourceGroup, 'name');
116115

117-
wizardContext.activityChildren?.push(
116+
prependOrInsertAfterLastInfoChild(wizardContext,
118117
new ActivityChildItem({
119118
label: localize('useResourceGroup', 'Use resource group "{0}"', resourceGroupName),
120119
activityType: ActivityChildType.Info,
@@ -136,7 +135,7 @@ export async function deployWorkspaceProjectInternal(
136135

137136
const managedEnvironmentName: string = nonNullValueAndProp(wizardContext.managedEnvironment, 'name');
138137

139-
wizardContext.activityChildren?.push(
138+
prependOrInsertAfterLastInfoChild(wizardContext,
140139
new ActivityChildItem({
141140
label: localize('useManagedEnvironment', 'Use container apps environment "{0}"', managedEnvironmentName),
142141
activityType: ActivityChildType.Info,
@@ -165,9 +164,9 @@ export async function deployWorkspaceProjectInternal(
165164

166165
const registryName: string = nonNullValueAndProp(wizardContext.registry, 'name');
167166

168-
wizardContext.activityChildren?.push(
167+
prependOrInsertAfterLastInfoChild(wizardContext,
169168
new ActivityChildItem({
170-
label: localize('useAcr', 'Using container registry "{0}"', registryName),
169+
label: localize('useAcr', 'Use container registry "{0}"', registryName),
171170
activityType: ActivityChildType.Info,
172171
contextValue: activityInfoContext,
173172
iconPath: activityInfoIcon
@@ -188,9 +187,9 @@ export async function deployWorkspaceProjectInternal(
188187

189188
executeSteps.push(new ContainerAppUpdateStep());
190189

191-
wizardContext.activityChildren?.push(
190+
prependOrInsertAfterLastInfoChild(wizardContext,
192191
new ActivityChildItem({
193-
label: localize('useContainerApp', 'Using container app "{0}"', containerAppName),
192+
label: localize('useContainerApp', 'Use container app "{0}"', containerAppName),
194193
activityType: ActivityChildType.Info,
195194
contextValue: activityInfoContext,
196195
iconPath: activityInfoIcon

src/commands/editContainer/RegistryAndSecretsUpdateStep.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { type RegistryCredentials, type Secret } from "@azure/arm-appcontainers";
7-
import { AzureWizardExecuteStep, nonNullProp } from "@microsoft/vscode-azext-utils";
7+
import { AzureWizardExecuteStepWithActivityOutput, nonNullProp } from "@microsoft/vscode-azext-utils";
88
import * as deepEqual from "deep-eql";
99
import { type Progress } from "vscode";
1010
import { ext } from "../../extensionVariables";
@@ -13,22 +13,37 @@ import { localize } from "../../utils/localize";
1313
import { updateContainerApp } from "../updateContainerApp";
1414
import { type ContainerEditContext } from "./ContainerEditContext";
1515

16-
export class RegistryAndSecretsUpdateStep<T extends ContainerEditContext> extends AzureWizardExecuteStep<T> {
16+
export class RegistryAndSecretsUpdateStep<T extends ContainerEditContext> extends AzureWizardExecuteStepWithActivityOutput<T> {
1717
public priority: number = 580;
18+
public stepName: string = 'registryAndSecretsUpdateStep';
19+
protected getOutputLogSuccess = (context: T) => localize('updateRegistryCredentialsSuccess', 'Successfully updated new registry credentials and secrets for container app "{0}".', context.containerApp?.name);
20+
protected getOutputLogFail = (context: T) => localize('updateRegistryCredentialsFail', 'Failed to update new registry credentials and secrets for container app "{0}".', context.containerApp?.name);
21+
protected getTreeItemLabel = () => localize('updateRegistryCredentialsLabel', 'Update registry credentials and secrets');
1822

19-
public async execute(context: T, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
23+
private skipRegistryCredentialUpdate: boolean;
24+
25+
public async configureBeforeExecute(context: T): Promise<void> {
2026
const containerApp: ContainerAppModel = nonNullProp(context, 'containerApp');
2127
const containerAppEnvelope = await getContainerEnvelopeWithSecrets(context, context.subscription, containerApp);
2228

2329
// If the credentials have not changed, we can skip this update
2430
if (
31+
context.secrets && context.registryCredentials &&
2532
this.areSecretsDeepEqual(containerAppEnvelope.configuration.secrets, context.secrets) &&
2633
this.areRegistriesDeepEqual(containerAppEnvelope.configuration.registries, context.registryCredentials)
2734
) {
35+
this.skipRegistryCredentialUpdate = true;
2836
context.telemetry.properties.skippedRegistryCredentialUpdate = 'true';
29-
return;
37+
ext.outputChannel.appendLog(localize('skippingCredentialUpdate', 'Verified existing registry credentials are up to date.'));
38+
} else {
39+
this.skipRegistryCredentialUpdate = false;
40+
context.telemetry.properties.skippedRegistryCredentialUpdate = 'false';
3041
}
31-
context.telemetry.properties.skippedRegistryCredentialUpdate = 'false';
42+
}
43+
44+
public async execute(context: T, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
45+
const containerApp: ContainerAppModel = nonNullProp(context, 'containerApp');
46+
const containerAppEnvelope = await getContainerEnvelopeWithSecrets(context, context.subscription, containerApp);
3247

3348
progress.report({ message: localize('configuringSecrets', 'Configuring registry secrets...') });
3449
containerAppEnvelope.configuration.secrets = context.secrets;
@@ -39,7 +54,7 @@ export class RegistryAndSecretsUpdateStep<T extends ContainerEditContext> extend
3954
}
4055

4156
public shouldExecute(context: T): boolean {
42-
return !!context.registryCredentials && !!context.secrets;
57+
return !!context.registryCredentials && !!context.secrets && !this.skipRegistryCredentialUpdate;
4358
}
4459

4560
private areSecretsDeepEqual(originalSecrets: Secret[] | undefined, newSecrets: Secret[] | undefined): boolean {

src/commands/image/imageSource/EnvFileListStep.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { type EnvironmentVar } from "@azure/arm-appcontainers";
7-
import { ActivityChildItem, ActivityChildType, AzExtFsExtra, AzureWizardPromptStep, activitySuccessContext, activitySuccessIcon, createContextValue } from "@microsoft/vscode-azext-utils";
7+
import { ActivityChildItem, ActivityChildType, AzExtFsExtra, AzureWizardPromptStep, activityInfoContext, activityInfoIcon, activitySuccessContext, activitySuccessIcon, createContextValue } from "@microsoft/vscode-azext-utils";
88
import { parse, type DotenvParseOutput } from "dotenv";
99
import { RelativePattern, workspace, type Uri, type WorkspaceFolder } from "vscode";
1010
import { ImageSource, envFileGlobPattern } from "../../../constants";
1111
import { ext } from "../../../extensionVariables";
1212
import { type EnvironmentVariableTelemetryProps as TelemetryProps } from "../../../telemetry/ImageSourceTelemetryProps";
1313
import { type SetTelemetryProps } from "../../../telemetry/SetTelemetryProps";
14+
import { prependOrInsertAfterLastInfoChild } from "../../../utils/activityUtils";
1415
import { localize } from "../../../utils/localize";
1516
import { selectWorkspaceFile } from "../../../utils/workspaceUtils";
1617
import { type EnvironmentVariablesContext } from "../../environmentVariables/EnvironmentVariablesContext";
@@ -146,7 +147,7 @@ export class EnvFileListStep<T extends EnvFileListContext> extends AzureWizardPr
146147
} else if (setEnvironmentVariableOption === SetEnvironmentVariableOption.ProvideFile) {
147148
context.activityChildren?.push(
148149
new ActivityChildItem({
149-
label: localize('saveEnvVarsFileLabel', 'Save environment variables using provided .env file'),
150+
label: localize('saveEnvVarsFileLabel', 'Save environment variables from provided .env file'),
150151
description: '0s',
151152
contextValue: createContextValue([envFileListStepContext, activitySuccessContext]),
152153
activityType: ActivityChildType.Success,
@@ -155,13 +156,12 @@ export class EnvFileListStep<T extends EnvFileListContext> extends AzureWizardPr
155156
);
156157
ext.outputChannel.appendLog(localize('savedEnvVarsFileMessage', 'Saved environment variables using provided .env file "{0}".', context.envPath));
157158
} else if (setEnvironmentVariableOption === SetEnvironmentVariableOption.UseExisting) {
158-
context.activityChildren?.push(
159+
prependOrInsertAfterLastInfoChild(context,
159160
new ActivityChildItem({
160161
label: localize('useExistingEnvVarsLabel', 'Use existing environment variable configuration'),
161-
description: '0s',
162-
contextValue: createContextValue([envFileListStepContext, activitySuccessContext]),
163-
activityType: ActivityChildType.Success,
164-
iconPath: activitySuccessIcon,
162+
contextValue: createContextValue([envFileListStepContext, activityInfoContext]),
163+
activityType: ActivityChildType.Info,
164+
iconPath: activityInfoIcon,
165165
})
166166
);
167167
ext.outputChannel.appendLog(localize('useExistingEnvVarsMessage', 'Used existing environment variable configuration.'));

src/commands/registryCredentials/RegistryCredentialsAddConfigurationListStep.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { ActivityChildItem, ActivityChildType, activitySuccessContext, activitySuccessIcon, AzureWizardPromptStep, createContextValue, nonNullProp, type AzureWizardExecuteStep, type IAzureQuickPickItem, type IWizardOptions } from "@microsoft/vscode-azext-utils";
7-
import { acrDomain, type SupportedRegistries } from "../../constants";
6+
import { ActivityChildItem, ActivityChildType, activityInfoIcon, AzureWizardPromptStep, createContextValue, nonNullProp, type AzureWizardExecuteStep, type IAzureQuickPickItem, type IWizardOptions } from "@microsoft/vscode-azext-utils";
7+
import { acrDomain, activityInfoContext, type SupportedRegistries } from "../../constants";
88
import { ext } from "../../extensionVariables";
9+
import { prependOrInsertAfterLastInfoChild } from "../../utils/activityUtils";
910
import { getRegistryDomainFromContext } from "../../utils/imageNameUtils";
1011
import { localize } from "../../utils/localize";
1112
import { AcrEnableAdminUserConfirmStep } from "./dockerLogin/AcrEnableAdminUserConfirmStep";
@@ -92,13 +93,12 @@ export class RegistryCredentialsAddConfigurationListStep extends AzureWizardProm
9293
break;
9394
default:
9495
context.telemetry.properties.newRegistryCredentialType = 'useExisting';
95-
context.activityChildren?.push(
96+
prependOrInsertAfterLastInfoChild(context,
9697
new ActivityChildItem({
97-
label: localize('useExistingRegistryCredentials', 'Use existing registry credential'),
98-
contextValue: createContextValue(['registryCredentialsAddConfigurationListStepItem', activitySuccessContext]),
99-
description: '0s',
100-
activityType: ActivityChildType.Success,
101-
iconPath: activitySuccessIcon,
98+
label: localize('useExistingRegistryCredentials', 'Use existing registry credentials'),
99+
contextValue: createContextValue(['registryCredentialsAddConfigurationListStepItem', activityInfoContext]),
100+
activityType: ActivityChildType.Info,
101+
iconPath: activityInfoIcon,
102102
})
103103
);
104104
ext.outputChannel.appendLog(localize('usingRegistryCredentials', 'Using existing registry credentials.'));

src/commands/revisionDraft/RevisionDraftUpdateBaseStep.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export abstract class RevisionDraftUpdateBaseStep<T extends RevisionDraftContext
4747
ext.revisionDraftFileSystem.updateRevisionDraftWithTemplate(this.baseItem, this.revisionDraftTemplate);
4848

4949
if (context.shouldDeployRevisionDraft) {
50-
await this.deployRevisionDraftTemplate(context);
50+
void this.deployRevisionDraftTemplate(context);
5151
}
5252
}
5353

src/utils/activityUtils.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { type ExecuteActivityContext } from "@microsoft/vscode-azext-utils";
6+
import { ActivityChildType, type ActivityChildItemBase, type ExecuteActivityContext } from "@microsoft/vscode-azext-utils";
77
import { type AzureResourcesExtensionApiWithActivity } from "@microsoft/vscode-azext-utils/activity";
88
import { ext } from "../extensionVariables";
99
import { settingUtils } from "./settingUtils";
@@ -15,3 +15,24 @@ export async function createActivityContext(options?: { withChildren?: boolean }
1515
activityChildren: options?.withChildren ? [] : undefined,
1616
};
1717
}
18+
19+
/**
20+
* Adds a new activity child after the last info child in the `activityChildren` array.
21+
* If no info child already exists, the new child is prepended to the front of the array.
22+
* (This utility function is useful for keeping the info children grouped at the front of the list)
23+
*/
24+
export function prependOrInsertAfterLastInfoChild(context: Partial<ExecuteActivityContext>, infoChild: ActivityChildItemBase): void {
25+
if (!context.activityChildren) {
26+
return;
27+
}
28+
29+
const idx: number = context.activityChildren
30+
.map(child => child.activityType)
31+
.lastIndexOf(ActivityChildType.Info);
32+
33+
if (idx === -1) {
34+
context.activityChildren.unshift(infoChild);
35+
} else {
36+
context.activityChildren.splice(idx + 1, 0, infoChild);
37+
}
38+
}

0 commit comments

Comments
 (0)