From 34646f553d8f248d6885ed082cc74822e164f680 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Sun, 4 Dec 2022 01:56:07 +0100 Subject: [PATCH] Add collapsible stdout --- go/localtests/test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/go/localtests/test.go b/go/localtests/test.go index 1ed659f..ae9b13e 100644 --- a/go/localtests/test.go +++ b/go/localtests/test.go @@ -1,11 +1,15 @@ package localtests import ( + "bufio" "bytes" "database/sql" "fmt" + "io" "log" + "os" "os/exec" + "strings" ) // Test represents a single test. @@ -126,12 +130,22 @@ func (test *Test) Migrate(config Config, primary, replica *sql.DB) (err error) { cmd.Stderr = &stderr cmd.Stdout = &output + if strings.TrimSpace(os.Getenv("GITHUB_ACTION")) == "true" { + go func(reader io.Reader) { + scanner := bufio.NewScanner(output) + fmt.Printf("::group::%s stdout\n", test.Name) + for scanner.Scan() { + fmt.Println(scanner.Text()) + } + fmt.Println("::endgroup::") + }(&output) + } + if err = cmd.Run(); err != nil { if isExpectedFailureOutput(&stderr, test.ExpectedFailure) { return nil } - output.Write(stderr.Bytes()) - log.Printf("[%s] test failed: %+v", test.Name, output.String()) + log.Printf("[%s] test failed: %+v", test.Name, stderr.String()) } return err }