Skip to content

Commit

Permalink
Add head-sha, base-sha and github-workflow-name to flakeguard report
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcl committed Dec 11, 2024
1 parent 634ce9d commit 74be200
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
25 changes: 19 additions & 6 deletions tools/flakeguard/cmd/aggregate_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
15 changes: 9 additions & 6 deletions tools/flakeguard/reports/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 74be200

Please sign in to comment.