From dfcb104af02b536df7dfd7dc6d5911b654038ae9 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Fri, 12 Aug 2022 12:16:47 +0800 Subject: [PATCH] feat: add task log output hook --- cmd/root.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index e079c1c..29fc7b0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,10 +12,12 @@ import ( "github.com/joho/godotenv" "github.com/mattn/go-isatty" "github.com/nektos/act/pkg/artifacts" + "github.com/nektos/act/pkg/common" "github.com/nektos/act/pkg/model" "github.com/nektos/act/pkg/runner" "github.com/rs/zerolog" "github.com/rs/zerolog/log" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -236,9 +238,27 @@ func runTask(ctx context.Context, input *Input, jobID string) error { cancel() return nil }) + + outputHook := new(taskLogHook) + ctx = common.WithLoggerHook(ctx, outputHook) return executor(ctx) } +type taskLogHook struct{} + +func (h *taskLogHook) Levels() []logrus.Level { + return logrus.AllLevels +} + +func (h *taskLogHook) Fire(entry *logrus.Entry) error { + if flag, ok := entry.Data["raw_output"]; ok { + if flagVal, ok := flag.(bool); flagVal && ok { + log.Info().Msgf("task log: %s", entry.Message) + } + } + return nil +} + func runCommand(ctx context.Context, input *Input) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { jobID, err := cmd.Flags().GetString("job")