mirror of
https://gitea.com/gitea/act_runner.git
synced 2024-12-28 11:58:20 +01:00
feat: add task log output hook
This commit is contained in:
parent
3b7ac17410
commit
dfcb104af0
20
cmd/root.go
20
cmd/root.go
@ -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")
|
||||||
|
Loading…
Reference in New Issue
Block a user