Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metadata to Flakeguard report #1473

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading