Skip to content

Commit 1e6eecc

Browse files
committed
Fix summary json
1 parent c7f5719 commit 1e6eecc

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tools/flakeguard/cmd/report.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"path/filepath"
67
"strings"
@@ -114,6 +115,19 @@ var ReportCmd = &cobra.Command{
114115
s.Stop()
115116
fmt.Println("GitHub summary markdown generated successfully.")
116117

118+
// Generate all-tests-summary.json
119+
s = spinner.New(spinner.CharSets[11], 100*time.Millisecond)
120+
s.Suffix = " Generating all-tests-summary.json..."
121+
s.Start()
122+
123+
err = generateAllTestsSummaryJSON(aggregatedReport, filepath.Join(outputDir, "all-tests-summary.json"), reportMaxPassRatio)
124+
if err != nil {
125+
s.Stop()
126+
return fmt.Errorf("error generating all-tests-summary.json: %w", err)
127+
}
128+
s.Stop()
129+
fmt.Println("all-tests-summary.json generated successfully.")
130+
117131
if generatePRComment {
118132
// Retrieve required flags
119133
currentBranch, _ := cmd.Flags().GetString("current-branch")
@@ -235,6 +249,29 @@ func generatePRCommentMarkdown(report *reports.TestReport, outputPath, baseBranc
235249
return nil
236250
}
237251

252+
// New function to generate all-tests-summary.json
253+
func generateAllTestsSummaryJSON(report *reports.TestReport, outputPath string, maxPassRatio float64) error {
254+
summary := reports.GenerateSummaryData(report.Results, maxPassRatio)
255+
data, err := json.Marshal(summary)
256+
if err != nil {
257+
return fmt.Errorf("error marshaling summary data to JSON: %w", err)
258+
}
259+
260+
fs := reports.OSFileSystem{}
261+
jsonFile, err := fs.Create(outputPath)
262+
if err != nil {
263+
return fmt.Errorf("error creating all-tests-summary.json file: %w", err)
264+
}
265+
defer jsonFile.Close()
266+
267+
_, err = jsonFile.Write(data)
268+
if err != nil {
269+
return fmt.Errorf("error writing summary data to all-tests-summary.json: %w", err)
270+
}
271+
272+
return nil
273+
}
274+
238275
// Helper functions to retrieve original outputs and package outputs
239276
func getOriginalOutputs(reports []*reports.TestReport, testName, testPackage string) []string {
240277
for _, report := range reports {

0 commit comments

Comments
 (0)