1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

add commands support

Signed-off-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
Casey Lee 2020-02-11 23:38:30 -08:00
parent c44aa2a118
commit c236395c01
12 changed files with 303 additions and 33 deletions

View file

@ -7,6 +7,7 @@ import (
"io"
"os"
"strings"
"sync"
"github.com/nektos/act/pkg/common"
@ -27,6 +28,7 @@ const (
var colors []int
var nextColor int
var mux sync.Mutex
func init() {
nextColor = 0
@ -37,9 +39,11 @@ func init() {
// WithJobLogger attaches a new logger to context that is aware of steps
func WithJobLogger(ctx context.Context, jobName string) context.Context {
mux.Lock()
defer mux.Unlock()
formatter := new(stepLogFormatter)
formatter.color = colors[nextColor%len(colors)]
nextColor = nextColor + 1
nextColor++
logger := logrus.New()
logger.SetFormatter(formatter)
@ -71,7 +75,9 @@ func (f *stepLogFormatter) printColored(b *bytes.Buffer, entry *logrus.Entry) {
entry.Message = strings.TrimSuffix(entry.Message, "\n")
jobName := entry.Data["job"]
if entry.Data["dryrun"] == true {
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", gray, f.color, jobName, entry.Message)
} else {
fmt.Fprintf(b, "\x1b[%dm[%s] \x1b[0m%s", f.color, jobName, entry.Message)
@ -82,7 +88,9 @@ func (f *stepLogFormatter) print(b *bytes.Buffer, entry *logrus.Entry) {
entry.Message = strings.TrimSuffix(entry.Message, "\n")
jobName := entry.Data["job"]
if entry.Data["dryrun"] == true {
if entry.Data["raw_output"] == true {
fmt.Fprintf(b, "[%s] | %s", jobName, entry.Message)
} else if entry.Data["dryrun"] == true {
fmt.Fprintf(b, "*DRYRUN* [%s] %s", jobName, entry.Message)
} else {
fmt.Fprintf(b, "[%s] %s", jobName, entry.Message)