feat: add task log output hook

This commit is contained in:
fuxiaohei 2022-08-12 12:16:47 +08:00 committed by Jason Song
parent 3b7ac17410
commit dfcb104af0
1 changed files with 20 additions and 0 deletions

View File

@ -12,10 +12,12 @@ import (
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/mattn/go-isatty" "github.com/mattn/go-isatty"
"github.com/nektos/act/pkg/artifacts" "github.com/nektos/act/pkg/artifacts"
"github.com/nektos/act/pkg/common"
"github.com/nektos/act/pkg/model" "github.com/nektos/act/pkg/model"
"github.com/nektos/act/pkg/runner" "github.com/nektos/act/pkg/runner"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -236,9 +238,27 @@ func runTask(ctx context.Context, input *Input, jobID string) error {
cancel() cancel()
return nil return nil
}) })
outputHook := new(taskLogHook)
ctx = common.WithLoggerHook(ctx, outputHook)
return executor(ctx) 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 { func runCommand(ctx context.Context, input *Input) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error {
jobID, err := cmd.Flags().GetString("job") jobID, err := cmd.Flags().GetString("job")