mirror of
https://github.com/go-task/task.git
synced 2025-08-08 22:36:57 +02:00
wip
This commit is contained in:
@ -14,7 +14,7 @@ import (
|
||||
var ErrPreconditionFailed = errors.New("task: precondition not met")
|
||||
|
||||
func (e *Executor) areTaskPreconditionsMet(ctx context.Context, t *ast.Task) (bool, error) {
|
||||
for _, p := range t.Preconditions {
|
||||
for _, p := range append(t.Preconditions, e.Taskfile.Preconditions.Preconditions...) {
|
||||
err := execext.RunCommand(ctx, &execext.RunCommandOptions{
|
||||
Command: p.Sh,
|
||||
Dir: t.Dir,
|
||||
|
@ -2,9 +2,11 @@ package ast
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/go-task/task/v3/internal/deepcopy"
|
||||
"sync"
|
||||
|
||||
|
||||
"github.com/go-task/task/v3/internal/deepcopy"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/go-task/task/v3/errors"
|
||||
@ -13,7 +15,7 @@ import (
|
||||
// Precondition represents a precondition necessary for a task to run
|
||||
type (
|
||||
Preconditions struct {
|
||||
preconditions []*Precondition
|
||||
Preconditions []*Precondition
|
||||
mutex sync.RWMutex
|
||||
}
|
||||
|
||||
@ -30,7 +32,7 @@ func (p *Preconditions) DeepCopy() *Preconditions {
|
||||
defer p.mutex.RUnlock()
|
||||
p.mutex.RLock()
|
||||
return &Preconditions{
|
||||
preconditions: deepcopy.Slice(p.preconditions),
|
||||
Preconditions: deepcopy.Slice(p.Preconditions),
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +48,7 @@ func (p *Precondition) DeepCopy() *Precondition {
|
||||
|
||||
func NewPreconditions() *Preconditions {
|
||||
return &Preconditions{
|
||||
preconditions: make([]*Precondition, 0),
|
||||
Preconditions: make([]*Precondition, 0),
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,13 +85,12 @@ func (p *Precondition) UnmarshalYAML(node *yaml.Node) error {
|
||||
}
|
||||
|
||||
func (p *Preconditions) UnmarshalYAML(node *yaml.Node) error {
|
||||
|
||||
if p == nil || p.preconditions == nil {
|
||||
if p == nil || p.Preconditions == nil {
|
||||
*p = *NewPreconditions()
|
||||
}
|
||||
|
||||
if err := node.Decode(&p.preconditions); err != nil {
|
||||
return errors.NewTaskfileDecodeError(err, node).WithTypeMessage("precondition")
|
||||
if err := node.Decode(&p.Preconditions); err != nil {
|
||||
return errors.NewTaskfileDecodeError(err, node).WithTypeMessage("preconditions")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -60,8 +60,12 @@ func (t1 *Taskfile) Merge(t2 *Taskfile, include *Include) error {
|
||||
if t1.Tasks == nil {
|
||||
t1.Tasks = NewTasks()
|
||||
}
|
||||
if t1.Preconditions == nil {
|
||||
t1.Preconditions = NewPreconditions()
|
||||
}
|
||||
t1.Vars.Merge(t2.Vars, include)
|
||||
t1.Env.Merge(t2.Env, include)
|
||||
// TODO:@vmaerten Merge precondition
|
||||
return t1.Tasks.Merge(t2.Tasks, include, t1.Vars)
|
||||
}
|
||||
|
||||
@ -100,6 +104,7 @@ func (tf *Taskfile) UnmarshalYAML(node *yaml.Node) error {
|
||||
tf.Dotenv = taskfile.Dotenv
|
||||
tf.Run = taskfile.Run
|
||||
tf.Interval = taskfile.Interval
|
||||
tf.Preconditions = taskfile.Preconditions
|
||||
if tf.Includes == nil {
|
||||
tf.Includes = NewIncludes()
|
||||
}
|
||||
@ -112,7 +117,6 @@ func (tf *Taskfile) UnmarshalYAML(node *yaml.Node) error {
|
||||
if tf.Tasks == nil {
|
||||
tf.Tasks = NewTasks()
|
||||
}
|
||||
|
||||
if tf.Preconditions == nil {
|
||||
tf.Preconditions = NewPreconditions()
|
||||
}
|
||||
|
Reference in New Issue
Block a user