Skip to main content

dk_runner/workflow/
types.rs

1use serde::Deserialize;
2use std::time::Duration;
3
4// --- TOML deserialization types ---
5
6#[derive(Debug, Clone, Deserialize)]
7#[serde(deny_unknown_fields)]
8pub struct WorkflowFile {
9    pub pipeline: PipelineConfig,
10    #[serde(default)]
11    pub stage: Vec<StageConfig>,
12}
13
14#[derive(Debug, Clone, Deserialize)]
15#[serde(deny_unknown_fields)]
16pub struct PipelineConfig {
17    pub name: String,
18    #[serde(default = "default_timeout")]
19    pub timeout: String,
20}
21
22fn default_timeout() -> String {
23    "10m".to_string()
24}
25
26#[derive(Debug, Clone, Deserialize)]
27#[serde(deny_unknown_fields)]
28pub struct StageConfig {
29    pub name: String,
30    #[serde(default)]
31    pub parallel: bool,
32    #[serde(default)]
33    pub step: Vec<StepConfig>,
34}
35
36#[derive(Debug, Clone, Deserialize)]
37#[serde(deny_unknown_fields)]
38pub struct StepConfig {
39    pub name: String,
40    #[serde(default)]
41    pub run: Option<String>,
42    #[serde(default, rename = "type")]
43    pub step_type: Option<String>,
44    #[serde(default)]
45    pub timeout: Option<String>,
46    #[serde(default)]
47    pub changeset_aware: bool,
48    #[serde(default = "default_required")]
49    pub required: bool,
50    #[serde(default)]
51    pub check: Vec<String>,
52    #[serde(default)]
53    pub prompt: Option<String>,
54}
55
56fn default_required() -> bool {
57    true
58}
59
60// --- YAML deserialization types ---
61
62#[derive(Debug, Clone, Deserialize)]
63#[serde(deny_unknown_fields)]
64pub struct YamlWorkflowFile {
65    pub pipeline: YamlPipelineConfig,
66    #[serde(default)]
67    pub stages: Vec<YamlStageConfig>,
68}
69
70#[derive(Debug, Clone, Deserialize)]
71#[serde(deny_unknown_fields)]
72pub struct YamlPipelineConfig {
73    pub name: String,
74    #[serde(default = "default_timeout")]
75    pub timeout: String,
76    #[serde(default)]
77    pub allowed_commands: Vec<String>,
78}
79
80#[derive(Debug, Clone, Deserialize)]
81#[serde(deny_unknown_fields)]
82pub struct YamlStageConfig {
83    pub name: String,
84    #[serde(default)]
85    pub parallel: bool,
86    #[serde(default)]
87    pub steps: Vec<YamlStepConfig>,
88}
89
90#[derive(Debug, Clone, Deserialize)]
91#[serde(deny_unknown_fields)]
92pub struct YamlStepConfig {
93    pub name: String,
94    #[serde(default)]
95    pub run: Option<String>,
96    #[serde(default, rename = "type")]
97    pub step_type: Option<String>,
98    #[serde(default)]
99    pub timeout: Option<String>,
100    #[serde(default)]
101    pub changeset_aware: bool,
102    #[serde(default = "default_required")]
103    pub required: bool,
104    #[serde(default)]
105    pub check: Vec<String>,
106    #[serde(default)]
107    pub prompt: Option<String>,
108}
109
110// --- Resolved types (post-parsing) ---
111
112#[derive(Debug, Clone)]
113pub struct Workflow {
114    pub name: String,
115    pub timeout: Duration,
116    pub stages: Vec<Stage>,
117    /// Per-repo command allowlist. Empty means "use default allowlist".
118    pub allowed_commands: Vec<String>,
119}
120
121#[derive(Debug, Clone)]
122pub struct Stage {
123    pub name: String,
124    pub parallel: bool,
125    pub steps: Vec<Step>,
126}
127
128#[derive(Debug, Clone)]
129pub struct Step {
130    pub name: String,
131    pub step_type: StepType,
132    pub timeout: Duration,
133    pub required: bool,
134    pub changeset_aware: bool,
135}
136
137#[derive(Debug, Clone)]
138pub enum StepType {
139    Command { run: String },
140    Semantic { checks: Vec<String> },
141    AgentReview { prompt: String },
142    HumanApprove,
143}