cbtop/regression_pipeline/
types.rs1pub type PipelineResult<T> = Result<T, PipelineError>;
5
6#[derive(Debug, Clone, PartialEq)]
8pub enum PipelineError {
9 GitError { reason: String },
11 BenchmarkFailed { reason: String },
13 BaselineNotFound { commit: String },
15 InvalidConfig { reason: String },
17 Timeout { timeout_sec: u64 },
19 StatusUpdateFailed { reason: String },
21 ArtifactError { reason: String },
23}
24
25impl std::fmt::Display for PipelineError {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 Self::GitError { reason } => write!(f, "Git error: {}", reason),
29 Self::BenchmarkFailed { reason } => write!(f, "Benchmark failed: {}", reason),
30 Self::BaselineNotFound { commit } => write!(f, "Baseline not found for {}", commit),
31 Self::InvalidConfig { reason } => write!(f, "Invalid config: {}", reason),
32 Self::Timeout { timeout_sec } => write!(f, "Timeout after {}s", timeout_sec),
33 Self::StatusUpdateFailed { reason } => write!(f, "Status update failed: {}", reason),
34 Self::ArtifactError { reason } => write!(f, "Artifact error: {}", reason),
35 }
36 }
37}
38
39impl std::error::Error for PipelineError {}
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43pub enum PipelineStatus {
44 Pending,
46 Running,
48 Passed,
50 Warning,
52 Failed,
54 Cancelled,
56 Error,
58}
59
60impl PipelineStatus {
61 pub fn is_terminal(&self) -> bool {
63 matches!(
64 self,
65 Self::Passed | Self::Warning | Self::Failed | Self::Cancelled | Self::Error
66 )
67 }
68
69 pub fn github_state(&self) -> &'static str {
71 match self {
72 Self::Pending => "pending",
73 Self::Running => "pending",
74 Self::Passed => "success",
75 Self::Warning => "success",
76 Self::Failed => "failure",
77 Self::Cancelled => "error",
78 Self::Error => "error",
79 }
80 }
81}
82
83#[derive(Debug, Clone)]
85pub enum GitRef {
86 Branch(String),
88 Commit(String),
90 Tag(String),
92 PullRequest(u64),
94}
95
96impl GitRef {
97 pub fn as_ref_str(&self) -> String {
99 match self {
100 Self::Branch(name) => name.clone(),
101 Self::Commit(sha) => sha.clone(),
102 Self::Tag(name) => format!("refs/tags/{}", name),
103 Self::PullRequest(num) => format!("refs/pull/{}/head", num),
104 }
105 }
106}
107
108#[derive(Debug, Clone)]
110pub struct PipelineConfig {
111 pub base_branch: String,
113 pub benchmark_command: String,
115 pub work_dir: String,
117 pub timeout_sec: u64,
119 pub regression_threshold_percent: f64,
121 pub warning_threshold_percent: f64,
123 pub github_token: Option<String>,
125 pub repository: Option<String>,
127 pub artifact_path: String,
129 pub iterations: u32,
131 pub warmup_iterations: u32,
133}
134
135impl Default for PipelineConfig {
136 fn default() -> Self {
137 Self {
138 base_branch: "main".to_string(),
139 benchmark_command: "cargo bench --no-fail-fast".to_string(),
140 work_dir: ".".to_string(),
141 timeout_sec: 600,
142 regression_threshold_percent: 5.0,
143 warning_threshold_percent: 2.0,
144 github_token: None,
145 repository: None,
146 artifact_path: "./benchmark-artifacts".to_string(),
147 iterations: 10,
148 warmup_iterations: 3,
149 }
150 }
151}
152
153#[derive(Debug, Clone)]
155pub struct StatusCheck {
156 pub name: String,
158 pub state: PipelineStatus,
160 pub description: String,
162 pub target_url: Option<String>,
164 pub context: String,
166}