summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/action.rs42
-rw-r--r--src/plan.rs8
-rw-r--r--src/project.rs14
-rw-r--r--src/run.rs26
4 files changed, 34 insertions, 56 deletions
diff --git a/src/action.rs b/src/action.rs
index 98fc600..9fe9890 100644
--- a/src/action.rs
+++ b/src/action.rs
@@ -22,40 +22,17 @@ const RUST_ENVS: &[(&str, &str)] = &[
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "action")]
#[serde(rename_all = "snake_case")]
-pub enum PreAction {
+pub enum TrustedAction {
Dummy,
Pwd,
CargoFetch,
-}
-
-impl PreAction {
- pub fn names() -> &'static [&'static str] {
- &["dummy", "pwd", "cargo_fetch"]
- }
-
- pub fn execute(&self, project: &Project, state: &State) -> Result<(), ActionError> {
- debug!("Plan::execute: {:#?}", self);
- match self {
- Self::Dummy => dummy(),
- Self::Pwd => pwd(project),
- Self::CargoFetch => cargo_fetch(project, state),
- }
- }
-}
-
-#[derive(Debug, Clone, Serialize, Deserialize)]
-#[serde(tag = "action")]
-#[serde(rename_all = "snake_case")]
-pub enum PostAction {
- Dummy,
- Pwd,
Rsync,
Dput,
}
-impl PostAction {
+impl TrustedAction {
pub fn names() -> &'static [&'static str] {
- &["dummy", "pwd"]
+ &["dummy", "pwd", "cargo_fetch", "rsync", "dput"]
}
pub fn execute(
@@ -68,6 +45,7 @@ impl PostAction {
match self {
Self::Dummy => dummy(),
Self::Pwd => pwd(project),
+ Self::CargoFetch => cargo_fetch(project, state),
Self::Rsync => rsync(state, run),
Self::Dput => dput_action(state, run),
}
@@ -123,7 +101,7 @@ fn cargo_fetch(project: &Project, state: &State) -> Result<(), ActionError> {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "action")]
#[serde(rename_all = "snake_case")]
-pub enum Action {
+pub enum UnsafeAction {
Mkdir {
pathname: PathBuf,
},
@@ -149,7 +127,7 @@ pub enum Action {
Deb,
}
-impl Action {
+impl UnsafeAction {
pub fn names() -> &'static [&'static str] {
&[
"mkdir",
@@ -449,7 +427,7 @@ mod test {
fn mkdir_action() {
let tmp = tempdir().unwrap();
let path = tmp.path().join("testdir");
- let action = Action::mkdir(&path);
+ let action = UnsafeAction::mkdir(&path);
assert!(!path.exists());
assert!(action.execute().is_ok());
assert!(path.exists());
@@ -462,7 +440,7 @@ mod test {
let tar = tmp.path().join("src.tar");
std::fs::create_dir(&src).unwrap();
- let action = Action::tar_create(&tar, &src);
+ let action = UnsafeAction::tar_create(&tar, &src);
assert!(!tar.exists());
assert!(action.execute().is_ok());
@@ -478,9 +456,9 @@ mod test {
std::fs::create_dir(&src).unwrap();
std::fs::File::create(src.join("file.dat")).unwrap();
- Action::tar_create(&tar, &src).execute().unwrap();
+ UnsafeAction::tar_create(&tar, &src).execute().unwrap();
- let action = Action::tar_extract(&tar, &extracted);
+ let action = UnsafeAction::tar_extract(&tar, &extracted);
assert!(action.execute().is_ok());
assert!(extracted.join("file.dat").exists());
}
diff --git a/src/plan.rs b/src/plan.rs
index ff64b17..f289b20 100644
--- a/src/plan.rs
+++ b/src/plan.rs
@@ -2,11 +2,11 @@ use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};
-use crate::action::Action;
+use crate::action::UnsafeAction;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Plan {
- steps: Vec<Action>,
+ steps: Vec<UnsafeAction>,
}
impl Plan {
@@ -23,11 +23,11 @@ impl Plan {
Ok(())
}
- pub fn push(&mut self, action: Action) {
+ pub fn push(&mut self, action: UnsafeAction) {
self.steps.push(action);
}
- pub fn iter(&self) -> impl Iterator<Item = &Action> {
+ pub fn iter(&self) -> impl Iterator<Item = &UnsafeAction> {
self.steps.iter()
}
}
diff --git a/src/project.rs b/src/project.rs
index 959da5d..0ff2e34 100644
--- a/src/project.rs
+++ b/src/project.rs
@@ -8,7 +8,7 @@ use log::debug;
use serde::{Deserialize, Serialize};
use crate::{
- action::{Action, PostAction, PreAction},
+ action::{TrustedAction, UnsafeAction},
util::expand_tilde,
};
@@ -48,9 +48,9 @@ impl Projects {
pub struct Project {
source: PathBuf,
image: PathBuf,
- pre_plan: Option<Vec<PreAction>>,
- plan: Option<Vec<Action>>,
- post_plan: Option<Vec<PostAction>>,
+ pre_plan: Option<Vec<TrustedAction>>,
+ plan: Option<Vec<UnsafeAction>>,
+ post_plan: Option<Vec<TrustedAction>>,
artifact_max_size: Option<u64>,
cache_max_size: Option<u64>,
}
@@ -100,7 +100,7 @@ impl Project {
self.cache_max_size
}
- pub fn pre_plan(&self) -> &[PreAction] {
+ pub fn pre_plan(&self) -> &[TrustedAction] {
if let Some(plan) = &self.pre_plan {
plan.as_slice()
} else {
@@ -108,7 +108,7 @@ impl Project {
}
}
- pub fn plan(&self) -> &[Action] {
+ pub fn plan(&self) -> &[UnsafeAction] {
if let Some(plan) = &self.plan {
plan.as_slice()
} else {
@@ -116,7 +116,7 @@ impl Project {
}
}
- pub fn post_plan(&self) -> &[PostAction] {
+ pub fn post_plan(&self) -> &[TrustedAction] {
if let Some(plan) = &self.post_plan {
plan.as_slice()
} else {
diff --git a/src/run.rs b/src/run.rs
index 50e2c6d..e226983 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -8,7 +8,7 @@ use serde::Serialize;
use tempfile::tempdir_in;
use crate::{
- action::{Action, ActionError, PostAction, PreAction},
+ action::{ActionError, TrustedAction, UnsafeAction},
config::{Command, EffectiveConfig, ProjectsCommand, RunCommand},
git::{git_head, git_is_clean, is_git, GitError},
plan::{Plan, PlanError},
@@ -62,7 +62,7 @@ fn cmd_run(config: &EffectiveConfig, run: &RunCommand) -> Result<(), RunError> {
debug!("Executing pre-plan steps");
for action in project.pre_plan() {
- action.execute(project, &state)?;
+ action.execute(project, &state, run)?;
}
debug!("Executing CI run");
@@ -216,25 +216,25 @@ fn chosen<'a>(run: &'a RunCommand, projects: &'a Projects) -> Vec<(&'a str, &'a
}
fn prelude(plan: &mut Plan) {
- plan.push(Action::mkdir(Path::new(qemu::WORKSPACE_DIR)));
- plan.push(Action::mkdir(Path::new(qemu::ARTIFACTS_DIR)));
+ plan.push(UnsafeAction::mkdir(Path::new(qemu::WORKSPACE_DIR)));
+ plan.push(UnsafeAction::mkdir(Path::new(qemu::ARTIFACTS_DIR)));
- plan.push(Action::tar_extract(
+ plan.push(UnsafeAction::tar_extract(
Path::new(qemu::SOURCE_DRIVE),
Path::new(qemu::SOURCE_DIR),
));
- plan.push(Action::tar_extract(
+ plan.push(UnsafeAction::tar_extract(
Path::new(qemu::DEPS_DRIVE),
Path::new(qemu::DEPS_DIR),
));
- plan.push(Action::tar_extract(
+ plan.push(UnsafeAction::tar_extract(
Path::new(qemu::CACHE_DRIVE),
Path::new(qemu::CACHE_DIR),
));
- plan.push(Action::spawn(&[
+ plan.push(UnsafeAction::spawn(&[
"find",
"/workspace",
"-maxdepth",
@@ -244,11 +244,11 @@ fn prelude(plan: &mut Plan) {
}
fn epilog(plan: &mut Plan) {
- plan.push(Action::tar_create(
+ plan.push(UnsafeAction::tar_create(
Path::new(qemu::CACHE_DRIVE),
Path::new(qemu::CACHE_DIR),
));
- plan.push(Action::tar_create(
+ plan.push(UnsafeAction::tar_create(
Path::new(qemu::ARTIFACT_DRIVE),
Path::new(qemu::ARTIFACTS_DIR),
));
@@ -278,9 +278,9 @@ fn cmd_actions() {
}
let mut actions = Actions {
- pre_actions: PreAction::names().to_vec(),
- actions: Action::names().to_vec(),
- post_actions: PostAction::names().to_vec(),
+ pre_actions: TrustedAction::names().to_vec(),
+ actions: UnsafeAction::names().to_vec(),
+ post_actions: TrustedAction::names().to_vec(),
};
actions.pre_actions.sort();