sharpliner / sharpliner

Use C# instead of YAML to define your Azure DevOps pipelines
https://www.nuget.org/packages/Sharpliner/
MIT License
285 stars 21 forks source link

Runtime + Compile + Macro Syntaxes for Variables and Parameters #233

Closed thomhurst closed 1 year ago

thomhurst commented 1 year ago

This provides strongly typed objects where users can call:

Parameter.RuntimeExpression => "parameters.Parameter"

Parameter.CompileTimeExpression => "{{ parameters.Parameter }}"

Variable.MacroExpression => "$(Variable)"

Variable.RuntimeExpression => "variables['Variable']"

Variable.CompileTimeExpression => "{{ variables.Variable }}

This gives the caller more control if they need it.

There's also new types with implicit conversions.

Strings implicitly convert to StringRuntimeExpression for string conditions. StringRuntimeExpression is an IRuntimeExpression. This means conditions can accept these raw string expressions, or the new variable objects, or the new parameter objects. Then we can pull the correct run-time syntax out of these objects.

Variables now also serialize to Macro syntax so they can be used in scripts and such, but still serialize to runtime syntax for conditions and such.

This PR might seem quite convoluted but I couldn't think of a cleaner way to do this. Let me know what you think.

See #232

thomhurst commented 1 year ago

The IYamlConvertible worked !

premun commented 1 year ago

@thomhurst this is really amazing, thank you!

I have actually heard many times online from people that mixing these types of variables causes them a lot of headache so I will update the README later to list this as one of the main features.