(ctx context.Context, currentRun ProcessedRun, currentSnapshot auditComparisonSnapshot, outputDir string, owner, repo, hostname string, verbose bool)
| 523 | } |
| 524 | |
| 525 | func buildAuditComparisonForRun(ctx context.Context, currentRun ProcessedRun, currentSnapshot auditComparisonSnapshot, outputDir string, owner, repo, hostname string, verbose bool) *AuditComparisonData { |
| 526 | baselineRuns, err := findPreviousSuccessfulWorkflowRuns(ctx, currentRun.Run, owner, repo, hostname) |
| 527 | if err != nil { |
| 528 | auditLog.Printf("Skipping audit comparison: failed to find baseline: %v", err) |
| 529 | return &AuditComparisonData{BaselineFound: false} |
| 530 | } |
| 531 | if len(baselineRuns) == 0 { |
| 532 | return &AuditComparisonData{BaselineFound: false} |
| 533 | } |
| 534 | |
| 535 | candidates := make([]auditComparisonCandidate, 0, len(baselineRuns)) |
| 536 | for _, baselineRun := range baselineRuns { |
| 537 | baselineOutputDir := filepath.Join(outputDir, fmt.Sprintf("baseline-%d", baselineRun.DatabaseID)) |
| 538 | if _, err := os.Stat(baselineOutputDir); err != nil { |
| 539 | if downloadErr := downloadRunArtifacts(ctx, baselineRun.DatabaseID, baselineOutputDir, verbose, owner, repo, hostname, nil); downloadErr != nil { |
| 540 | auditLog.Printf("Skipping candidate baseline for run %d: failed to download baseline artifacts: %v", baselineRun.DatabaseID, downloadErr) |
| 541 | continue |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | candidate, candidateErr := loadAuditComparisonCandidate(baselineRun, baselineOutputDir, verbose) |
| 546 | if candidateErr != nil { |
| 547 | auditLog.Printf("Skipping candidate baseline for run %d: failed to load baseline snapshot: %v", baselineRun.DatabaseID, candidateErr) |
| 548 | continue |
| 549 | } |
| 550 | candidates = append(candidates, candidate) |
| 551 | } |
| 552 | |
| 553 | selected := selectAuditComparisonBaseline(currentRun, candidates) |
| 554 | if selected == nil { |
| 555 | return &AuditComparisonData{BaselineFound: false} |
| 556 | } |
| 557 | |
| 558 | comparison := buildAuditComparison(currentSnapshot, &selected.Run, &selected.Snapshot) |
| 559 | if comparison != nil && comparison.Baseline != nil { |
| 560 | comparison.Baseline.Selection = selected.Selection |
| 561 | comparison.Baseline.MatchedOn = selected.MatchedOn |
| 562 | } |
| 563 | return comparison |
| 564 | } |
no test coverage detected