Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove v2 support #1447

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 2 additions & 28 deletions args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/go-task/task/v3/taskfile"
)

// ParseV3 parses command line argument: tasks and global variables
func ParseV3(args ...string) ([]taskfile.Call, *taskfile.Vars) {
// Parse parses command line argument: tasks and global variables
func Parse(args ...string) ([]taskfile.Call, *taskfile.Vars) {
calls := []taskfile.Call{}
globals := &taskfile.Vars{}

Expand All @@ -24,32 +24,6 @@ func ParseV3(args ...string) ([]taskfile.Call, *taskfile.Vars) {
return calls, globals
}

// ParseV2 parses command line argument: tasks and vars of each task
func ParseV2(args ...string) ([]taskfile.Call, *taskfile.Vars) {
calls := []taskfile.Call{}
globals := &taskfile.Vars{}

for _, arg := range args {
if !strings.Contains(arg, "=") {
calls = append(calls, taskfile.Call{Task: arg, Direct: true})
continue
}

if len(calls) < 1 {
name, value := splitVar(arg)
globals.Set(name, taskfile.Var{Value: value})
} else {
if calls[len(calls)-1].Vars == nil {
calls[len(calls)-1].Vars = &taskfile.Vars{}
}
name, value := splitVar(arg)
calls[len(calls)-1].Vars.Set(name, taskfile.Var{Value: value})
}
}

return calls, globals
}

func splitVar(s string) (string, string) {
pair := strings.SplitN(s, "=", 2)
return pair[0], pair[1]
Expand Down
115 changes: 2 additions & 113 deletions args/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/go-task/task/v3/taskfile"
)

func TestArgsV3(t *testing.T) {
func TestArgs(t *testing.T) {
tests := []struct {
Args []string
ExpectedCalls []taskfile.Call
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestArgsV3(t *testing.T) {

for i, test := range tests {
t.Run(fmt.Sprintf("TestArgs%d", i+1), func(t *testing.T) {
calls, globals := args.ParseV3(test.Args...)
calls, globals := args.Parse(test.Args...)
assert.Equal(t, test.ExpectedCalls, calls)
if test.ExpectedGlobals.Len() > 0 || globals.Len() > 0 {
assert.Equal(t, test.ExpectedGlobals.Keys(), globals.Keys())
Expand All @@ -106,114 +106,3 @@ func TestArgsV3(t *testing.T) {
})
}
}

func TestArgsV2(t *testing.T) {
tests := []struct {
Args []string
ExpectedCalls []taskfile.Call
ExpectedGlobals *taskfile.Vars
}{
{
Args: []string{"task-a", "task-b", "task-c"},
ExpectedCalls: []taskfile.Call{
{Task: "task-a", Direct: true},
{Task: "task-b", Direct: true},
{Task: "task-c", Direct: true},
},
},
{
Args: []string{"task-a", "FOO=bar", "task-b", "task-c", "BAR=baz", "BAZ=foo"},
ExpectedCalls: []taskfile.Call{
{
Task: "task-a",
Direct: true,
Vars: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{
"FOO": {Value: "bar"},
},
[]string{"FOO"},
),
},
},
{Task: "task-b", Direct: true},
{
Task: "task-c",
Direct: true,
Vars: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{
"BAR": {Value: "baz"},
"BAZ": {Value: "foo"},
},
[]string{"BAR", "BAZ"},
),
},
},
},
},
{
Args: []string{"task-a", "CONTENT=with some spaces"},
ExpectedCalls: []taskfile.Call{
{
Task: "task-a",
Direct: true,
Vars: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{
"CONTENT": {Value: "with some spaces"},
},
[]string{"CONTENT"},
),
},
},
},
},
{
Args: []string{"FOO=bar", "task-a", "task-b"},
ExpectedCalls: []taskfile.Call{
{Task: "task-a", Direct: true},
{Task: "task-b", Direct: true},
},
ExpectedGlobals: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{
"FOO": {Value: "bar"},
},
[]string{"FOO"},
),
},
},
{
Args: nil,
ExpectedCalls: []taskfile.Call{},
},
{
Args: []string{},
ExpectedCalls: []taskfile.Call{},
},
{
Args: []string{"FOO=bar", "BAR=baz"},
ExpectedCalls: []taskfile.Call{},
ExpectedGlobals: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{
"FOO": {Value: "bar"},
"BAR": {Value: "baz"},
},
[]string{"FOO", "BAR"},
),
},
},
}

for i, test := range tests {
t.Run(fmt.Sprintf("TestArgs%d", i+1), func(t *testing.T) {
calls, globals := args.ParseV2(test.Args...)
assert.Equal(t, test.ExpectedCalls, calls)
if test.ExpectedGlobals.Len() > 0 || globals.Len() > 0 {
assert.Equal(t, test.ExpectedGlobals, globals)
}
})
}
}
6 changes: 1 addition & 5 deletions cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,7 @@ func run() error {
return err
}

if e.Taskfile.Version.Compare(taskfile.V3) >= 0 {
calls, globals = args.ParseV3(tasksAndVars...)
} else {
calls, globals = args.ParseV2(tasksAndVars...)
}
calls, globals = args.Parse(tasksAndVars...)

// If there are no calls, run the default task instead
if len(calls) == 0 {
Expand Down
25 changes: 14 additions & 11 deletions docs/docs/deprecations/version_2_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ slug: /deprecations/version-2-schema/
- Any Taskfiles that use the version 2 schema
- `Taskvar.yml` files

The Taskfile v2 schema was introduced in March 2018 and replaced by version 3 in
August the following year. Users have had a long time to update and so we feel
that it is time to tidy up the codebase and focus on new functionality instead.
The Taskfile version 2 schema was introduced in March 2018 and replaced by
version 3 in August 2019. In May 2023 [we published a deprecation
notice][deprecation-notice] for the version 2 schema on the basis that the vast
majority of users had already upgraded to version 3 and removing support for
version 2 would allow us to tidy up the codebase and focus on new functionality
instead.

This notice does not mean that we are immediately removing support for version 2
schemas. However, support will not be extended to future major releases and we
_strongly recommend_ that anybody still using a version 2 schema upgrades to
version 3 as soon as possible.

A list of changes between version 2 and version 3 are available in the [Task v3
Release Notes][version-3-release-notes].
In December 2023, the final version of Task that supports the version 2 schema
([v3.33.0][v3.33.0]) was published and all legacy code was removed from Task's
main branch. To use a more recent version of Task, you will need to ensure that
your Taskfile uses the version 3 schema instead. A list of changes between
version 2 and version 3 are available in the [Task v3 Release Notes][v3.0.0].

<!-- prettier-ignore-start -->
[version-3-release-notes]: https://github.com/go-task/task/releases/tag/v3.0.0
[v3.0.0]: https://github.com/go-task/task/releases/tag/v3.0.0
[v3.33.0]: https://github.com/go-task/task/releases/tag/v3.33.0
[deprecation-notice]: https://github.com/go-task/task/issues/1197
<!-- prettier-ignore-end -->
18 changes: 9 additions & 9 deletions docs/docs/taskfile_versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ tasks:

:::caution

v2 schema support is [deprecated][deprecate-version-2-schema] and will be
removed in a future release.
v2 schemas are [no longer supported by the latest version of
Task][deprecate-version-2-schema].

:::

Expand All @@ -106,8 +106,8 @@ Please check the [documentation][includes]

:::caution

v2 schema support is [deprecated][deprecate-version-2-schema] and will be
removed in a future release.
v2 schemas are [no longer supported by the latest version of
Task][deprecate-version-2-schema].

:::

Expand All @@ -125,8 +125,8 @@ includes:

:::caution

v2 schema support is [deprecated][deprecate-version-2-schema] and will be
removed in a future release.
v2 schemas are [no longer supported by the latest version of
Task][deprecate-version-2-schema].

:::

Expand Down Expand Up @@ -170,8 +170,8 @@ tasks:

:::caution

v2 schema support is [deprecated][deprecate-version-2-schema] and will be
removed in a future release.
v2 schemas are [no longer supported by the latest version of
Task][deprecate-version-2-schema].

:::

Expand Down Expand Up @@ -256,7 +256,7 @@ The variable priority order was also different:
4. `Taskvars.yml` variables

<!-- prettier-ignore-start -->
[deprecate-version-2-schema]: https://github.com/go-task/task/issues/1197
[deprecate-version-2-schema]: /deprecations/version-2-schema/
[output]: /usage#output-syntax
[ignore_errors]: /usage#ignore-errors
[includes]: /usage#including-other-taskfiles
Expand Down
Loading