If Condition
Mint tasks can be configured to run conditionally by using an if:
key on the task definition with an expression.
Example: Only on Main
A common use case for conditional tasks is having some tasks that only run on a certain branch, like main
.
tasks:
- key: test
run: ./run-tests.sh
- key: deploy
after: test
if: ${{ init.branch == 'main' }}
run: ./deploy.sh
If the if
condition returns false, then the task will be skipped.
Any tasks that depend on the skipped task will also be skipped.
Recommended Workflow for Testing Changes
It's common to have tasks that only run on certain branches, but they can be hard to test. For example, if you have a task that only runs on main, you ideally don't want to have to merge into main to find out whether your changes worked.
To execute tasks outside of the condition under which they normally run, it's a best practice to define the condition as an init parameter and then use the init parameter in your task definition. Using that approach, you can then execute the task directly via the Mint CLI without needing to comment out or change the if:
condition to test it.
on:
github:
push:
init:
deploy: ${{ event.git.branch == 'main' }}
tasks:
- key: deploy
if: ${{ init.deploy }}
run: ./deploy.sh
With this approach, you can test the deploy
task by using the CLI and executing mint run --init deploy=true
.