docs/adrs/1438-conditional-composite.md
Date: 2021-10-13
Status: Accepted
We recently shipped composite actions, which allows you to reuse individual steps inside an action.
However, one of the most requested features has been a way to support the if keyword.
if keywordsuccess should be implementable without calling them, for example you can do job.status == success rather then success() currently.Currently, we have limited conditional support in composite actions for pre and post steps.
These are based on the job status, and support keywords like always(), failed(), success() and cancelled().
However, generic or main steps do not support conditionals.
By default, in a regular workflow, a step runs on the success() condition. Which looks at the job status, sees if it is successful and runs.
By default, in a composite action, main steps run until a single step fails in that composite action, then the composite action is halted early. It does not care about the job status. Pre, and post steps in composite actions use the job status to determine if they should run.
Well, if we think about what composite actions are currently doing when invoking main steps, they are checking if the current composite action is successful. Lets formalize that concept into a "real" idea.
action_status field to the github context to mimic the job's context status.
action_path which is only set for composite actions on the github context.success() function will check if action_status == success, rather then job_status == success. Failure will work the same way.
For nested composite actions, we will follow the existing behavior, you only care about your current composite action, not any parents. For example, lets imagine a scenario with a simple nested composite action
- Job
- Regular Step
- Composite Action
- runs: exit 1
- if: always()
uses: A child composite action
- if: success()
runs: echo "this should print"
- runs: echo "this should also print"
- if: success()
runs: echo "this will not print as the current composite action has failed already"
The child composite actions steps should run in this example, the child composite action has not yet failed, so it should run all steps until a step fails. This is consistent with how a composite action currently works in production if the main job fails but a composite action is invoked with if:always() or if: failure()
We could add the current_step_status to the job context rather then __status to the steps context, however this comes with two major downsides:
successcurrent_step value on the job context__status on the steps context.
__ is required to prevent us from colliding with a step with id: status