-
-
Notifications
You must be signed in to change notification settings - Fork 780
Description
It would be great to be able to set global preconditions to prevent running any tasks in a Taskfile and its children if the precondition is not met. This would be a simple way to add a precondition to all tasks without having to add the same precondition to every task individually.
The use case for this is for example to enforce that a repository has been initialized somehow before allowing to run any other tasks, like setting up release targets for goreleaser or similar. In this example I would have the .goreleaser.yml contain a string like "INIT_PACKAGE" which should be replaced by the package name of the repository, and until that's done all tasks should fail (precondition greps for "INIT_PACKAGE"), and return the same message "This repository hasn't been initialized, please run 'task init'".
Obviously to be able to run the initial task init there needs to be a property to disable the global precondition for that specific task. So the Taskfile would end up something like this:
version: '2'
preconditions:
- grep INIT_PACKAGE .goreleaser.yml
msg: "this repository needs to be initialized, run 'task init' to continue"
tasks:
build:
desc: build go project
cmds:
- go build .
init:
desc: initalize repository
cmds:
- sed -i 's/INIT_PACKAGE/myPackage/g' .goreleaser.yml
ignore_preconditions: yes
Also the logic should probably be that any preconditions from the parent Taskfile which includes other taskfiles should be applied on all the child taskfiles' tasks as well, i.e. they inherit the parent's global preconditions. The preconditions should only be propagated downwards in the hierarchy meaning that the parent Taskfile doesn't inherit global preconditions from it's children. Or maybe there should be a property to select this behavior as well, "include_preconditions: yes/no"?