-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for case function #4147
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for a new case expression function that provides conditional evaluation similar to a switch/case or if-else-if chain. The function accepts an odd number of arguments: pairs of boolean predicates and their corresponding results, plus a default value.
- Implements the
Casefunction in multiple expression namespaces (GitHub.Actions.Expressions and GitHub.DistributedTask.Expressions2) - Adds an
AllowCaseFunctionflag to control whether the case function is available in specific contexts - Includes parser-level validation to ensure the case function receives an odd number of parameters
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Sdk/Expressions/Sdk/Functions/Case.cs | New implementation of the Case function for GitHub Actions expressions |
| src/Sdk/DTExpressions2/Expressions2/Sdk/Functions/Case.cs | Duplicate Case function implementation for DistributedTask expressions |
| src/Sdk/Expressions/ExpressionConstants.cs | Registers the case function with min 3 and max 255 parameters |
| src/Sdk/DTExpressions2/Expressions2/ExpressionConstants.cs | Registers the case function in DTExpressions2 namespace |
| src/Sdk/Expressions/ParseExceptionKind.cs | Adds EvenParameters exception type for case function validation |
| src/Sdk/DTExpressions2/Expressions2/ParseExceptionKind.cs | Adds EvenParameters exception type in DTExpressions2 |
| src/Sdk/Expressions/ParseException.cs | Adds error message for even parameter count |
| src/Sdk/DTExpressions2/Expressions2/ParseException.cs | Adds error message for even parameter count in DTExpressions2 |
| src/Sdk/Expressions/ExpressionParser.cs | Adds allowCaseFunction parameter and validation logic for even parameters |
| src/Sdk/DTExpressions2/Expressions2/ExpressionParser.cs | Adds allowCaseFunction parameter and validation logic in DTExpressions2 |
| src/Sdk/WorkflowParser/ObjectTemplating/TemplateContext.cs | Adds AllowCaseFunction property defaulting to true |
| src/Sdk/DTObjectTemplating/ObjectTemplating/TemplateContext.cs | Adds AllowCaseFunction property in DTObjectTemplating |
| src/Sdk/WorkflowParser/ObjectTemplating/Tokens/TemplateToken.cs | Passes AllowCaseFunction to expression parser in 4 evaluation methods |
| src/Sdk/DTObjectTemplating/ObjectTemplating/Tokens/TemplateToken.cs | Passes AllowCaseFunction to expression parser in 4 evaluation methods |
| src/Sdk/WorkflowParser/Conversion/WorkflowTemplateConverter.cs | Passes AllowCaseFunction when converting if conditions |
| src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs | Passes AllowCaseFunction when converting if conditions |
| src/Runner.Worker/ActionManifestManager.cs | Disables case function for action manifest parsing |
| src/Runner.Worker/ActionManifestManagerLegacy.cs | Disables case function for legacy action manifest parsing |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| try | ||
| { | ||
| var tree = new ExpressionParser().CreateTree(expression, null, context.GetExpressionNamedValues(), context.ExpressionFunctions); | ||
| var tree = new ExpressionParser().CreateTree(expression, null, context.GetExpressionNamedValues(), context.ExpressionFunctions, allowCaseFunction: context.AllowCaseFunction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this for the evaluator? Do we hardcode to true for the evaluator?
Basically I just want to make sure we set to true for evaluation. If evaluation works E2E then 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, this is defaulted to true but will allow the manifest manager code paths to disable it.
No description provided.