Conversation
| if err := execext.RunCommand(ctx, &execext.RunCommandOptions{ | ||
| Command: t.If, | ||
| Dir: t.Dir, | ||
| Env: env.Get(t), |
There was a problem hiding this comment.
Sometimes people ask to have Posix and Bash opt available on these commands. I don't know if that is a good or a bad idea, never the less please see #2538 where the idea is in draft form.
There was a problem hiding this comment.
I think it make sense
I'll take a look at your PR soon ! :)
Add `if` field to tasks and commands that allows conditional execution based on a shell command exit code. When the condition returns non-zero, the task/command is silently skipped (with verbose logging). - Task-level: skip entire task if condition fails - Command-level: skip individual command if condition fails - Supports template variables in conditions - Works with for loops (condition evaluated per iteration) - Works with deferred commands
Add comprehensive test cases for: - Task calls in cmds with if conditions - Go template functions (eq, ne, and, or) - Direct template variable evaluation - CLI variable overrides - Task-level if with templates
Add comprehensive golden fixture tests for if feature: - Command-level if (true/false) - Task-level if (true/false) - Task calls with if conditions - Go template functions (eq, ne, and, or) - Direct template variable evaluation - CLI variable overrides - For loops with if conditions
📦 Build artifacts ready!Download binaries from this workflow run. Available platforms: Linux, macOS, Windows (amd64, arm64) |
andreynering
left a comment
There was a problem hiding this comment.
This is perfect, thank you @vmaerten! 🚀
Reminder that we talked about having a short blog post. Feel free to merge, though. If you add it on this PR or on a follow-up one, as you prefer.
There was a problem hiding this comment.
I liked that you kept all tests in the same file. Looks very clean!
Co-authored-by: Andrey Nering <andreynering@users.noreply.github.com>

if:keyword to control when a task or command is ran? #608Summary
ifattribute for conditional execution of tasks and commandsifexits with non-zero, the task/command is skipped (not failed){{eq .VAR "value"}}) which evaluate totrue/falseforloops, evaluating the condition for each iterationTurns out it was not that hard and it can solve most of problems described in the issue
Example