Skip to content

Commit

Permalink
Fix summary json
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcl committed Dec 6, 2024
1 parent c7f5719 commit 1e6eecc
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tools/flakeguard/cmd/report.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"encoding/json"
"fmt"
"path/filepath"
"strings"
Expand Down Expand Up @@ -114,6 +115,19 @@ var ReportCmd = &cobra.Command{
s.Stop()
fmt.Println("GitHub summary markdown generated successfully.")

// Generate all-tests-summary.json
s = spinner.New(spinner.CharSets[11], 100*time.Millisecond)
s.Suffix = " Generating all-tests-summary.json..."
s.Start()

err = generateAllTestsSummaryJSON(aggregatedReport, filepath.Join(outputDir, "all-tests-summary.json"), reportMaxPassRatio)
if err != nil {
s.Stop()
return fmt.Errorf("error generating all-tests-summary.json: %w", err)
}
s.Stop()
fmt.Println("all-tests-summary.json generated successfully.")

if generatePRComment {
// Retrieve required flags
currentBranch, _ := cmd.Flags().GetString("current-branch")
Expand Down Expand Up @@ -235,6 +249,29 @@ func generatePRCommentMarkdown(report *reports.TestReport, outputPath, baseBranc
return nil
}

// New function to generate all-tests-summary.json
func generateAllTestsSummaryJSON(report *reports.TestReport, outputPath string, maxPassRatio float64) error {
summary := reports.GenerateSummaryData(report.Results, maxPassRatio)
data, err := json.Marshal(summary)
if err != nil {
return fmt.Errorf("error marshaling summary data to JSON: %w", err)
}

fs := reports.OSFileSystem{}
jsonFile, err := fs.Create(outputPath)
if err != nil {
return fmt.Errorf("error creating all-tests-summary.json file: %w", err)
}
defer jsonFile.Close()

_, err = jsonFile.Write(data)
if err != nil {
return fmt.Errorf("error writing summary data to all-tests-summary.json: %w", err)
}

return nil
}

// Helper functions to retrieve original outputs and package outputs
func getOriginalOutputs(reports []*reports.TestReport, testName, testPackage string) []string {
for _, report := range reports {
Expand Down

0 comments on commit 1e6eecc

Please sign in to comment.