1
0
mirror of https://github.com/go-task/task.git synced 2025-08-10 22:42:19 +02:00

feat: remove v2 support (#1447)

* feat: remove v2 support

* docs: update v2 schema docs
This commit is contained in:
Pete Davison
2023-12-29 20:26:02 +00:00
committed by GitHub
parent 212ff42304
commit 2b67d05b9d
31 changed files with 317 additions and 990 deletions

View File

@@ -13,10 +13,6 @@ func Merge(t1, t2 *Taskfile, includedTaskfile *IncludedTaskfile, namespaces ...s
if !t1.Version.Equal(t2.Version) {
return fmt.Errorf(`task: Taskfiles versions should match. First is "%s" but second is "%s"`, t1.Version, t2.Version)
}
if t2.Expansions != 0 && t2.Expansions != 2 {
t1.Expansions = t2.Expansions
}
if t2.Output.IsSet() {
t1.Output = t2.Output
}

View File

@@ -11,7 +11,7 @@ import (
"github.com/go-task/task/v3/taskfile"
)
func Dotenv(c compiler.Compiler, tf *taskfile.Taskfile, dir string) (*taskfile.Vars, error) {
func Dotenv(c *compiler.Compiler, tf *taskfile.Taskfile, dir string) (*taskfile.Vars, error) {
if len(tf.Dotenv) == 0 {
return nil, nil
}
@@ -23,7 +23,7 @@ func Dotenv(c compiler.Compiler, tf *taskfile.Taskfile, dir string) (*taskfile.V
env := &taskfile.Vars{}
tr := templater.Templater{Vars: vars, RemoveNoValue: true}
tr := templater.Templater{Vars: vars}
for _, dotEnvPath := range tf.Dotenv {
dotEnvPath = tr.Replace(dotEnvPath)

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"time"
"gopkg.in/yaml.v3"
@@ -174,21 +173,19 @@ func Taskfile(
}
err = t.Includes.Range(func(namespace string, includedTask taskfile.IncludedTaskfile) error {
if t.Version.Compare(taskfile.V3) >= 0 {
tr := templater.Templater{Vars: t.Vars, RemoveNoValue: true}
includedTask = taskfile.IncludedTaskfile{
Taskfile: tr.Replace(includedTask.Taskfile),
Dir: tr.Replace(includedTask.Dir),
Optional: includedTask.Optional,
Internal: includedTask.Internal,
Aliases: includedTask.Aliases,
AdvancedImport: includedTask.AdvancedImport,
Vars: includedTask.Vars,
BaseDir: includedTask.BaseDir,
}
if err := tr.Err(); err != nil {
return err
}
tr := templater.Templater{Vars: t.Vars}
includedTask = taskfile.IncludedTaskfile{
Taskfile: tr.Replace(includedTask.Taskfile),
Dir: tr.Replace(includedTask.Dir),
Optional: includedTask.Optional,
Internal: includedTask.Internal,
Aliases: includedTask.Aliases,
AdvancedImport: includedTask.AdvancedImport,
Vars: includedTask.Vars,
BaseDir: includedTask.BaseDir,
}
if err := tr.Err(); err != nil {
return err
}
uri, err := includedTask.FullTaskfilePath()
@@ -219,7 +216,7 @@ func Taskfile(
return err
}
if t.Version.Compare(taskfile.V3) >= 0 && len(includedTaskfile.Dotenv) > 0 {
if len(includedTaskfile.Dotenv) > 0 {
return ErrIncludedTaskfilesCantHaveDotenvs
}
@@ -273,31 +270,6 @@ func Taskfile(
return nil, err
}
if t.Version.Compare(taskfile.V3) < 0 {
if node, isFileNode := node.(*FileNode); isFileNode {
path := filepathext.SmartJoin(node.Dir, fmt.Sprintf("Taskfile_%s.yml", runtime.GOOS))
if _, err = os.Stat(path); err == nil {
osNode := &FileNode{
BaseNode: NewBaseNode(WithParent(node)),
Entrypoint: path,
Dir: node.Dir,
}
b, err := osNode.Read(context.Background())
if err != nil {
return nil, err
}
var osTaskfile *taskfile.Taskfile
if err := yaml.Unmarshal(b, &osTaskfile); err != nil {
return nil, &errors.TaskfileInvalidError{URI: filepathext.TryAbsToRel(node.Location()), Err: err}
}
t.Location = node.Location()
if err = taskfile.Merge(t, osTaskfile, nil); err != nil {
return nil, err
}
}
}
}
for _, task := range t.Tasks.Values() {
// If the task is not defined, create a new one
if task == nil {

View File

@@ -1,45 +0,0 @@
package read
import (
"fmt"
"os"
"runtime"
"gopkg.in/yaml.v3"
"github.com/go-task/task/v3/internal/filepathext"
"github.com/go-task/task/v3/taskfile"
)
// Taskvars reads a Taskvars for a given directory
func Taskvars(dir string) (*taskfile.Vars, error) {
vars := &taskfile.Vars{}
path := filepathext.SmartJoin(dir, "Taskvars.yml")
if _, err := os.Stat(path); err == nil {
vars, err = readTaskvars(path)
if err != nil {
return nil, err
}
}
path = filepathext.SmartJoin(dir, fmt.Sprintf("Taskvars_%s.yml", runtime.GOOS))
if _, err := os.Stat(path); err == nil {
osVars, err := readTaskvars(path)
if err != nil {
return nil, err
}
vars.Merge(osVars)
}
return vars, nil
}
func readTaskvars(file string) (*taskfile.Vars, error) {
f, err := os.Open(file)
if err != nil {
return nil, err
}
var vars taskfile.Vars
return &vars, yaml.NewDecoder(f).Decode(&vars)
}

View File

@@ -10,54 +10,48 @@ import (
"github.com/go-task/task/v3/errors"
)
var (
V3 = semver.MustParse("3")
V2 = semver.MustParse("2")
)
var V3 = semver.MustParse("3")
// Taskfile represents a Taskfile.yml
type Taskfile struct {
Location string
Version *semver.Version
Expansions int
Output Output
Method string
Includes *IncludedTaskfiles
Set []string
Shopt []string
Vars *Vars
Env *Vars
Tasks Tasks
Silent bool
Dotenv []string
Run string
Interval time.Duration
Location string
Version *semver.Version
Output Output
Method string
Includes *IncludedTaskfiles
Set []string
Shopt []string
Vars *Vars
Env *Vars
Tasks Tasks
Silent bool
Dotenv []string
Run string
Interval time.Duration
}
func (tf *Taskfile) UnmarshalYAML(node *yaml.Node) error {
switch node.Kind {
case yaml.MappingNode:
var taskfile struct {
Version *semver.Version
Expansions int
Output Output
Method string
Includes *IncludedTaskfiles
Set []string
Shopt []string
Vars *Vars
Env *Vars
Tasks Tasks
Silent bool
Dotenv []string
Run string
Interval time.Duration
Version *semver.Version
Output Output
Method string
Includes *IncludedTaskfiles
Set []string
Shopt []string
Vars *Vars
Env *Vars
Tasks Tasks
Silent bool
Dotenv []string
Run string
Interval time.Duration
}
if err := node.Decode(&taskfile); err != nil {
return err
}
tf.Version = taskfile.Version
tf.Expansions = taskfile.Expansions
tf.Output = taskfile.Output
tf.Method = taskfile.Method
tf.Includes = taskfile.Includes
@@ -70,9 +64,6 @@ func (tf *Taskfile) UnmarshalYAML(node *yaml.Node) error {
tf.Dotenv = taskfile.Dotenv
tf.Run = taskfile.Run
tf.Interval = taskfile.Interval
if tf.Expansions <= 0 {
tf.Expansions = 2
}
if tf.Version == nil {
return errors.New("task: 'version' is required")
}