mirror of
https://github.com/go-task/task.git
synced 2025-05-15 22:26:28 +02:00
feat: version checks
This commit is contained in:
parent
8c0236c795
commit
e2b85c6aa1
@ -17,7 +17,7 @@ const (
|
|||||||
CodeTaskfileNotTrusted
|
CodeTaskfileNotTrusted
|
||||||
CodeTaskfileNotSecure
|
CodeTaskfileNotSecure
|
||||||
CodeTaskfileCacheNotFound
|
CodeTaskfileCacheNotFound
|
||||||
CodeTaskfileVersionNotDefined
|
CodeTaskfileVersionCheckError
|
||||||
CodeTaskfileNetworkTimeout
|
CodeTaskfileNetworkTimeout
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Masterminds/semver/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TaskfileNotFoundError is returned when no appropriate Taskfile is found when
|
// TaskfileNotFoundError is returned when no appropriate Taskfile is found when
|
||||||
@ -122,21 +124,32 @@ func (err *TaskfileCacheNotFound) Code() int {
|
|||||||
return CodeTaskfileCacheNotFound
|
return CodeTaskfileCacheNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
// TaskfileVersionNotDefined is returned when the user attempts to run a
|
// TaskfileVersionCheckError is returned when the user attempts to run a
|
||||||
// Taskfile that does not contain a Taskfile schema version key.
|
// Taskfile that does not contain a Taskfile schema version key or if they try
|
||||||
type TaskfileVersionNotDefined struct {
|
// to use a feature that is not supported by the schema version.
|
||||||
|
type TaskfileVersionCheckError struct {
|
||||||
URI string
|
URI string
|
||||||
|
SchemaVersion *semver.Version
|
||||||
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err *TaskfileVersionNotDefined) Error() string {
|
func (err *TaskfileVersionCheckError) Error() string {
|
||||||
|
if err.SchemaVersion == nil {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
`task: Taskfile %q does not contain a schema version key`,
|
`task: Missing schema version in Taskfile %q`,
|
||||||
err.URI,
|
err.URI,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"task: Invalid schema version in Taskfile %q:\nSchema version (%s) %s",
|
||||||
|
err.URI,
|
||||||
|
err.SchemaVersion.String(),
|
||||||
|
err.Message,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err *TaskfileVersionNotDefined) Code() int {
|
func (err *TaskfileVersionCheckError) Code() int {
|
||||||
return CodeTaskfileVersionNotDefined
|
return CodeTaskfileVersionCheckError
|
||||||
}
|
}
|
||||||
|
|
||||||
// TaskfileNetworkTimeout is returned when the user attempts to use a remote
|
// TaskfileNetworkTimeout is returned when the user attempts to use a remote
|
||||||
|
47
setup.go
47
setup.go
@ -2,7 +2,6 @@ package task
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -12,11 +11,13 @@ import (
|
|||||||
"github.com/Masterminds/semver/v3"
|
"github.com/Masterminds/semver/v3"
|
||||||
"github.com/sajari/fuzzy"
|
"github.com/sajari/fuzzy"
|
||||||
|
|
||||||
|
"github.com/go-task/task/v3/errors"
|
||||||
"github.com/go-task/task/v3/internal/compiler"
|
"github.com/go-task/task/v3/internal/compiler"
|
||||||
"github.com/go-task/task/v3/internal/execext"
|
"github.com/go-task/task/v3/internal/execext"
|
||||||
"github.com/go-task/task/v3/internal/filepathext"
|
"github.com/go-task/task/v3/internal/filepathext"
|
||||||
"github.com/go-task/task/v3/internal/logger"
|
"github.com/go-task/task/v3/internal/logger"
|
||||||
"github.com/go-task/task/v3/internal/output"
|
"github.com/go-task/task/v3/internal/output"
|
||||||
|
"github.com/go-task/task/v3/internal/version"
|
||||||
"github.com/go-task/task/v3/taskfile"
|
"github.com/go-task/task/v3/taskfile"
|
||||||
"github.com/go-task/task/v3/taskfile/ast"
|
"github.com/go-task/task/v3/taskfile/ast"
|
||||||
)
|
)
|
||||||
@ -241,35 +242,31 @@ func (e *Executor) setupConcurrencyState() {
|
|||||||
|
|
||||||
func (e *Executor) doVersionChecks() error {
|
func (e *Executor) doVersionChecks() error {
|
||||||
// Copy the version to avoid modifying the original
|
// Copy the version to avoid modifying the original
|
||||||
v := &semver.Version{}
|
schemaVersion := &semver.Version{}
|
||||||
*v = *e.Taskfile.Version
|
*schemaVersion = *e.Taskfile.Version
|
||||||
|
|
||||||
if v.LessThan(ast.V3) {
|
// Error if the Taskfile uses a schema version below v3
|
||||||
return fmt.Errorf(`task: Taskfile schemas prior to v3 are no longer supported`)
|
if schemaVersion.LessThan(ast.V3) {
|
||||||
|
return &errors.TaskfileVersionCheckError{
|
||||||
|
URI: e.Taskfile.Location,
|
||||||
|
SchemaVersion: schemaVersion,
|
||||||
|
Message: `no longer supported. Please use v3 or above`,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// consider as equal to the greater version if round
|
// Get the current version of Task
|
||||||
if v.Equal(ast.V3) {
|
// If we can't parse the version (e.g. when its "devel"), then ignore the current version checks
|
||||||
v = semver.MustParse("3.8")
|
currentVersion, err := semver.NewVersion(version.GetVersion())
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.GreaterThan(semver.MustParse("3.8")) {
|
// Error if the Taskfile uses a schema version above the current version of Task
|
||||||
return fmt.Errorf(`task: Taskfile versions greater than v3.8 not implemented in the version of Task`)
|
if schemaVersion.GreaterThan(currentVersion) {
|
||||||
}
|
return &errors.TaskfileVersionCheckError{
|
||||||
|
URI: e.Taskfile.Location,
|
||||||
if v.LessThan(semver.MustParse("3.8")) && e.Taskfile.Output.Group.IsSet() {
|
SchemaVersion: schemaVersion,
|
||||||
return fmt.Errorf(`task: Taskfile option "output.group" is only available starting on Taskfile version v3.8`)
|
Message: fmt.Sprintf(`is greater than the current version of Task (%s)`, currentVersion.String()),
|
||||||
}
|
|
||||||
|
|
||||||
if v.LessThan(semver.MustParse("3.7")) {
|
|
||||||
if e.Taskfile.Run != "" {
|
|
||||||
return errors.New(`task: Setting the "run" type is only available starting on Taskfile version v3.7`)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, task := range e.Taskfile.Tasks.Values() {
|
|
||||||
if task.Run != "" {
|
|
||||||
return errors.New(`task: Setting the "run" type is only available starting on Taskfile version v3.7`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,8 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/Masterminds/semver/v3"
|
"github.com/Masterminds/semver/v3"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/go-task/task/v3/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var V3 = semver.MustParse("3")
|
var V3 = semver.MustParse("3")
|
||||||
@ -64,9 +62,6 @@ func (tf *Taskfile) UnmarshalYAML(node *yaml.Node) error {
|
|||||||
tf.Dotenv = taskfile.Dotenv
|
tf.Dotenv = taskfile.Dotenv
|
||||||
tf.Run = taskfile.Run
|
tf.Run = taskfile.Run
|
||||||
tf.Interval = taskfile.Interval
|
tf.Interval = taskfile.Interval
|
||||||
if tf.Version == nil {
|
|
||||||
return errors.New("task: 'version' is required")
|
|
||||||
}
|
|
||||||
if tf.Vars == nil {
|
if tf.Vars == nil {
|
||||||
tf.Vars = &Vars{}
|
tf.Vars = &Vars{}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func Read(
|
|||||||
|
|
||||||
// Check that the Taskfile is set and has a schema version
|
// Check that the Taskfile is set and has a schema version
|
||||||
if t == nil || t.Version == nil {
|
if t == nil || t.Version == nil {
|
||||||
return nil, &errors.TaskfileVersionNotDefined{URI: node.Location()}
|
return nil, &errors.TaskfileVersionCheckError{URI: node.Location()}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Annotate any included Taskfile reference with a base directory for resolving relative paths
|
// Annotate any included Taskfile reference with a base directory for resolving relative paths
|
||||||
|
Loading…
x
Reference in New Issue
Block a user