presets: Conditional workflow preset step execution
Currently, workflow presets provide a fairly rigid facility. They execute a defined set of steps, stopping at the first one that fails. While the hook script feature proposed in #25475 would be a nice improvement, that still doesn't allow a workflow step to react to the state of steps that came before it. Consider the scenario where a test step might fail, but you still want to perform some sort of cleanup or reporting afterwards (e.g. collecting and reporting coverage data).
I propose we allow steps to specify conditions that define whether they execute or not. Instead of stopping a workflow at the first step that fails, cmake
would continue through the list of steps and for each one, check if it has conditions and whether those conditions still allow it to run. By default, a step with no conditions would not execute in this scenario, which would preserve existing behavior.
A few different types of conditions could be supported:
- The step always runs, even if there has been an error in any previous step.
- The step never runs, unless there has been an error in any previous step.
- The step only runs if a particular earlier step (or maybe a list of steps) completed successfully.
- The step only runs if a particular earlier step (or maybe a list of steps) failed.
For the last two, if a list of steps is given, you'd have to decide whether they specify an AND or OR relationship.
One of the problems with the above is that we don't currently have a way to uniquely refer to a workflow step other than a numerical counter or index for the step number. That would be fairly fragile, in my view. We could allow referring to a step by name if the name is unique, but in my experience, names are frequently not unique. Perhaps we would add support for a new field like id
or reference
which is required to be unique for each step when given, and conditions between steps must use these fields to refer to other steps. This would mean existing workflow presets continue to work as before, and you only need to add these extra fields if you want to add inter-step conditions.
When combined with the feature proposed in #25475, the above proposal would make workflow presets a very powerful and flexible way of defining CI workflows.