Skip to content

Commit

Permalink
Add metadata to Flakeguard report (#1473)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcl authored Dec 11, 2024
1 parent 634ce9d commit d3bffaf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
30 changes: 24 additions & 6 deletions tools/flakeguard/cmd/aggregate_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ var AggregateResultsCmd = &cobra.Command{
maxPassRatio, _ := cmd.Flags().GetFloat64("max-pass-ratio")
codeOwnersPath, _ := cmd.Flags().GetString("codeowners-path")
repoPath, _ := cmd.Flags().GetString("repo-path")
repoURL, _ := cmd.Flags().GetString("repo-url")
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 {
Expand Down Expand Up @@ -51,6 +55,13 @@ var AggregateResultsCmd = &cobra.Command{

// Aggregate the reports
aggregatedReport, err := reports.Aggregate(testReports...)

// Add metadata to the aggregated report
aggregatedReport.HeadSHA = headSHA
aggregatedReport.BaseSHA = baseSHA
aggregatedReport.RepoURL = repoURL
aggregatedReport.GitHubWorkflowName = githubWorkflowName

if err != nil {
s.Stop()
return fmt.Errorf("error aggregating test reports: %w", err)
Expand Down Expand Up @@ -98,12 +109,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
Expand Down Expand Up @@ -171,6 +185,10 @@ 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("repo-url", "", "The repository URL")
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")
}
Expand Down
16 changes: 10 additions & 6 deletions tools/flakeguard/reports/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ import (
// Data Structures

type TestReport struct {
GoProject string
TestRunCount int
RaceDetection bool
ExcludedTests []string
SelectedTests []string
Results []TestResult
GoProject string
HeadSHA string
BaseSHA string
RepoURL string
GitHubWorkflowName string
TestRunCount int
RaceDetection bool
ExcludedTests []string
SelectedTests []string
Results []TestResult
}

type TestResult struct {
Expand Down

0 comments on commit d3bffaf

Please sign in to comment.