mirror of
https://github.com/go-task/task.git
synced 2025-06-15 00:15:10 +02:00
Add support for 'platforms' in both task and command (#980)
This commit is contained in:
24
task.go
24
task.go
@ -135,6 +135,13 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
|
||||
defer release()
|
||||
|
||||
return e.startExecution(ctx, t, func(ctx context.Context) error {
|
||||
|
||||
// Check platform
|
||||
if !ShouldRunOnCurrentPlatform(t.Platforms) {
|
||||
e.Logger.VerboseOutf(logger.Yellow, `task: "%s" not for current platform - ignored`, call.Task)
|
||||
return nil
|
||||
}
|
||||
|
||||
e.Logger.VerboseErrf(logger.Magenta, `task: "%s" started`, call.Task)
|
||||
if err := e.runDeps(ctx, t); err != nil {
|
||||
return err
|
||||
@ -252,6 +259,11 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi
|
||||
}
|
||||
return nil
|
||||
case cmd.Cmd != "":
|
||||
// Check platform
|
||||
if !ShouldRunOnCurrentPlatform(cmd.Platforms) {
|
||||
e.Logger.VerboseOutf(logger.Yellow, `task: [%s] %s not for current platform - ignored`, t.Name(), cmd.Cmd)
|
||||
return nil
|
||||
}
|
||||
if e.Verbose || (!cmd.Silent && !t.Silent && !e.Taskfile.Silent && !e.Silent) {
|
||||
e.Logger.Errf(logger.Green, "task: [%s] %s", t.Name(), cmd.Cmd)
|
||||
}
|
||||
@ -455,3 +467,15 @@ func FilterOutInternal() FilterFunc {
|
||||
return task.Internal
|
||||
})
|
||||
}
|
||||
|
||||
func ShouldRunOnCurrentPlatform(platforms []*taskfile.Platform) bool {
|
||||
if len(platforms) == 0 {
|
||||
return true
|
||||
}
|
||||
for _, platform := range platforms {
|
||||
if platform.MatchesCurrentPlatform() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user