Skip to content
Draft
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
19 changes: 13 additions & 6 deletions internal/fingerprint/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@ import (
"github.com/go-task/task/v3/internal/env"
"github.com/go-task/task/v3/internal/execext"
"github.com/go-task/task/v3/internal/logger"
"github.com/go-task/task/v3/internal/slicesext"
"github.com/go-task/task/v3/taskfile/ast"
)

type StatusChecker struct {
logger *logger.Logger
logger *logger.Logger
posixOpts []string
bashOpts []string
}

func NewStatusChecker(logger *logger.Logger) StatusCheckable {
func NewStatusChecker(logger *logger.Logger, posixOpts []string, bashOpts []string) StatusCheckable {
return &StatusChecker{
logger: logger,
logger: logger,
posixOpts: posixOpts,
bashOpts: bashOpts,
}
}

func (checker *StatusChecker) IsUpToDate(ctx context.Context, t *ast.Task) (bool, error) {
for _, s := range t.Status {
err := execext.RunCommand(ctx, &execext.RunCommandOptions{
Command: s,
Dir: t.Dir,
Env: env.Get(t),
Command: s,
Dir: t.Dir,
Env: env.Get(t),
PosixOpts: slicesext.UniqueJoin(checker.posixOpts, t.Set),
BashOpts: slicesext.UniqueJoin(checker.bashOpts, t.Shopt),
})
if err != nil {
checker.logger.VerboseOutf(logger.Yellow, "task: status command %s exited non-zero: %s\n", s, err)
Expand Down
18 changes: 17 additions & 1 deletion internal/fingerprint/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type (
logger *logger.Logger
statusChecker StatusCheckable
sourcesChecker SourcesCheckable
posixOpts []string
bashOpts []string
}
)

Expand Down Expand Up @@ -55,6 +57,18 @@ func WithSourcesChecker(checker SourcesCheckable) CheckerOption {
}
}

func WithPosixOpts(posixOpts []string) CheckerOption {
return func(config *CheckerConfig) {
config.posixOpts = posixOpts
}
}

func WithBashOpts(bashOpts []string) CheckerOption {
return func(config *CheckerConfig) {
config.bashOpts = bashOpts
}
}

func IsTaskUpToDate(
ctx context.Context,
t *ast.Task,
Expand All @@ -72,6 +86,8 @@ func IsTaskUpToDate(
logger: nil,
statusChecker: nil,
sourcesChecker: nil,
posixOpts: []string{},
bashOpts: []string{},
}

// Apply functional options
Expand All @@ -81,7 +97,7 @@ func IsTaskUpToDate(

// If no status checker was given, set up the default one
if config.statusChecker == nil {
config.statusChecker = NewStatusChecker(config.logger)
config.statusChecker = NewStatusChecker(config.logger, config.posixOpts, config.bashOpts)
}

// If no sources checker was given, set up the default one
Expand Down
9 changes: 6 additions & 3 deletions precondition.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/go-task/task/v3/internal/env"
"github.com/go-task/task/v3/internal/execext"
"github.com/go-task/task/v3/internal/logger"
"github.com/go-task/task/v3/internal/slicesext"
"github.com/go-task/task/v3/taskfile/ast"
)

Expand All @@ -16,9 +17,11 @@ var ErrPreconditionFailed = errors.New("task: precondition not met")
func (e *Executor) areTaskPreconditionsMet(ctx context.Context, t *ast.Task) (bool, error) {
for _, p := range t.Preconditions {
err := execext.RunCommand(ctx, &execext.RunCommandOptions{
Command: p.Sh,
Dir: t.Dir,
Env: env.Get(t),
Command: p.Sh,
Dir: t.Dir,
Env: env.Get(t),
PosixOpts: slicesext.UniqueJoin(e.Taskfile.Set, t.Set),
BashOpts: slicesext.UniqueJoin(e.Taskfile.Shopt, t.Shopt),
})
if err != nil {
if !errors.Is(err, context.Canceled) {
Expand Down
2 changes: 2 additions & 0 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func (e *Executor) Status(ctx context.Context, calls ...*Call) error {
fingerprint.WithTempDir(e.TempDir.Fingerprint),
fingerprint.WithDry(e.Dry),
fingerprint.WithLogger(e.Logger),
fingerprint.WithPosixOpts(e.Taskfile.Set),
fingerprint.WithBashOpts(e.Taskfile.Shopt),
)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ func (e *Executor) RunTask(ctx context.Context, call *Call) error {
fingerprint.WithTempDir(e.TempDir.Fingerprint),
fingerprint.WithDry(e.Dry),
fingerprint.WithLogger(e.Logger),
fingerprint.WithPosixOpts(e.Taskfile.Set),
fingerprint.WithBashOpts(e.Taskfile.Shopt),
)
if err != nil {
return err
Expand Down
Loading