Repository: go-task/task
Pull request #1199 (2023-06-03 20:09:56)

feat: add a deprecation warning when running Taskfiles with a v2 schema
Added a warning to the output when using a `version: 2` schema. (This functionality was split out of #1198).

![image](https://github.com/go-task/task/assets/9294862/17e9b6fb-b2fc-4a7f-abc1-fd2b9a5d57f3)

This might break things for people using v2 schemas in scripts if they update... we could stop output if the `--silent` flag is specified, but this might not stop it from breaking where some tasks have `silent: true`. Maybe we send the output to stderr instead? Thoughts welcome.

andreynering: One more thing: this is worth a mention on the CHANGELOG, IMO.

> Schema version 2 is now considered deprecated and scheduled to be removed in the next major release.
pd93: > Yes, sending to `stderr` would be more appropriate, and mitigate possible breakage in scripts

Updated

> Yes, respecting the `--silent` flag be interesting. I wouldn't worry too much about `silent: true` set on tasks, though. v2 has very few users currently.

It's actually kind of annoying to pass in the flags to the version checks function. I could move the check into the main function, but I think with this being output to stderr now, this should be necessary anymore?

> One more thing: this is worth a mention on the CHANGELOG, IMO.

Ah yeah, I forgot to bring this change over from #1198. I've added it now, Thanks


andreynering: > It's actually kind of annoying to pass in the flags to the version checks function. I could move the check into the main function, but I think with this being output to stderr now, this should be necessary anymore?

Agreed. No need to check `--silent` anymore.

CI broke. Probably easy to fix, just a matter of check `stderr` instead of `stdout` on the test, I believe.
pd93: > CI broke. Probably easy to fix, just a matter of check stderr instead of stdout on the test, I believe.

Whoops, thank you 😛 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b962c93d..d55e76dd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@
   #1194 by @deviantintegral).
 - Added [experiments documentation](https://taskfile.dev/experiments) to the
   website (#1198 by @pd93).
+- Deprecated `version: 2` schema. This will be removed in the next major release
+  (#1197, #1198, #1199 by @pd93).
 
 ## v3.25.0 - 2023-05-22
 
diff --git a/setup.go b/setup.go
index 2eb72a87..060cc782 100644
--- a/setup.go
+++ b/setup.go
@@ -250,7 +250,11 @@ func (e *Executor) doVersionChecks() error {
 	*v = *e.Taskfile.Version
 
 	if v.LessThan(taskfile.V2) {
-		return fmt.Errorf(`task: Taskfile versions prior to v2 are not supported anymore`)
+		return fmt.Errorf(`task: version 1 schemas are no longer supported`)
+	}
+
+	if v.LessThan(taskfile.V3) {
+		e.Logger.Errf(logger.Yellow, "task: version 2 schemas are deprecated and will be removed in a future release\nSee https://github.com/go-task/task/issues/1197 for more details\n")
 	}
 
 	// consider as equal to the greater version if round


Test patch:
diff --git a/task_test.go b/task_test.go
index e238e95d..4046a7a8 100644
--- a/task_test.go
+++ b/task_test.go
@@ -1371,7 +1371,7 @@ func TestDynamicVariablesShouldRunOnTheTaskDir(t *testing.T) {
 	tt.Run(t)
 }
 
-func TestDisplaysErrorOnUnsupportedVersion(t *testing.T) {
+func TestDisplaysErrorOnVersion1Schema(t *testing.T) {
 	e := task.Executor{
 		Dir:    "testdata/version/v1",
 		Stdout: io.Discard,
@@ -1379,7 +1379,19 @@ func TestDisplaysErrorOnUnsupportedVersion(t *testing.T) {
 	}
 	err := e.Setup()
 	require.Error(t, err)
-	assert.Equal(t, "task: Taskfile versions prior to v2 are not supported anymore", err.Error())
+	assert.Equal(t, "task: version 1 schemas are no longer supported", err.Error())
+}
+
+func TestDisplaysWarningOnVersion2Schema(t *testing.T) {
+	var buff bytes.Buffer
+	e := task.Executor{
+		Dir:    "testdata/version/v2",
+		Stdout: io.Discard,
+		Stderr: &buff,
+	}
+	err := e.Setup()
+	require.NoError(t, err)
+	assert.Equal(t, "task: version 2 schemas are deprecated and will be removed in a future release\nSee https://github.com/go-task/task/issues/1197 for more details\n", buff.String())
 }
 
 func TestShortTaskNotation(t *testing.T) {