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

Enable supplemental params validation with build-params command #11975

Merged
merged 10 commits into from
Oct 2, 2023

Conversation

Usman0111
Copy link
Contributor

@Usman0111 Usman0111 commented Sep 28, 2023

Enable build-params command to use values from a BICEP_PARAMETERS_OVERRIDES environment variable to update the .bicepparam file

This work is to support the Inline overrides use case for az cli

Microsoft Reviewers: Open in CodeFlow

@github-actions
Copy link
Contributor

github-actions bot commented Sep 28, 2023

Test this change out locally with the following install scripts (Action run 6386146837)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 6386146837
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 6386146837"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 6386146837
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 6386146837"

@github-actions
Copy link
Contributor

github-actions bot commented Sep 28, 2023

Test Results

     132 files  ±0       132 suites  ±0   4h 0m 29s ⏱️ + 11m 51s
10 658 tests +2  10 657 ✔️ +1  0 💤 ±0  1 +1 
51 499 runs  +8  51 495 ✔️ +4  0 💤 ±0  4 +4 

For more details on these failures, see this check.

Results for commit 430d71f. ± Comparison against base commit c43ca5f.

♻️ This comment has been updated with latest results.

@Usman0111 Usman0111 marked this pull request as ready for review September 29, 2023 21:57
{
JTokenType.String => SyntaxFactory.CreateStringLiteral(value.ToString(CultureInfo.InvariantCulture)),
JTokenType.Integer => SyntaxFactory.CreatePositiveOrNegativeInteger(value.Value<long>()),
// Floats are currently not supported in Bicep, so fall back to the default behavior of "any"
Copy link
Member

Choose a reason for hiding this comment

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

Floats

When we eventually add Bicep support, will this behavior change (which could be a breaking change) or are we going to leave it as is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will likely have to change this behavior since we need to assign types that are as accurate as possible for correct type validation.

This behavior is similar to that of ConvertJsonToBicepType from SystemNamesapceType so I am thinking the breaking change (with the introduction of floats) would be in all locations where we are going from JSON to Bicep

Alternatively, we could also just block usage of floats to avoid breaking change at least in .bicepparam files

var fileContents = await File.ReadAllTextAsync(paramsInputPath);
var sourceFile = SourceFileFactory.CreateBicepParamFile(PathHelper.FilePathToFileUrl(paramsInputPath), fileContents);

var newProgramSyntax = CallbackRewriter.Rewrite(sourceFile.ProgramSyntax, syntax =>
Copy link
Member

Choose a reason for hiding this comment

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

Rewrite

Since we're modifying the user-provided file, what happens to the locations in the TextSpan objects on the generated syntax nodes? If the compiler decides to emit a diagnostic whose span involves one of the generated nodes, are we going to emit misleading locations?

This is likely out of scope for this PR, but I'm wondering if we need to add a concept of an "external" location for syntax nodes for scenarios such as this. (Plus semantics on how an external location interacts with regular locations when we do TextSpan calculations in the compiler.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue with line numbers is something we've discussed during parameters sync meeting multiple times. The solution two for question one in design gist somewhat attempts to solve this issue. However, we've decided to continue with current implementation as it is lower cost and errors are "good enough" for users to debug.

Adding an "external" location sounds like a great idea. I've linked this comment to the gist so we can track this in future discussions

Copy link
Member

@anthony-c-martin anthony-c-martin left a comment

Choose a reason for hiding this comment

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

Looks good!

@Usman0111 Usman0111 enabled auto-merge (squash) October 2, 2023 17:31
@Usman0111 Usman0111 merged commit c8c867a into main Oct 2, 2023
46 checks passed
@Usman0111 Usman0111 deleted the Usman0111/build-params-overload branch October 2, 2023 22:25
@charper-work
Copy link

Which milestone is this a part of? We are looking to use both bicepparams and inline parameters with our DevOps pipelines.

@anthony-c-martin
Copy link
Member

Which milestone is this a part of? We are looking to use both bicepparams and inline parameters with our DevOps pipelines.

This'll be available in the Azure CLI & Azure PowerShell upcoming releases on 11/14:
https://github.com/Azure/azure-cli/milestone/135
https://github.com/Azure/azure-powershell/milestone/152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants