From 74be200ab03c719dfd5b3996c56dc32a812dd37f Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Wed, 11 Dec 2024 15:56:24 +0100 Subject: [PATCH] Add head-sha, base-sha and github-workflow-name to flakeguard report --- tools/flakeguard/cmd/aggregate_results.go | 25 +++++++++++++++++------ tools/flakeguard/reports/data.go | 15 ++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/tools/flakeguard/cmd/aggregate_results.go b/tools/flakeguard/cmd/aggregate_results.go index ad6a98b4b..d692f7519 100644 --- a/tools/flakeguard/cmd/aggregate_results.go +++ b/tools/flakeguard/cmd/aggregate_results.go @@ -24,6 +24,9 @@ var AggregateResultsCmd = &cobra.Command{ maxPassRatio, _ := cmd.Flags().GetFloat64("max-pass-ratio") codeOwnersPath, _ := cmd.Flags().GetString("codeowners-path") repoPath, _ := cmd.Flags().GetString("repo-path") + headSHA, _ := cmd.Flags().GetString("head-sha") + baseSHA, _ := cmd.Flags().GetString("base-sha") + githubWorkflowName, _ := cmd.Flags().GetString("github-workflow-name") // Ensure the output directory exists if err := fs.MkdirAll(outputDir, 0755); err != nil { @@ -51,6 +54,10 @@ var AggregateResultsCmd = &cobra.Command{ // Aggregate the reports aggregatedReport, err := reports.Aggregate(testReports...) + aggregatedReport.HeadSHA = headSHA + aggregatedReport.BaseSHA = baseSHA + aggregatedReport.GitHubWorkflowName = githubWorkflowName + if err != nil { s.Stop() return fmt.Errorf("error aggregating test reports: %w", err) @@ -98,12 +105,15 @@ var AggregateResultsCmd = &cobra.Command{ // Create a new report for failed tests with logs failedReportWithLogs := &reports.TestReport{ - GoProject: aggregatedReport.GoProject, - TestRunCount: aggregatedReport.TestRunCount, - RaceDetection: aggregatedReport.RaceDetection, - ExcludedTests: aggregatedReport.ExcludedTests, - SelectedTests: aggregatedReport.SelectedTests, - Results: failedTests, + GoProject: aggregatedReport.GoProject, + TestRunCount: aggregatedReport.TestRunCount, + RaceDetection: aggregatedReport.RaceDetection, + ExcludedTests: aggregatedReport.ExcludedTests, + SelectedTests: aggregatedReport.SelectedTests, + HeadSHA: aggregatedReport.HeadSHA, + BaseSHA: aggregatedReport.BaseSHA, + GitHubWorkflowName: aggregatedReport.GitHubWorkflowName, + Results: failedTests, } // Save the failed tests report with logs @@ -171,6 +181,9 @@ func init() { AggregateResultsCmd.Flags().Float64P("max-pass-ratio", "", 1.0, "The maximum pass ratio threshold for a test to be considered flaky") AggregateResultsCmd.Flags().StringP("codeowners-path", "", "", "Path to the CODEOWNERS file") AggregateResultsCmd.Flags().StringP("repo-path", "", ".", "The path to the root of the repository/project") + AggregateResultsCmd.Flags().String("head-sha", "", "Head commit SHA for the test report") + AggregateResultsCmd.Flags().String("base-sha", "", "Base commit SHA for the test report") + AggregateResultsCmd.Flags().String("github-workflow-name", "", "GitHub workflow name for the test report") AggregateResultsCmd.MarkFlagRequired("results-path") } diff --git a/tools/flakeguard/reports/data.go b/tools/flakeguard/reports/data.go index b58caf9f7..f3005e667 100644 --- a/tools/flakeguard/reports/data.go +++ b/tools/flakeguard/reports/data.go @@ -11,12 +11,15 @@ import ( // Data Structures type TestReport struct { - GoProject string - TestRunCount int - RaceDetection bool - ExcludedTests []string - SelectedTests []string - Results []TestResult + GoProject string + TestRunCount int + RaceDetection bool + ExcludedTests []string + SelectedTests []string + Results []TestResult + HeadSHA string + BaseSHA string + GitHubWorkflowName string } type TestResult struct {