-
Notifications
You must be signed in to change notification settings - Fork 295
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
Support named, conditional tasks #229
base: master
Are you sure you want to change the base?
Conversation
Just like on a link action, the value is executed in the shell. If it has a non-zero exit code (failure), the whole task is skipped. This allows tasks to group actions that only apply in certain conditions (e.g. on certain OSes or in certain configurations), and allows all actions (not just link) to be conditional.
I haven't tackled trying to figure out the testing infrastructure yet, so I haven't written any tests. Here's the
|
A new property called task can be used to assign a name. If it is specified, then the task's actions must be nested under an actions property, and an if property can be used to make it conditional. Just like on a link action, the value is executed in the shell. If it has a non-zero exit code (failure), the whole task is skipped. This allows tasks to group actions that only apply in certain conditions (e.g. on certain OSes or in certain configurations), and allows all actions (not just link) to be conditional. If there is no task property, then the task behaves exactly as it did previously.
This PR now supports named tasks, too, as described in #225 (comment) Here's the
|
Thanks for taking the time to submit a PR. I left some general comments related to the discussion in #225 back in #225 (comment). This is an interesting proposal. While not technically backwards compatible in the strictest sense (there could have been a plugin called "if" or "task"), I don't think it will break anything in practice (nobody is using those plugin names). It does change the execution model for tasks. As it's implemented now, tasks are a set of actions, and Dotbot executes all of them independently (in an arbitrary order). I wonder what is the use of named tasks, beyond documentation? Would it be equivalent if they were Compositionality is a tricky issue... I'm going to spend a bit of time thinking about many of the open issues for Dotbot, thinking a bit about how people are using Dotbot in practice (going to try to do a user study), think about what we'd change if we could break backwards compatibility, and so on. I'll try to see if there's a clean solution to this problem of compositionality (e.g. it's a little annoying if we have a different I'll leave this issue open right now, so I can think about it for a bit. Happy to hear feedback from you on this as well. (Once I make a bit more progress on a user study and going through issues, I might try to come up with a more general way to discuss and get feedback on potential larger-scale changes / a Dotbot 2.0). |
Thanks for considering my proposal and for the feedback here and on the issue. To answer your question here: I think the main use of named tasks is for log output. It lets dotbot print out the name of the task when it begins running or when it is skipped, giving context that helps the user to understand what happened. I agree with all of your comments on #225. It's not strictly backwards compatible, but the risk of someone using Regarding the limitation that actions in a task are unique and unordered, I think that's okay, since it feels like imposing order or repeating actions within a task are super edge-case. At worst, you could always split one task into more than one if you had such a need, even if it meant repeating a test. In the end, I still see my proposal as small change that gives you a whole lot more power, and that feels worth it to me. But of course that's based only on my usage. And I can see why you might prefer to shoot for something better in a larger-scale change. Thanks again! |
@anishathalye any chance you will merge this, both the named part and conditional part would be very useful. Today I'm trying to figure out how to run a command, but only if a directory doesn't already exist. I don't think there's any way to do this, but this PR would solve it. |
For the moment, as a workaround, you could incorporate the check into the command. |
@anishathalye Sorry for digging out older things here but.... I'd really like to have this! Any chance? Edit: I need to edit myself... - shell:
- description: Include ansible configuration
command: >
[ -x "$(command -v ansible)" ] && ./install -c ansible.conf.yaml || true
stdout: true seems to do exactly what I had in mind! (Not the nicest solution but better than nothing.) |
Just like on a link action, the value is executed in the shell. If it has a non-zero exit code (indicating failure), the whole task is skipped.
This allows tasks to group actions that only apply in certain conditions (e.g. on certain OSes or in certain configurations), and allows all actions (not just link) to be conditional.
Resolves #225.