Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit c736b95

Browse files
committed
[BUG FIX] Variable group is created too late in spk setup command
1 parent 1766787 commit c736b95

File tree

13 files changed

+164
-84
lines changed

13 files changed

+164
-84
lines changed

docs/commands/data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,4 +721,4 @@
721721
],
722722
"markdown": "## Description\n\nInstall the build and push to acr pipeline for a service to your Azure DevOps\ninstance. The default pipeline generated by `spk service create` is a multistage\npipeline, which is in public preview and must be enabled to use.\nhttps://docs.microsoft.com/en-us/azure/devops/pipelines/process/stages?view=azure-devops&tabs=yaml\n"
723723
}
724-
}
724+
}

src/commands/project/create-variable-group.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
validateForRequiredValues,
1212
} from "../../lib/commandBuilder";
1313
import { PROJECT_PIPELINE_FILENAME } from "../../lib/constants";
14-
import { AzureDevOpsOpts } from "../../lib/git";
1514
import { addVariableGroup } from "../../lib/pipelines/variableGroup";
1615
import {
1716
hasValue,

src/commands/setup.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import * as promptInstance from "../lib/setup/prompt";
1515
import * as scaffold from "../lib/setup/scaffold";
1616
import * as setupLog from "../lib/setup/setupLog";
1717
import * as azureStorage from "../lib/setup/azureStorage";
18+
import * as variableGroup from "../lib/setup/variableGroup";
19+
import * as shell from "../lib/shell";
1820
import { deepClone } from "../lib/util";
1921
import { ConfigYaml } from "../types";
2022
import {
@@ -23,6 +25,7 @@ import {
2325
execute,
2426
getAPIClients,
2527
getErrorMessage,
28+
isAzCLIInstall,
2629
} from "./setup";
2730
import * as setup from "./setup";
2831

@@ -38,6 +41,8 @@ const mockRequestContext: RequestContext = {
3841
workspace: WORKSPACE,
3942
};
4043

44+
jest.spyOn(variableGroup, "setupVariableGroup").mockResolvedValue();
45+
4146
describe("test createSPKConfig function", () => {
4247
it("positive test", () => {
4348
const tmpFile = path.join(createTempDir(), "config.yaml");
@@ -420,3 +425,25 @@ describe("test getAPIClients function", () => {
420425
);
421426
});
422427
});
428+
429+
describe("test isAzCLIInstall function", () => {
430+
it("positive test", async () => {
431+
const version = JSON.stringify({
432+
"azure-cli": "2.0.79",
433+
});
434+
jest.spyOn(shell, "exec").mockResolvedValueOnce(version);
435+
await isAzCLIInstall();
436+
});
437+
it("negative test: version is not returned", async () => {
438+
jest.spyOn(shell, "exec").mockResolvedValueOnce("");
439+
await expect(isAzCLIInstall()).rejects.toThrow(
440+
errorMessage("setup-cmd-az-cli-err")
441+
);
442+
});
443+
it("negative test: az is not installed", async () => {
444+
jest.spyOn(shell, "exec").mockRejectedValueOnce(Error("test"));
445+
await expect(isAzCLIInstall()).rejects.toThrow(
446+
errorMessage("setup-cmd-az-cli-err")
447+
);
448+
});
449+
});

src/commands/setup.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
manifestRepo,
3939
} from "../lib/setup/scaffold";
4040
import { create as createSetupLog } from "../lib/setup/setupLog";
41+
import { setupVariableGroup } from "../lib/setup/variableGroup";
4142
import { logger } from "../logger";
4243
import decorator from "./setup.decorator.json";
4344
import { createStorage } from "../lib/setup/azureStorage";
@@ -188,6 +189,7 @@ export const createAppRepoTasks = async (
188189
rc.acrName,
189190
RESOURCE_GROUP_LOCATION
190191
);
192+
await setupVariableGroup(rc);
191193
await helmRepo(gitAPI, rc);
192194
await appRepo(gitAPI, rc);
193195
await createLifecyclePipeline(buildAPI, rc);
@@ -266,6 +268,7 @@ export const execute = async (
266268
const { coreAPI, gitAPI, buildAPI } = await getAPIClients();
267269

268270
await createProjectIfNotExist(coreAPI, rc);
271+
await setupVariableGroup(rc);
269272
await hldRepo(gitAPI, rc);
270273
await manifestRepo(gitAPI, rc);
271274
await createHLDtoManifestPipeline(buildAPI, rc);

src/lib/azure/keyvault.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { PipelineOptions } from "@azure/core-http";
21
import { KeyVaultSecret } from "@azure/keyvault-secrets";
32
import uuid from "uuid/v4";
43
import { disableVerboseLogging, enableVerboseLogging } from "../../logger";
54
import { getErrorMessage } from "../errorBuilder";
65
import * as azurecredentials from "./azurecredentials";
76
import { getClient, getSecret, setSecret } from "./keyvault";
87
import * as keyvault from "./keyvault";
9-
import { TokenCredential } from "azure-storage";
108

119
const keyVaultName = uuid();
1210
const mockedName = uuid();

src/lib/fileutils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
VM_IMAGE,
2525
BEDROCK_FILENAME,
2626
} from "../lib/constants";
27-
import { disableVerboseLogging, enableVerboseLogging, logger } from "../logger";
27+
import { disableVerboseLogging, enableVerboseLogging } from "../logger";
2828
import {
2929
createTestComponentYaml,
3030
createTestHldAzurePipelinesYaml,

src/lib/i18n.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
"setup-cmd-git-api-err": "Could not get Git API client. Check the Azure DevOps credential.",
3131
"setup-cmd-build-api-err": "Could not get Build API client. Check the Azure DevOps credential.",
3232
"setup-cmd-cannot-locate-pr-for-approval": "Could not locate pull request for approval",
33+
"setup-cmd-create-variable-group-missing-pat": "Could not created variable group because Personal Access Token was missing.",
34+
"setup-cmd-create-variable-group-missing-acr-name": "Could not created variable group because ACR name was missing.",
35+
"setup-cmd-create-variable-group-missing-sp-id": "Could not created variable group because service principal id was missing.",
36+
"setup-cmd-create-variable-group-missing-sp-pwd": "Could not created variable group because service principal password was missing.",
37+
"setup-cmd-create-variable-group-missing-tenant-id": "Could not created variable group because service principal tenant id was missing.",
38+
"setup-cmd-create-variable-group-missing-storage-access-key": "Could not created variable group because storage account access key was missing.",
39+
"setup-cmd-create-variable-group-missing-storage-account-name": "Could not created variable group because storage account name was missing.",
40+
"setup-cmd-create-variable-group-missing-storage-table-name": "Could not created variable group because storage table name was missing.",
3341

3442
"spk-config-yaml-err-readyaml": "Could not load file, {0}.",
3543
"spk-config-yaml-var-undefined": "Environment variable needs to be defined for {0} since it's referenced in the config file.",

src/lib/setup/prompt.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
validationServicePrincipalInfoFromFile,
1515
} from "./prompt";
1616
import * as promptInstance from "./prompt";
17-
import * as gitService from "./gitService";
1817
import * as servicePrincipalService from "../azure/servicePrincipalService";
1918
import * as subscriptionService from "../azure/subscriptionService";
2019

src/lib/setup/prompt.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ import {
1616
import {
1717
ACR_NAME,
1818
DEFAULT_PROJECT_NAME,
19-
HLD_REPO,
2019
RequestContext,
2120
WORKSPACE,
2221
} from "./constants";
23-
import { getAzureRepoUrl } from "./gitService";
2422
import {
2523
azCLILogin,
2624
createWithAzCLI,

src/lib/setup/scaffold.test.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
import * as fs from "fs-extra";
33
import * as path from "path";
44
import simpleGit from "simple-git/promise";
5-
import * as cmdCreateVariableGroup from "../../commands/project/create-variable-group";
65
import * as projectInit from "../../commands/project/init";
6+
import * as cmdCreateVariableGroup from "../../commands/project/create-variable-group";
77
import * as createService from "../../commands/service/create";
88
import * as fileutils from "../../lib/fileutils";
9-
import * as variableGroup from "../../lib/pipelines/variableGroup";
10-
import * as sVariableGroup from "../setup/variableGroup";
119
import { createTempDir } from "../ioUtil";
1210
import {
1311
APP_REPO,
@@ -23,7 +21,6 @@ import {
2321
hldRepo,
2422
initService,
2523
manifestRepo,
26-
setupVariableGroup,
2724
} from "./scaffold";
2825
import * as scaffold from "./scaffold";
2926

@@ -160,11 +157,16 @@ describe("test appRepo function", () => {
160157
const git = simpleGit();
161158
git.init = jest.fn();
162159

163-
jest.spyOn(scaffold, "setupVariableGroup").mockResolvedValueOnce();
164160
jest.spyOn(scaffold, "initService").mockResolvedValueOnce();
165161
jest.spyOn(projectInit, "initialize").mockImplementationOnce(async () => {
166162
fs.createFileSync("README.md");
167163
});
164+
jest
165+
.spyOn(cmdCreateVariableGroup, "setVariableGroupInBedrockFile")
166+
.mockReturnValueOnce();
167+
jest
168+
.spyOn(cmdCreateVariableGroup, "updateLifeCyclePipeline")
169+
.mockReturnValueOnce();
168170

169171
await appRepo({} as any, createRequestContext(tempDir));
170172
const folder = path.join(tempDir, APP_REPO);
@@ -175,19 +177,6 @@ describe("test appRepo function", () => {
175177
jest.spyOn(createService, "createService").mockResolvedValueOnce();
176178
await initService(createRequestContext("test"), "test");
177179
});
178-
it("sanity test on setupVariableGroup", async () => {
179-
jest
180-
.spyOn(variableGroup, "deleteVariableGroup")
181-
.mockResolvedValueOnce(true);
182-
jest.spyOn(sVariableGroup, "create").mockResolvedValueOnce();
183-
jest
184-
.spyOn(cmdCreateVariableGroup, "setVariableGroupInBedrockFile")
185-
.mockReturnValueOnce();
186-
jest
187-
.spyOn(cmdCreateVariableGroup, "updateLifeCyclePipeline")
188-
.mockReturnValueOnce();
189-
await setupVariableGroup(createRequestContext("/dummy"));
190-
});
191180
it("negative test", async () => {
192181
const tempDir = createTempDir();
193182
jest.spyOn(gitService, "createRepoInAzureOrg").mockImplementation(() => {

0 commit comments

Comments
 (0)