Skip to content

Commit 132ade5

Browse files
Fix bug in local-deploy, add live test for OCI (#14592)
Fix bug in local-deploy, add live test for OCI ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/14592)
1 parent cdb0fd7 commit 132ade5

File tree

11 files changed

+285
-80
lines changed

11 files changed

+285
-80
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,9 @@ jobs:
710710

711711
steps:
712712
- uses: actions/checkout@v4
713+
with:
714+
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
715+
submodules: true
713716

714717
- name: Setup Node.js
715718
uses: actions/setup-node@v4
@@ -786,6 +789,6 @@ jobs:
786789
- name: Run Bicep Live E2E Tests (${{ matrix.environment }})
787790
run: npm ci && npm run test:live:${{ matrix.environment }}
788791
env:
789-
BICEP_CLI_DOTNET_RID: ${{ matrix.runtime.rid }}
792+
BICEP_CLI_DOTNET_RID: linux-musl-x64
790793
BICEP_CLI_EXECUTABLE: ../../../Bicep.Cli.E2eTests/src/temp/bicep-cli/bicep
791794
working-directory: ./src/Bicep.Cli.E2eTests
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"experimentalFeaturesEnabled": {
3+
"extensibility": true,
4+
"extensionRegistry": true,
5+
"localDeploy": true
6+
},
7+
"extensions": {
8+
"mock": "$TARGET_REFERENCE"
9+
},
10+
"cloud": {
11+
"currentProfile": "AzureUSGovernment",
12+
"credentialPrecedence": [
13+
// used by CI
14+
"Environment",
15+
"AzureCLI"
16+
]
17+
}
18+
}

src/Bicep.Cli.E2eTests/src/examples/local-deploy/bicepconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"extensibility": true,
44
"extensionRegistry": true,
55
"localDeploy": true
6+
},
7+
"extensions": {
8+
"mock": "$TARGET_REFERENCE"
69
}
710
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"experimentalFeaturesEnabled": {
3+
"extensibility": true,
4+
"extensionRegistry": true,
5+
"localDeploy": true
6+
},
7+
"extensions": {
8+
"mock": "$TARGET_REFERENCE"
9+
},
10+
"cloud": {
11+
"currentProfile": "AzureCloud",
12+
"credentialPrecedence": ["AzureCLI"]
13+
}
14+
}

src/Bicep.Cli.E2eTests/src/examples/local-deploy/main.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extension '../../temp/local-deploy/provider.tgz'
1+
extension mock
22

33
param payload string
44

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
/**
5+
* Live tests for "bicep local-deploy".
6+
*
7+
* @group live
8+
*/
9+
10+
import os from "os";
11+
import { invokingBicepCommand } from "./utils/command";
12+
import { copyToTempFile, pathToExampleFile, pathToTempFile } from "./utils/fs";
13+
import {
14+
platformSupportsLocalDeploy,
15+
publishExtension,
16+
} from "./utils/localdeploy";
17+
import { getEnvironment } from "./utils/liveTestEnvironments";
18+
import { BicepRegistryReferenceBuilder } from "./utils/br";
19+
import { itif } from "./utils/testHelpers";
20+
21+
describe("bicep local-deploy", () => {
22+
const environment = getEnvironment();
23+
const testArea = `local-deploy-live${environment.suffix}`;
24+
const builder = new BicepRegistryReferenceBuilder(
25+
environment.registryUri,
26+
testArea,
27+
);
28+
29+
itif(platformSupportsLocalDeploy())(
30+
"should publish and run an extension published to a registry",
31+
() => {
32+
const baseFolder = pathToExampleFile("local-deploy");
33+
const target = builder.getBicepReference("mock", "0.0.1");
34+
35+
const files = {
36+
bicep: copyToTempFile(baseFolder, "main.bicep", testArea),
37+
bicepparam: copyToTempFile(baseFolder, "main.bicepparam", testArea),
38+
bicepconfig: copyToTempFile(
39+
baseFolder,
40+
`bicepconfig${environment.suffix}.json`,
41+
testArea,
42+
{
43+
relativePath: "bicepconfig.json",
44+
values: {
45+
$TARGET_REFERENCE: target,
46+
},
47+
},
48+
),
49+
};
50+
51+
const typesIndexPath = pathToTempFile(testArea, "types", "index.json");
52+
publishExtension(typesIndexPath, target)
53+
.shouldSucceed()
54+
.withEmptyStdout();
55+
56+
invokingBicepCommand("local-deploy", files.bicepparam)
57+
.shouldSucceed()
58+
.withStdout(
59+
[
60+
'Output sayHiResult: "Hello, World!"',
61+
"Resource sayHi (Create): Succeeded",
62+
"Result: Succeeded",
63+
"",
64+
].join(os.EOL),
65+
);
66+
},
67+
);
68+
});

src/Bicep.Cli.E2eTests/src/localDeploy.test.ts

Lines changed: 41 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,85 +7,50 @@
77
* @group CI
88
*/
99

10-
import spawn from "cross-spawn";
1110
import os from "os";
12-
import path from "path";
1311
import { invokingBicepCommand } from "./utils/command";
12+
import { copyToTempFile, pathToExampleFile, pathToTempFile } from "./utils/fs";
1413
import {
15-
ensureParentDirExists,
16-
expectFileExists,
17-
pathToExampleFile,
18-
pathToTempFile,
19-
} from "./utils/fs";
20-
21-
const itif = (condition: boolean) => condition ? it : it.skip;
22-
const cliDotnetRid = process.env.BICEP_CLI_DOTNET_RID;
23-
// We don't have an easy way of running this test for linux-musl-x64 RID, so skip for now.
24-
const canRunLocalDeploy = () => !cliDotnetRid || architectures.map(x => x.dotnetRid).includes(cliDotnetRid);
25-
26-
const mockExtensionExeName = 'bicep-ext-mock';
27-
const mockExtensionProjPath = path.resolve(
28-
__dirname,
29-
"../../Bicep.Local.Extension.Mock"
30-
);
31-
32-
const architectures = [
33-
{ dotnetRid: 'osx-arm64', bicepArgs: ['--bin-osx-arm64', `${mockExtensionProjPath}/bin/release/net8.0/osx-arm64/publish/${mockExtensionExeName}`] },
34-
{ dotnetRid: 'osx-x64', bicepArgs: ['--bin-osx-x64', `${mockExtensionProjPath}/bin/release/net8.0/osx-x64/publish/${mockExtensionExeName}`] },
35-
{ dotnetRid: 'linux-x64', bicepArgs: ['--bin-linux-x64', `${mockExtensionProjPath}/bin/release/net8.0/linux-x64/publish/${mockExtensionExeName}`] },
36-
{ dotnetRid: 'win-x64', bicepArgs: ['--bin-win-x64', `${mockExtensionProjPath}/bin/release/net8.0/win-x64/publish/${mockExtensionExeName}.exe`] },
37-
];
14+
platformSupportsLocalDeploy,
15+
publishExtension,
16+
} from "./utils/localdeploy";
17+
import { itif } from "./utils/testHelpers";
3818

3919
describe("bicep local-deploy", () => {
40-
itif(canRunLocalDeploy())("should build and deploy a provider published to the local file system", () => {
41-
42-
for (const arch of architectures) {
43-
execDotnet(['publish', '--verbosity', 'quiet', '--configuration', 'release', '--self-contained', 'true', '-r', arch.dotnetRid, mockExtensionProjPath]);
44-
}
45-
46-
const typesIndexPath = pathToTempFile("local-deploy", "types", "index.json");
47-
const typesDir = path.dirname(typesIndexPath);
48-
ensureParentDirExists(typesIndexPath);
49-
50-
execDotnet(['run', '--verbosity', 'quiet', '--project', mockExtensionProjPath], {
51-
MOCK_TYPES_OUTPUT_PATH: typesDir,
52-
});
53-
54-
const targetPath = pathToTempFile("local-deploy", "provider.tgz");
55-
56-
invokingBicepCommand(
57-
"publish-provider",
58-
typesIndexPath,
59-
"--target",
60-
targetPath,
61-
...(architectures.flatMap(arch => arch.bicepArgs))
62-
)
63-
.shouldSucceed()
64-
.withEmptyStdout();
65-
66-
expectFileExists(targetPath);
67-
68-
const bicepparamFilePath = pathToExampleFile("local-deploy", "main.bicepparam");
69-
70-
invokingBicepCommand("local-deploy", bicepparamFilePath)
71-
.shouldSucceed()
72-
.withStdout([
73-
'Output sayHiResult: "Hello, World!"',
74-
'Resource sayHi (Create): Succeeded',
75-
'Result: Succeeded',
76-
''
77-
].join(os.EOL));
78-
});
20+
const testArea = "local-deploy";
21+
22+
itif(platformSupportsLocalDeploy())(
23+
"should publish and run an extension published to the local file system",
24+
() => {
25+
const baseFolder = pathToExampleFile("local-deploy");
26+
const target = pathToTempFile(testArea, "mock.tgz");
27+
28+
const files = {
29+
bicep: copyToTempFile(baseFolder, "main.bicep", testArea),
30+
bicepparam: copyToTempFile(baseFolder, "main.bicepparam", testArea),
31+
bicepconfig: copyToTempFile(baseFolder, `bicepconfig.json`, testArea, {
32+
relativePath: "bicepconfig.json",
33+
values: {
34+
$TARGET_REFERENCE: "./mock.tgz",
35+
},
36+
}),
37+
};
38+
39+
const typesIndexPath = pathToTempFile(testArea, "types", "index.json");
40+
publishExtension(typesIndexPath, target)
41+
.shouldSucceed()
42+
.withEmptyStdout();
43+
44+
invokingBicepCommand("local-deploy", files.bicepparam)
45+
.shouldSucceed()
46+
.withStdout(
47+
[
48+
'Output sayHiResult: "Hello, World!"',
49+
"Resource sayHi (Create): Succeeded",
50+
"Result: Succeeded",
51+
"",
52+
].join(os.EOL),
53+
);
54+
},
55+
);
7956
});
80-
81-
function execDotnet(args: string[], envOverrides?: NodeJS.ProcessEnv) {
82-
const result = spawn.sync('dotnet', args, {
83-
encoding: 'utf-8',
84-
stdio: 'inherit',
85-
env: {
86-
...process.env,
87-
...(envOverrides ?? {})
88-
}
89-
});
90-
expect(result.status).toBe(0);
91-
}

src/Bicep.Cli.E2eTests/src/utils/fs.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,23 @@ export function writeTempFile(
8383

8484
export function ensureParentDirExists(filePath: string): void {
8585
fs.mkdirSync(path.dirname(filePath), { recursive: true });
86-
}
86+
}
87+
88+
export function copyToTempFile(
89+
baseFolder: string,
90+
relativePath: string,
91+
testArea: string,
92+
replace?: {
93+
values: Record<string, string>;
94+
relativePath: string
95+
}
96+
) {
97+
const fileContents = readFileSync(path.join(baseFolder, relativePath));
98+
99+
const replacedContents = Object.entries(replace?.values ?? {}).reduce(
100+
(contents, [from, to]) => contents.replace(from, to),
101+
fileContents,
102+
);
103+
104+
return writeTempFile(testArea, replace?.relativePath ?? relativePath, replacedContents);
105+
}

0 commit comments

Comments
 (0)