Skip to content

feat: add global preconditions at the taskfile level#2734

Draft
drichardson wants to merge 2 commits intogo-task:mainfrom
drichardson:feat/global-preconditions
Draft

feat: add global preconditions at the taskfile level#2734
drichardson wants to merge 2 commits intogo-task:mainfrom
drichardson:feat/global-preconditions

Conversation

@drichardson
Copy link

@drichardson drichardson commented Mar 9, 2026

Closes #294

Summary

Adds a top-level preconditions key to Taskfiles that applies to all tasks in that file before they run.

version: '3'

preconditions:
  - sh: test -f .env
    msg: "Missing .env file. Run 'task init' to set up the project."
    inherit: true   # also applies to tasks in included Taskfiles

includes:
  tools: ./tools

tasks:
  init:
    skip_preconditions: true  # skips parent's inherited preconditions
    cmds:
      - cp .env.template .env

Behavior

  • Global preconditions are file-scoped by default — they apply to tasks in the file they are defined in, but not to tasks in included Taskfiles
  • Setting inherit: true on a precondition causes it to propagate into included Taskfiles, transitively through the include hierarchy
  • A task with skip_preconditions: true opts out of inherited preconditions from parent Taskfiles; global preconditions from the task's own file still apply
  • skip_preconditions has no effect on root-level tasks (they have no inherited preconditions)
  • Global preconditions are checked before a task's own preconditions

Changes

Core:

  • taskfile/ast/taskfile.goPreconditions []*Precondition field on Taskfile
  • taskfile/ast/precondition.goInherit bool field on Precondition
  • taskfile/ast/task.goSkipPreconditions bool field on Task
  • taskfile/ast/tasks.go — scoped injection in Tasks.Merge: own-file tasks always get all preconditions; transitive-include tasks only get inherit: true preconditions unless skip_preconditions
  • taskfile/ast/graph.go — same scoped logic applied to root preconditions after full merge

Tests (20 new cases):

  • Global precondition met/not met for root and included tasks
  • Non-inheriting precondition does not affect included tasks
  • inherit: true blocks included tasks and propagates transitively (root → mid → deep)
  • Mid-level inherit: true blocks sub-includes but does not affect root tasks
  • skip_preconditions skips inherited preconditions
  • skip_preconditions does not skip own-file preconditions
  • skip_preconditions is a no-op on root tasks

Docs:

  • website/src/docs/guide.md — new "Global preconditions" section with inherit and skip_preconditions usage
  • website/src/docs/reference/schema.md — new entries in Root Schema, Task, and Precondition sections
  • website/src/public/schema.jsonpreconditions on root taskfile, inherit on precondition object, skip_preconditions on task

drichardson and others added 2 commits March 9, 2026 16:17
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add global preconditions

1 participant