mirror of
https://github.com/go-task/task.git
synced 2025-08-08 22:36:57 +02:00
preconditions cannot be in included taskfile
This commit is contained in:
15
task_test.go
15
task_test.go
@ -539,6 +539,21 @@ func TestPreconditionGlobal(t *testing.T) {
|
||||
if buff.String() != "task: 1 != 0 obviously!\n" {
|
||||
t.Errorf("Wrong output message: %s", buff.String())
|
||||
}
|
||||
|
||||
buff.Reset()
|
||||
|
||||
e = &task.Executor{
|
||||
Dir: "testdata/precondition/global/included",
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
}
|
||||
|
||||
err := e.Setup()
|
||||
require.Error(t, err)
|
||||
|
||||
assert.Equal(t, "task: Included Taskfiles can't have preconditions declarations. Please, move the preconditions declaration to the main Taskfile", err.Error())
|
||||
buff.Reset()
|
||||
|
||||
}
|
||||
|
||||
func TestGenerates(t *testing.T) {
|
||||
|
@ -2,8 +2,10 @@ package ast
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/go-task/task/v3/errors"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/go-task/task/v3/errors"
|
||||
)
|
||||
|
||||
// Precondition represents a precondition necessary for a task to run
|
||||
|
@ -34,20 +34,6 @@ func (p *Preconditions) DeepCopy() *Preconditions {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Preconditions) Merge(other *Preconditions) {
|
||||
if p == nil || p.Values == nil || other == nil {
|
||||
return
|
||||
}
|
||||
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
|
||||
other.mutex.RLock()
|
||||
defer other.mutex.RUnlock()
|
||||
|
||||
p.Values = append(p.Values, deepcopy.Slice(other.Values)...)
|
||||
}
|
||||
|
||||
func (p *Preconditions) UnmarshalYAML(node *yaml.Node) error {
|
||||
if p == nil || p.Values == nil {
|
||||
*p = *NewPreconditions()
|
||||
|
@ -18,6 +18,9 @@ var V3 = semver.MustParse("3")
|
||||
// ErrIncludedTaskfilesCantHaveDotenvs is returned when a included Taskfile contains dotenvs
|
||||
var ErrIncludedTaskfilesCantHaveDotenvs = errors.New("task: Included Taskfiles can't have dotenv declarations. Please, move the dotenv declaration to the main Taskfile")
|
||||
|
||||
// ErrIncludedTaskfilesCantHavePreconditions is returned when a included Taskfile contains Preconditions
|
||||
var ErrIncludedTaskfilesCantHavePreconditions = errors.New("task: Included Taskfiles can't have preconditions declarations. Please, move the preconditions declaration to the main Taskfile")
|
||||
|
||||
// Taskfile is the abstract syntax tree for a Taskfile
|
||||
type Taskfile struct {
|
||||
Location string
|
||||
@ -45,6 +48,9 @@ func (t1 *Taskfile) Merge(t2 *Taskfile, include *Include) error {
|
||||
if len(t2.Dotenv) > 0 {
|
||||
return ErrIncludedTaskfilesCantHaveDotenvs
|
||||
}
|
||||
if len(t2.Preconditions.Values) > 0 {
|
||||
return ErrIncludedTaskfilesCantHavePreconditions
|
||||
}
|
||||
if t2.Output.IsSet() {
|
||||
t1.Output = t2.Output
|
||||
}
|
||||
@ -65,7 +71,6 @@ func (t1 *Taskfile) Merge(t2 *Taskfile, include *Include) error {
|
||||
}
|
||||
t1.Vars.Merge(t2.Vars, include)
|
||||
t1.Env.Merge(t2.Env, include)
|
||||
t1.Preconditions.Merge(t2.Preconditions)
|
||||
return t1.Tasks.Merge(t2.Tasks, include, t1.Vars)
|
||||
}
|
||||
|
||||
|
8
testdata/precondition/global/included/Taskfile.yml
vendored
Normal file
8
testdata/precondition/global/included/Taskfile.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
version: 3
|
||||
|
||||
includes:
|
||||
included: included.yml
|
||||
|
||||
preconditions:
|
||||
- sh: "[ 1 = 0 ]"
|
||||
msg: "1 != 0 obviously!"
|
5
testdata/precondition/global/included/included.yml
vendored
Normal file
5
testdata/precondition/global/included/included.yml
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
version: 3
|
||||
|
||||
preconditions:
|
||||
- sh: "[ 1 = 0 ]"
|
||||
msg: "1 != 0 obviously!"
|
Reference in New Issue
Block a user