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:

npx croct@latest use template.json5

Properties

These are the supported properties:

name
string

The action identifier. Always test for this action.

condition
boolean

An expression that determines which branch to execute.

then
Action|Array<Action>

The actions to execute when the condition is true.

Accepts a single action or a list of actions.

else(optional)
Action|Array<Action>

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.