summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.github/actions/run-tests/action.yml2
-rw-r--r--cmd/input.go1
-rw-r--r--cmd/root.go2
-rw-r--r--pkg/runner/logger.go34
-rw-r--r--pkg/runner/runner.go1
5 files changed, 30 insertions, 10 deletions
diff --git a/.github/actions/run-tests/action.yml b/.github/actions/run-tests/action.yml
index 09cb3da..f548c0a 100644
--- a/.github/actions/run-tests/action.yml
+++ b/.github/actions/run-tests/action.yml
@@ -54,7 +54,7 @@ runs:
}
}
};
- var args = ['test', '-v', '-cover', '-coverprofile=coverage.txt', '-covermode=atomic', '-timeout', '15m'];
+ var args = ['test', '-v', '-cover', '-coverprofile=coverage.txt', '-covermode=atomic', '-timeout', '20m'];
var filter = process.env.FILTER;
if(filter) {
args.push('-run');
diff --git a/cmd/input.go b/cmd/input.go
index 64556e1..1ae2793 100644
--- a/cmd/input.go
+++ b/cmd/input.go
@@ -55,6 +55,7 @@ type Input struct {
replaceGheActionTokenWithGithubCom string
matrix []string
actionCachePath string
+ logPrefixJobID bool
}
func (i *Input) resolve(path string) string {
diff --git a/cmd/root.go b/cmd/root.go
index f7b6515..679d20e 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -75,6 +75,7 @@ func Execute(ctx context.Context, version string) {
rootCmd.PersistentFlags().StringVarP(&input.workdir, "directory", "C", ".", "working directory")
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output")
rootCmd.PersistentFlags().BoolVar(&input.jsonLogger, "json", false, "Output logs in json format")
+ rootCmd.PersistentFlags().BoolVar(&input.logPrefixJobID, "log-prefix-job-id", false, "Output the job id within non-json logs instead of the entire name")
rootCmd.PersistentFlags().BoolVarP(&input.noOutput, "quiet", "q", false, "disable logging of output from steps")
rootCmd.PersistentFlags().BoolVarP(&input.dryrun, "dryrun", "n", false, "dryrun mode")
rootCmd.PersistentFlags().StringVarP(&input.secretfile, "secret-file", "", ".secrets", "file with list of secrets to read from (e.g. --secret-file .secrets)")
@@ -584,6 +585,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
BindWorkdir: input.bindWorkdir,
LogOutput: !input.noOutput,
JSONLogger: input.jsonLogger,
+ LogPrefixJobID: input.logPrefixJobID,
Env: envs,
Secrets: secrets,
Vars: vars,
diff --git a/pkg/runner/logger.go b/pkg/runner/logger.go
index 162fc57..5a98210 100644
--- a/pkg/runner/logger.go
+++ b/pkg/runner/logger.go
@@ -85,7 +85,8 @@ func WithJobLogger(ctx context.Context, jobID string, jobName string, config *Co
defer mux.Unlock()
nextColor++
formatter = &jobLogFormatter{
- color: colors[nextColor%len(colors)],
+ color: colors[nextColor%len(colors)],
+ logPrefixJobID: config.LogPrefixJobID,
}
}
@@ -176,7 +177,8 @@ func (f *maskedFormatter) Format(entry *logrus.Entry) ([]byte, error) {
}
type jobLogFormatter struct {
- color int
+ color int
+ logPrefixJobID bool
}
func (f *jobLogFormatter) Format(entry *logrus.Entry) ([]byte, error) {
@@ -194,7 +196,14 @@ func (f *jobLogFormatter) Format(entry *logrus.Entry) ([]byte, error) {
func (f *jobLogFormatter) printColored(b *bytes.Buffer, entry *logrus.Entry) {
entry.Message = strings.TrimSuffix(entry.Message, "\n")
- jobName := entry.Data["job"]
+
+ var job any
+ if f.logPrefixJobID {
+ job = entry.Data["jobID"]
+ } else {
+ job = entry.Data["job"]
+ }
+
debugFlag := ""
if entry.Level == logrus.DebugLevel {
debugFlag = "[DEBUG] "
@@ -203,26 +212,33 @@ func (f *jobLogFormatter) printColored(b *bytes.Buffer, entry *logrus.Entry) {
if entry.Data["raw_output"] == true {
fmt.Fprintf(b, "\x1b[%dm|\x1b[0m %s", f.color, entry.Message)
} else if entry.Data["dryrun"] == true {
- fmt.Fprintf(b, "\x1b[1m\x1b[%dm\x1b[7m*DRYRUN*\x1b[0m \x1b[%dm[%s] \x1b[0m%s%s", gray, f.color, jobName, debugFlag, entry.Message)
+ fmt.Fprintf(b, "\x1b[1m\x1b[%dm\x1b[7m*DRYRUN*\x1b[0m \x1b[%dm[%s] \x1b[0m%s%s", gray, f.color, job, debugFlag, entry.Message)
} else {
- fmt.Fprintf(b, "\x1b[%dm[%s] \x1b[0m%s%s", f.color, jobName, debugFlag, entry.Message)
+ fmt.Fprintf(b, "\x1b[%dm[%s] \x1b[0m%s%s", f.color, job, debugFlag, entry.Message)
}
}
func (f *jobLogFormatter) print(b *bytes.Buffer, entry *logrus.Entry) {
entry.Message = strings.TrimSuffix(entry.Message, "\n")
- jobName := entry.Data["job"]
+
+ var job any
+ if f.logPrefixJobID {
+ job = entry.Data["jobID"]
+ } else {
+ job = entry.Data["job"]
+ }
+
debugFlag := ""
if entry.Level == logrus.DebugLevel {
debugFlag = "[DEBUG] "
}
if entry.Data["raw_output"] == true {
- fmt.Fprintf(b, "[%s] | %s", jobName, entry.Message)
+ fmt.Fprintf(b, "[%s] | %s", job, entry.Message)
} else if entry.Data["dryrun"] == true {
- fmt.Fprintf(b, "*DRYRUN* [%s] %s%s", jobName, debugFlag, entry.Message)
+ fmt.Fprintf(b, "*DRYRUN* [%s] %s%s", job, debugFlag, entry.Message)
} else {
- fmt.Fprintf(b, "[%s] %s%s", jobName, debugFlag, entry.Message)
+ fmt.Fprintf(b, "[%s] %s%s", job, debugFlag, entry.Message)
}
}
diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go
index ecb70e7..09c1731 100644
--- a/pkg/runner/runner.go
+++ b/pkg/runner/runner.go
@@ -32,6 +32,7 @@ type Config struct {
ForceRebuild bool // force rebuilding local docker image action
LogOutput bool // log the output from docker run
JSONLogger bool // use json or text logger
+ LogPrefixJobID bool // switches from the full job name to the job id
Env map[string]string // env for containers
Inputs map[string]string // manually passed action inputs
Secrets map[string]string // list of secrets