Skip to content

Commit abe0352

Browse files
committed
Fixed some bugs regarding minor version checks on version:
1. I have forgot to update it on recent releases. Seems that most people just use round versions since nobody complained. 2. It's too hard to understand how the github.com/Masterminds/semver package works, so I just got rid of it and we're now using plain float checks.
1 parent 4cee4aa commit abe0352

File tree

4 files changed

+36
-76
lines changed

4 files changed

+36
-76
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- Fixed some bugs regarding minor version checks on `version:`.
56
- Add `preconditions:` to task
67
([#205](https://github.com/go-task/task/pull/205)).
78
- Create directory informed on `dir:` if it doesn't exist

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module github.com/go-task/task/v2
22

33
require (
4-
github.com/Masterminds/semver v1.4.2
4+
github.com/Masterminds/semver v1.4.2 // indirect
55
github.com/Masterminds/sprig v2.16.0+incompatible
66
github.com/aokoli/goutils v1.0.1 // indirect
77
github.com/davecgh/go-spew v1.1.1 // indirect

internal/taskfile/version/version.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

task.go

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package task
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"io"
78
"os"
9+
"strconv"
810
"sync"
911
"sync/atomic"
1012

@@ -17,9 +19,7 @@ import (
1719
"github.com/go-task/task/v2/internal/summary"
1820
"github.com/go-task/task/v2/internal/taskfile"
1921
"github.com/go-task/task/v2/internal/taskfile/read"
20-
"github.com/go-task/task/v2/internal/taskfile/version"
2122

22-
"github.com/Masterminds/semver"
2323
"golang.org/x/sync/errgroup"
2424
)
2525

@@ -95,11 +95,6 @@ func (e *Executor) Setup() error {
9595
return err
9696
}
9797

98-
v, err := semver.NewConstraint(e.Taskfile.Version)
99-
if err != nil {
100-
return fmt.Errorf(`task: could not parse taskfile version "%s": %v`, e.Taskfile.Version, err)
101-
}
102-
10398
if e.Stdin == nil {
10499
e.Stdin = os.Stdin
105100
}
@@ -114,32 +109,46 @@ func (e *Executor) Setup() error {
114109
Stderr: e.Stderr,
115110
Verbose: e.Verbose,
116111
}
117-
switch {
118-
case version.IsV1(v):
112+
113+
v, err := strconv.ParseFloat(e.Taskfile.Version, 64)
114+
if err != nil {
115+
return fmt.Errorf(`task: Could not parse taskfile version "%s": %v`, e.Taskfile.Version, err)
116+
}
117+
// consider as equal to the greater version if round
118+
if v == 2.0 {
119+
v = 2.6
120+
}
121+
122+
if v < 1 {
123+
return fmt.Errorf(`task: Taskfile version should be greater or equal to v1`)
124+
}
125+
if v > 2.6 {
126+
return fmt.Errorf(`task: Taskfile versions greater than v2.6 not implemented in the version of Task`)
127+
}
128+
129+
if v < 2 {
119130
e.Compiler = &compilerv1.CompilerV1{
120131
Dir: e.Dir,
121132
Vars: e.taskvars,
122133
Logger: e.Logger,
123134
}
124-
case version.IsV2(v), version.IsV21(v), version.IsV22(v), version.IsV23(v):
135+
} else { // v >= 2
125136
e.Compiler = &compilerv2.CompilerV2{
126137
Dir: e.Dir,
127138
Taskvars: e.taskvars,
128139
TaskfileVars: e.Taskfile.Vars,
129140
Expansions: e.Taskfile.Expansions,
130141
Logger: e.Logger,
131142
}
132-
133-
case version.IsV24(v):
134-
return fmt.Errorf(`task: Taskfile versions greater than v2.4 not implemented in the version of Task`)
135143
}
136144

137-
if !version.IsV21(v) && e.Taskfile.Output != "" {
145+
if v < 2.1 && e.Taskfile.Output != "" {
138146
return fmt.Errorf(`task: Taskfile option "output" is only available starting on Taskfile version v2.1`)
139147
}
140-
if !version.IsV22(v) && len(e.Taskfile.Includes) > 0 {
148+
if v < 2.2 && len(e.Taskfile.Includes) > 0 {
141149
return fmt.Errorf(`task: Including Taskfiles is only available starting on Taskfile version v2.2`)
142150
}
151+
143152
if e.OutputStyle != "" {
144153
e.Taskfile.Output = e.OutputStyle
145154
}
@@ -154,8 +163,8 @@ func (e *Executor) Setup() error {
154163
return fmt.Errorf(`task: output option "%s" not recognized`, e.Taskfile.Output)
155164
}
156165

157-
if !version.IsV21(v) {
158-
err := fmt.Errorf(`task: Taskfile option "ignore_error" is only available starting on Taskfile version v2.1`)
166+
if v <= 2.1 {
167+
err := errors.New(`task: Taskfile option "ignore_error" is only available starting on Taskfile version v2.1`)
159168

160169
for _, task := range e.Taskfile.Tasks {
161170
if task.IgnoreError {
@@ -169,6 +178,14 @@ func (e *Executor) Setup() error {
169178
}
170179
}
171180

181+
if v < 2.6 {
182+
for _, task := range e.Taskfile.Tasks {
183+
if len(task.Preconditions) > 0 {
184+
return errors.New(`task: Task option "preconditions" is only available starting on Taskfile version v2.6`)
185+
}
186+
}
187+
}
188+
172189
e.taskCallCount = make(map[string]*int32, len(e.Taskfile.Tasks))
173190
e.mkdirMutexMap = make(map[string]*sync.Mutex, len(e.Taskfile.Tasks))
174191
for k := range e.Taskfile.Tasks {

0 commit comments

Comments
 (0)