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

allow using none statements in bicepparam files at build-params command #15107

Merged
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
26 changes: 26 additions & 0 deletions src/Bicep.Cli.IntegrationTests/BuildParamsCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,32 @@ public async Task Build_params_returns_intuitive_error_if_invoked_with_bicep_fil
result.Should().Fail().And.HaveStderrMatch($"Bicep file * provided with --bicep-file can only be used if the Bicep parameters \"using\" declaration refers to a Bicep file on disk.*");
}

[TestMethod]
[TestCategory(BaselineHelper.BaselineTestCategory)]
public async Task Build_params_works_with_using_none()
{
var outputPath = FileHelper.GetUniqueTestOutputPath(TestContext);

var bicepFile = FileHelper.SaveResultFile(TestContext, "main.bicep", @"
param unusedParam int
", outputPath);

var inputFile = FileHelper.SaveResultFile(TestContext, "main.bicepparam", @"
using none

param unusedParam = 3
", outputPath);

var (output, error, result) = await Bicep(["build-params", inputFile, "--bicep-file", bicepFile]);

var expectedOutputFile = FileHelper.GetResultFilePath(TestContext, "main.json", outputPath);

File.Exists(expectedOutputFile).Should().BeTrue();
output.Should().BeEmpty();
error.Should().BeEmpty();
result.Should().Be(0);
}

[TestMethod]
[EmbeddedFilesTestData(@"Files/BuildParamsCommandTests/Registry/main\.bicepparam")]
[TestCategory(BaselineHelper.BaselineTestCategory)]
Expand Down
17 changes: 10 additions & 7 deletions src/Bicep.Cli/Commands/BuildParamsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ public async Task<int> RunAsync(BuildParamsArguments args)
if (bicepFileUri is not null &&
compilation.GetEntrypointSemanticModel().Root.TryGetBicepFileSemanticModelViaUsing().IsSuccess(out var usingModel))
{
if (usingModel is not SemanticModel bicepSemanticModel)
Copy link
Member

@anthony-c-martin anthony-c-martin Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work with Azure CLI if the user doesn't provide a template? E.g. here. Would this cause an error?

Copy link
Member Author

@polatengin polatengin Nov 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the following content in main.bicep and main.bicepparam files;

// main.bicep
param bar string
// main.bicepparam
using none
param bar = 'foo'

When I run the following command, it successfully build the files;

dotnet run --project src/Bicep.Cli/Bicep.Cli.csproj -- build-params ./main.bicepparam --bicep-file ./main.bicep --stdout

If I understand your comment correctly, you're asking what happens if we don't provide --bicep-file ./main.bicep option;

dotnet run --project src/Bicep.Cli/Bicep.Cli.csproj -- build-params ./main.bicepparam --stdout

I ran the command and saw it successfully build the main.bicepparam file.

if (usingModel is not EmptySemanticModel)
{
throw new CommandLineException($"Bicep file {bicepFileUri.LocalPath} provided with --bicep-file can only be used if the Bicep parameters \"using\" declaration refers to a Bicep file on disk.");
}

if (!bicepSemanticModel.Root.FileUri.Equals(bicepFileUri))
{
throw new CommandLineException($"Bicep file {bicepFileUri.LocalPath} provided with --bicep-file option doesn't match the Bicep file {bicepSemanticModel.Root.Name} referenced by the \"using\" declaration in the parameters file.");
if (usingModel is not SemanticModel bicepSemanticModel)
{
throw new CommandLineException($"Bicep file {bicepFileUri.LocalPath} provided with --bicep-file can only be used if the Bicep parameters \"using\" declaration refers to a Bicep file on disk.");
}

if (!bicepSemanticModel.Root.FileUri.Equals(bicepFileUri))
{
throw new CommandLineException($"Bicep file {bicepFileUri.LocalPath} provided with --bicep-file option doesn't match the Bicep file {bicepSemanticModel.Root.Name} referenced by the \"using\" declaration in the parameters file.");
}
}
}

Expand Down
Loading