Skip to content

feat: add global preconditions at the taskfile level#2734

Draft
drichardson wants to merge 1 commit intogo-task:mainfrom
drichardson:feat/global-preconditions
Draft

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

Conversation

@drichardson
Copy link

Closes #294

Summary

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

version: '3'

preconditions:
  - sh: test -f .env
    msg: "Missing .env file. Run 'task init' to set up the project."

tasks:
  build:
    cmds:
      - go build ./...
  • Global preconditions are checked before a task's own preconditions
  • They are inherited by tasks in included Taskfiles (preconditions propagate downward through the include hierarchy)

Changes

  • taskfile/ast/taskfile.go — add Preconditions field to Taskfile struct and UnmarshalYAML
  • taskfile/ast/tasks.go — pass global preconditions through Tasks.Merge, prepending them to each task after deep copy
  • taskfile/ast/graph.go — after full graph merge, prepend root taskfile's global preconditions to all tasks
  • executor_test.go + test fixtures — 6 new test cases covering: precondition met, precondition not met, inheritance by included tasks, interaction with task-level preconditions
  • website/src/docs/guide.md — new "Global preconditions" section
  • website/src/docs/reference/schema.md — new preconditions entry in Root Schema
  • website/src/public/schema.jsonpreconditions added to root taskfile properties

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>
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