mirror of
https://github.com/go-task/task.git
synced 2025-11-23 22:24:45 +02:00
fix: matrix loops should be deterministic (#1784)
This commit is contained in:
@@ -5,12 +5,13 @@ import (
|
||||
|
||||
"github.com/go-task/task/v3/errors"
|
||||
"github.com/go-task/task/v3/internal/deepcopy"
|
||||
"github.com/go-task/task/v3/internal/omap"
|
||||
)
|
||||
|
||||
type For struct {
|
||||
From string
|
||||
List []any
|
||||
Matrix map[string][]any
|
||||
Matrix omap.OrderedMap[string, []any]
|
||||
Var string
|
||||
Split string
|
||||
As string
|
||||
@@ -37,7 +38,7 @@ func (f *For) UnmarshalYAML(node *yaml.Node) error {
|
||||
|
||||
case yaml.MappingNode:
|
||||
var forStruct struct {
|
||||
Matrix map[string][]any
|
||||
Matrix omap.OrderedMap[string, []any]
|
||||
Var string
|
||||
Split string
|
||||
As string
|
||||
@@ -45,10 +46,10 @@ func (f *For) UnmarshalYAML(node *yaml.Node) error {
|
||||
if err := node.Decode(&forStruct); err != nil {
|
||||
return errors.NewTaskfileDecodeError(err, node)
|
||||
}
|
||||
if forStruct.Var == "" && forStruct.Matrix == nil {
|
||||
if forStruct.Var == "" && forStruct.Matrix.Len() == 0 {
|
||||
return errors.NewTaskfileDecodeError(nil, node).WithMessage("invalid keys in for")
|
||||
}
|
||||
if forStruct.Var != "" && forStruct.Matrix != nil {
|
||||
if forStruct.Var != "" && forStruct.Matrix.Len() != 0 {
|
||||
return errors.NewTaskfileDecodeError(nil, node).WithMessage("cannot use both var and matrix in for")
|
||||
}
|
||||
f.Matrix = forStruct.Matrix
|
||||
@@ -68,7 +69,7 @@ func (f *For) DeepCopy() *For {
|
||||
return &For{
|
||||
From: f.From,
|
||||
List: deepcopy.Slice(f.List),
|
||||
Matrix: deepcopy.Map(f.Matrix),
|
||||
Matrix: f.Matrix.DeepCopy(),
|
||||
Var: f.Var,
|
||||
Split: f.Split,
|
||||
As: f.As,
|
||||
|
||||
Reference in New Issue
Block a user