1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
mod builder;
mod job;
mod parser;

use crate::{ExecutionContext, WorkflowTriggerEvents};
use astro_run_shared::{Id, WorkflowEvent};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

pub type Step = astro_run_shared::Command;

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Workflow {
  pub id: Id,
  pub name: Option<String>,
  pub event: WorkflowEvent,
  pub on: Option<WorkflowTriggerEvents>,
  pub jobs: HashMap<String, job::Job>,
}

impl Workflow {
  pub async fn run(&self, ctx: ExecutionContext) -> astro_run_shared::Result<()> {
    for job in self.jobs.values() {
      job.run(ctx.clone()).await?;
    }

    Ok(())
  }

  pub fn builder() -> builder::WorkflowBuilder {
    builder::WorkflowBuilder::new()
  }
}