test
Learn how to execute actions conditionally.
This action executes different actions depending on whether a condition is true or false, allowing the workflow to branch based on project settings, user input, or other runtime values.
Example
The following template checks the detected platform and prints a message accordingly:
template.json5
{ "$schema": "https://schema.croct.com/json/v1/template.json", "title": "Platform check", "description": "Checks the detected platform.", "actions": [ { "name": "test", "condition": "${project.platform !== 'unknown'}", "then": { "name": "print", "message": "Detected platform: ${project.platform}" }, "else": { "name": "print", "message": "No supported platform detected." } } ]}To apply this template, run:
npm
npx croct@latest use template.json5Properties
These are the supported properties:
- namestring
The action identifier. Always test for this action.
- conditionboolean
An expression that determines which branch to execute.
- then
The actions to execute when the condition is true.
Accepts a single action or a list of actions.
- else(optional)
The actions to execute when the condition is false.
Accepts a single action or a list of actions. When omitted, nothing happens if the condition is false.