1
0
mirror of https://github.com/go-task/task.git synced 2025-01-20 04:59:37 +02:00

feat: invert call.Direct (#1459)

This commit is contained in:
Pete Davison 2024-01-11 00:32:49 +00:00 committed by GitHub
parent 07e6f5cad7
commit 42af0fc791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 22 deletions

View File

@ -13,7 +13,7 @@ func Parse(args ...string) ([]ast.Call, *ast.Vars) {
for _, arg := range args { for _, arg := range args {
if !strings.Contains(arg, "=") { if !strings.Contains(arg, "=") {
calls = append(calls, ast.Call{Task: arg, Direct: true}) calls = append(calls, ast.Call{Task: arg})
continue continue
} }

View File

@ -20,17 +20,17 @@ func TestArgs(t *testing.T) {
{ {
Args: []string{"task-a", "task-b", "task-c"}, Args: []string{"task-a", "task-b", "task-c"},
ExpectedCalls: []ast.Call{ ExpectedCalls: []ast.Call{
{Task: "task-a", Direct: true}, {Task: "task-a"},
{Task: "task-b", Direct: true}, {Task: "task-b"},
{Task: "task-c", Direct: true}, {Task: "task-c"},
}, },
}, },
{ {
Args: []string{"task-a", "FOO=bar", "task-b", "task-c", "BAR=baz", "BAZ=foo"}, Args: []string{"task-a", "FOO=bar", "task-b", "task-c", "BAR=baz", "BAZ=foo"},
ExpectedCalls: []ast.Call{ ExpectedCalls: []ast.Call{
{Task: "task-a", Direct: true}, {Task: "task-a"},
{Task: "task-b", Direct: true}, {Task: "task-b"},
{Task: "task-c", Direct: true}, {Task: "task-c"},
}, },
ExpectedGlobals: &ast.Vars{ ExpectedGlobals: &ast.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
@ -46,7 +46,7 @@ func TestArgs(t *testing.T) {
{ {
Args: []string{"task-a", "CONTENT=with some spaces"}, Args: []string{"task-a", "CONTENT=with some spaces"},
ExpectedCalls: []ast.Call{ ExpectedCalls: []ast.Call{
{Task: "task-a", Direct: true}, {Task: "task-a"},
}, },
ExpectedGlobals: &ast.Vars{ ExpectedGlobals: &ast.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
@ -60,8 +60,8 @@ func TestArgs(t *testing.T) {
{ {
Args: []string{"FOO=bar", "task-a", "task-b"}, Args: []string{"FOO=bar", "task-a", "task-b"},
ExpectedCalls: []ast.Call{ ExpectedCalls: []ast.Call{
{Task: "task-a", Direct: true}, {Task: "task-a"},
{Task: "task-b", Direct: true}, {Task: "task-b"},
}, },
ExpectedGlobals: &ast.Vars{ ExpectedGlobals: &ast.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(

View File

@ -304,7 +304,7 @@ func run() error {
// If there are no calls, run the default task instead // If there are no calls, run the default task instead
if len(calls) == 0 { if len(calls) == 0 {
calls = append(calls, ast.Call{Task: "default", Direct: true}) calls = append(calls, ast.Call{Task: "default"})
} }
globals.Set("CLI_ARGS", ast.Var{Value: cliArgs}) globals.Set("CLI_ARGS", ast.Var{Value: cliArgs})

View File

@ -199,7 +199,7 @@ func (e *Executor) RunTask(ctx context.Context, call ast.Call) error {
return err return err
} }
skipFingerprinting := e.ForceAll || (call.Direct && e.Force) skipFingerprinting := e.ForceAll || (!call.Indirect && e.Force)
if !skipFingerprinting { if !skipFingerprinting {
if err := ctx.Err(); err != nil { if err := ctx.Err(); err != nil {
return err return err
@ -258,7 +258,7 @@ func (e *Executor) RunTask(ctx context.Context, call ast.Call) error {
continue continue
} }
if !call.Direct { if call.Indirect {
return err return err
} }
@ -296,7 +296,7 @@ func (e *Executor) runDeps(ctx context.Context, t *ast.Task) error {
for _, d := range t.Deps { for _, d := range t.Deps {
d := d d := d
g.Go(func() error { g.Go(func() error {
err := e.RunTask(ctx, ast.Call{Task: d.Task, Vars: d.Vars, Silent: d.Silent}) err := e.RunTask(ctx, ast.Call{Task: d.Task, Vars: d.Vars, Silent: d.Silent, Indirect: true})
if err != nil { if err != nil {
return err return err
} }
@ -324,7 +324,7 @@ func (e *Executor) runCommand(ctx context.Context, t *ast.Task, call ast.Call, i
reacquire := e.releaseConcurrencyLimit() reacquire := e.releaseConcurrencyLimit()
defer reacquire() defer reacquire()
err := e.RunTask(ctx, ast.Call{Task: cmd.Task, Vars: cmd.Vars, Silent: cmd.Silent}) err := e.RunTask(ctx, ast.Call{Task: cmd.Task, Vars: cmd.Vars, Silent: cmd.Silent, Indirect: true})
if err != nil { if err != nil {
return err return err
} }

View File

@ -1789,7 +1789,7 @@ func TestErrorCode(t *testing.T) {
} }
require.NoError(t, e.Setup()) require.NoError(t, e.Setup())
err := e.Run(context.Background(), ast.Call{Task: test.task, Direct: true}) err := e.Run(context.Background(), ast.Call{Task: test.task})
require.Error(t, err) require.Error(t, err)
taskRunErr, ok := err.(*errors.TaskRunError) taskRunErr, ok := err.(*errors.TaskRunError)
assert.True(t, ok, "cannot cast returned error to *task.TaskRunError") assert.True(t, ok, "cannot cast returned error to *task.TaskRunError")
@ -2183,7 +2183,7 @@ func TestForce(t *testing.T) {
ForceAll: tt.forceAll, ForceAll: tt.forceAll,
} }
require.NoError(t, e.Setup()) require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), ast.Call{Task: "task-with-dep", Direct: true})) require.NoError(t, e.Run(context.Background(), ast.Call{Task: "task-with-dep"}))
}) })
} }
} }
@ -2238,7 +2238,7 @@ func TestFor(t *testing.T) {
Force: true, Force: true,
} }
require.NoError(t, e.Setup()) require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), ast.Call{Task: test.name, Direct: true})) require.NoError(t, e.Run(context.Background(), ast.Call{Task: test.name}))
assert.Equal(t, test.expectedOutput, buff.String()) assert.Equal(t, test.expectedOutput, buff.String())
}) })
} }

View File

@ -2,8 +2,8 @@ package ast
// Call is the parameters to a task call // Call is the parameters to a task call
type Call struct { type Call struct {
Task string Task string
Vars *Vars Vars *Vars
Silent bool Silent bool
Direct bool // Was the task called directly or via another task? Indirect bool // True if the task was called by another task
} }