-
Notifications
You must be signed in to change notification settings - Fork 69
Conditional execution of steps with if:
#520
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.
Just one question about the TODO comment. Thanks!
410631c to
2bf1637
Compare
in: and if: attributes
eb233ff to
6605471
Compare
9608082 to
ef33f27
Compare
in: and if: attributesif:
|
@sourcegraph/batchers this has been updated to also allow And I extended how far we can statically evaluate the condition by implementing support for Go's |
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.
Very neat 🌟 Thanks a lot for picking up the suggestion of making it a single field and sorting out the caching with a partial evaluator :)
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.
This is really cool!
We might want to tighten up what's accepted here slightly: playing around with if conditions, I can see that we report errors in templates pretty nicely, but there's some weirdness with non-template strings. If I define a step with, say, if: dsjfldl, then that seems to silently gets treated as true right now. Maybe we should error in that case?
It's not treated as |
This was far easier than I assumed it would be. Pushed a commit for this. |
This extends the schema of the batch spec `steps` to add a new field: - `if: <string that can use templating to evaluate to "true" or "false">` (the corresponding schema changes `sourcegraph/sourcegraph` are here: https://github.com/sourcegraph/sourcegraph/pull/20399) `if:` is evaluated in a best-effort partial-evaluation manner before the execution of the `steps`. If we can statically evaluate it, we use the result of that evaluation to build a per-repository/per-workspace list of tasks, which increases cache utilisation. See the comments in `partial_eval.go` for more details. It also extends the `StepContext` in the templates to have the `steps.{added,modified,deleted}_files` and `steps.path` fields.
This extends the schema of the batch spec
stepsto add a new field:if: <string that can use templating to evaluate to "true" or "false">(the corresponding schema changes
sourcegraph/sourcegraphare here: https://github.com/sourcegraph/sourcegraph/pull/20399)if:is evaluated in a best-effort partial-evaluation manner before the execution of thesteps. If we can statically evaluate it, we use the result of that evaluation to build a per-repository/per-workspace list of tasks, which increases cache utilisation.See the comments in
partial_eval.gofor more details.It also extends the
StepContextin the templates to have thesteps.{added,modified,deleted}_filesandsteps.pathfields.Example batch spec
Demo video
Click here