-
-
Notifications
You must be signed in to change notification settings - Fork 778
feat: add conditional execution for tasks and commands #2564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Summary
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 iterationfixes #608
Turns out it was not that hard and it can solve most of problems described in the issue
Example