feat: add global preconditions at the taskfile level#2734
Draft
drichardson wants to merge 2 commits intogo-task:mainfrom
Draft
feat: add global preconditions at the taskfile level#2734drichardson wants to merge 2 commits intogo-task:mainfrom
drichardson wants to merge 2 commits intogo-task:mainfrom
Conversation
Adds a top-level `preconditions` key to Taskfiles that applies to all tasks. Preconditions from a parent taskfile are inherited by tasks in included taskfiles (propagated downward through the include hierarchy). Closes go-task#294 Assisted by AI Co-Authored-By: Claude <noreply@anthropic.com>
Extends global preconditions with two new fields: - `inherit: bool` on a precondition: when true, the precondition propagates to tasks in included Taskfiles (transitively). Defaults to false, so preconditions are file-scoped by default. - `skip_preconditions: bool` on a task: when true, the task does not receive preconditions inherited from parent Taskfiles. Global preconditions defined in the same file as the task still apply. Has no effect on root-level tasks. Assisted by AI Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #294
Summary
Adds a top-level
preconditionskey to Taskfiles that applies to all tasks in that file before they run.Behavior
inherit: trueon a precondition causes it to propagate into included Taskfiles, transitively through the include hierarchyskip_preconditions: trueopts out of inherited preconditions from parent Taskfiles; global preconditions from the task's own file still applyskip_preconditionshas no effect on root-level tasks (they have no inherited preconditions)Changes
Core:
taskfile/ast/taskfile.go—Preconditions []*Preconditionfield onTaskfiletaskfile/ast/precondition.go—Inherit boolfield onPreconditiontaskfile/ast/task.go—SkipPreconditions boolfield onTasktaskfile/ast/tasks.go— scoped injection inTasks.Merge: own-file tasks always get all preconditions; transitive-include tasks only getinherit: truepreconditions unlessskip_preconditionstaskfile/ast/graph.go— same scoped logic applied to root preconditions after full mergeTests (20 new cases):
inherit: trueblocks included tasks and propagates transitively (root → mid → deep)inherit: trueblocks sub-includes but does not affect root tasksskip_preconditionsskips inherited preconditionsskip_preconditionsdoes not skip own-file preconditionsskip_preconditionsis a no-op on root tasksDocs:
website/src/docs/guide.md— new "Global preconditions" section with inherit and skip_preconditions usagewebsite/src/docs/reference/schema.md— new entries in Root Schema, Task, and Precondition sectionswebsite/src/public/schema.json—preconditionson root taskfile,inheriton precondition object,skip_preconditionson task