pipeline_service/pipeline/
models.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use std::time::Duration;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Pipeline {
7    pub name: String,
8    #[serde(default)]
9    pub description: Option<String>,
10    #[serde(default)]
11    pub env: HashMap<String, String>,
12    pub steps: Vec<Step>,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct Step {
17    pub name: String,
18    #[serde(flatten)]
19    pub action: StepAction,
20    #[serde(default)]
21    pub env: HashMap<String, String>,
22    #[serde(default)]
23    pub continue_on_error: bool,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(rename_all = "lowercase")]
28pub enum StepAction {
29    Command(String),
30    Shell {
31        shell: Option<String>,
32        script: String,
33    },
34}
35
36#[derive(Debug, Clone)]
37pub struct StepResult {
38    pub step_name: String,
39    pub status: StepStatus,
40    pub output: String,
41    pub error: Option<String>,
42    pub duration: Duration,
43    pub exit_code: Option<i32>,
44}
45
46#[derive(Debug, Clone, PartialEq, Eq)]
47pub enum StepStatus {
48    Pending,
49    Running,
50    Success,
51    Failed,
52    Skipped,
53}
54
55#[derive(Debug, Clone)]
56pub struct ExecutionContext {
57    pub pipeline_name: String,
58    pub env: HashMap<String, String>,
59    pub working_dir: String,
60}
61
62impl ExecutionContext {
63    pub fn new(pipeline_name: String, working_dir: String) -> Self {
64        Self {
65            pipeline_name,
66            env: HashMap::new(),
67            working_dir,
68        }
69    }
70
71    pub fn with_env(mut self, env: HashMap<String, String>) -> Self {
72        self.env = env;
73        self
74    }
75}