astro_run/workflow/
step.rs

1use crate::{Command, Condition, ContainerOptions, EnvironmentVariables, ExecutionContext, StepId};
2use serde::{Deserialize, Serialize};
3use std::time::Duration;
4
5#[derive(Serialize, Deserialize, Debug, Clone, Default)]
6pub struct Step {
7  pub id: StepId,
8  pub name: Option<String>,
9  pub on: Option<Condition>,
10  pub container: Option<ContainerOptions>,
11  pub run: String,
12  pub continue_on_error: bool,
13  pub environments: EnvironmentVariables,
14  pub secrets: Vec<String>,
15  pub timeout: Duration,
16}
17
18impl Step {
19  pub async fn should_skip(&self, ctx: &ExecutionContext) -> bool {
20    if let Some(on) = &self.on {
21      !ctx.is_match(on).await
22    } else {
23      false
24    }
25  }
26}
27
28impl From<Step> for Command {
29  fn from(step: Step) -> Command {
30    Command {
31      id: step.id,
32      name: step.name,
33      container: step.container,
34      run: step.run,
35      continue_on_error: step.continue_on_error,
36      environments: step.environments,
37      secrets: step.secrets,
38      timeout: step.timeout,
39    }
40  }
41}
42
43impl From<Command> for Step {
44  fn from(command: Command) -> Step {
45    Step {
46      id: command.id,
47      name: command.name,
48      container: command.container,
49      run: command.run,
50      continue_on_error: command.continue_on_error,
51      environments: command.environments,
52      secrets: command.secrets,
53      timeout: command.timeout,
54      on: None,
55    }
56  }
57}