pub mod container;
pub mod shell;
pub mod task;
pub use container::ContainerRunner;
pub use shell::ShellRunner;
pub use task::TaskRunner;
use crate::parser::models::{Step, StepResult};
use std::collections::HashMap;
use std::path::Path;
#[async_trait::async_trait]
pub trait Runner: Send + Sync {
async fn execute(
&self,
step: &Step,
env: &HashMap<String, String>,
working_dir: &Path,
) -> StepResult;
}
pub struct RunnerRegistry {
shell: ShellRunner,
task: Option<TaskRunner>,
container: Option<ContainerRunner>,
}
impl RunnerRegistry {
pub fn new() -> Self {
Self {
shell: ShellRunner::new(),
task: None,
container: None,
}
}
pub fn with_task_runner(mut self, cache_dir: impl AsRef<Path>) -> Self {
self.task = Some(TaskRunner::new(cache_dir.as_ref().to_path_buf()));
self
}
pub fn with_container_runner(mut self) -> Self {
self.container = Some(ContainerRunner::new());
self
}
pub fn shell(&self) -> &ShellRunner {
&self.shell
}
pub fn task(&self) -> Option<&TaskRunner> {
self.task.as_ref()
}
pub fn container(&self) -> Option<&ContainerRunner> {
self.container.as_ref()
}
}
impl Default for RunnerRegistry {
fn default() -> Self {
Self::new()
}
}