Skip to content

Commit a125efb

Browse files
committed
bazel-github-helper: additionally dump summary markdown to build log
Release note: none Epic: none
1 parent 43b6fce commit a125efb

File tree

1 file changed

+14
-10
lines changed
  • pkg/cmd/bazci/bazel-github-helper

1 file changed

+14
-10
lines changed

pkg/cmd/bazci/bazel-github-helper/main.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"encoding/xml"
2323
"flag"
2424
"fmt"
25+
"io"
2526
"os"
2627
"os/exec"
2728
"sort"
@@ -79,7 +80,10 @@ func process() error {
7980
summaryF, err := os.OpenFile(summaryFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
8081
if err == nil {
8182
defer func() { _ = summaryF.Close() }()
82-
logError("dump summary", dumpSummary(summaryF, invocation))
83+
fmt.Fprintln(os.Stdout, "=== BEGIN SUMMARY MARKDOWN ===")
84+
w := io.MultiWriter(summaryF, os.Stdout)
85+
logError("dump summary", dumpSummary(w, invocation))
86+
fmt.Fprintln(os.Stdout, "=== END SUMMARY MARKDOWN ===")
8387
} else {
8488
logError("open summary file", err)
8589
}
@@ -131,7 +135,7 @@ func process() error {
131135
return nil
132136
}
133137

134-
func dumpSummary(f *os.File, invocation *engflow.InvocationInfo) error {
138+
func dumpSummary(f io.Writer, invocation *engflow.InvocationInfo) error {
135139
var title string
136140
if !invocation.Finished {
137141
title = "# Build did not succeed"
@@ -140,11 +144,11 @@ func dumpSummary(f *os.File, invocation *engflow.InvocationInfo) error {
140144
} else {
141145
title = fmt.Sprintf("# Build Failed (code: %s)", invocation.ExitCodeName)
142146
}
143-
_, err := f.WriteString(fmt.Sprintf("%s\n", title))
147+
_, err := fmt.Fprintf(f, "%s\n", title)
144148
if err != nil {
145149
return err
146150
}
147-
_, err = f.WriteString(fmt.Sprintf("### [EngFlow link](https://%s.cluster.engflow.com/invocations/default/%s)\n", *serverName, invocation.InvocationId))
151+
_, err = fmt.Fprintf(f, "### [EngFlow link](https://%s.cluster.engflow.com/invocations/default/%s)\n", *serverName, invocation.InvocationId)
148152
if err != nil {
149153
return err
150154
}
@@ -196,15 +200,15 @@ func dumpSummary(f *os.File, invocation *engflow.InvocationInfo) error {
196200
})
197201

198202
if len(failedTests) != 0 {
199-
_, err := f.WriteString(`| Label | TestName | Status | Link |
203+
_, err := io.WriteString(f, `| Label | TestName | Status | Link |
200204
| --- | --- | --- | --- |
201205
`)
202206
if err != nil {
203207
return err
204208
}
205209
for _, failedTest := range failedTests {
206210
base64Target := base64.StdEncoding.EncodeToString([]byte(failedTest.label))
207-
_, err := f.WriteString(fmt.Sprintf("| `%s` | `%s` | `%s` | [Link](https://%s.cluster.engflow.com/invocations/default/%s?testReportRun=%d&testReportShard=%d&testReportAttempt=%d#targets-%s) |\n", failedTest.label, failedTest.name, failedTest.status, *serverName, invocation.InvocationId, failedTest.run, failedTest.shard, failedTest.attempt, base64Target))
211+
_, err := fmt.Fprintf(f, "| `%s` | `%s` | `%s` | [Link](https://%s.cluster.engflow.com/invocations/default/%s?testReportRun=%d&testReportShard=%d&testReportAttempt=%d#targets-%s) |\n", failedTest.label, failedTest.name, failedTest.status, *serverName, invocation.InvocationId, failedTest.run, failedTest.shard, failedTest.attempt, base64Target)
208212
if err != nil {
209213
return err
210214
}
@@ -214,12 +218,12 @@ func dumpSummary(f *os.File, invocation *engflow.InvocationInfo) error {
214218
if len(invocation.FailedBuildActions) > 0 {
215219
for _, actions := range invocation.FailedBuildActions {
216220
for _, action := range actions {
217-
_, err := f.WriteString(fmt.Sprintf("### Build of `%s` failed (exit code %d)\n", action.Label, action.ExitCode))
221+
_, err := fmt.Fprintf(f, "### Build of `%s` failed (exit code %d)\n", action.Label, action.ExitCode)
218222
if err != nil {
219223
return err
220224
}
221225
if action.FailureDetail != "" {
222-
_, err := f.WriteString(fmt.Sprintf("```\n%s\n```\n", action.FailureDetail))
226+
_, err := fmt.Fprintf(f, "```\n%s\n```\n", action.FailureDetail)
223227
if err != nil {
224228
return err
225229
}
@@ -228,13 +232,13 @@ func dumpSummary(f *os.File, invocation *engflow.InvocationInfo) error {
228232
fmt.Fprintf(os.Stderr, "could not download action log: got error %+v\n", err)
229233
}
230234
if action.Stdout != "" {
231-
_, err := f.WriteString(fmt.Sprintf("Stdout:\n```\n%s\n```\n", action.Stdout))
235+
_, err := fmt.Fprintf(f, "Stdout:\n```\n%s\n```\n", action.Stdout)
232236
if err != nil {
233237
return err
234238
}
235239
}
236240
if action.Stderr != "" {
237-
_, err := f.WriteString(fmt.Sprintf("Stdout:\n```\n%s\n```\n", action.Stderr))
241+
_, err := fmt.Fprintf(f, "Stdout:\n```\n%s\n```\n", action.Stderr)
238242
if err != nil {
239243
return err
240244
}

0 commit comments

Comments
 (0)