Skip to content

Commit

Permalink
internal: Rework action structures. (#1446)
Browse files Browse the repository at this point in the history
* Update cache.

* Create new crate.

* Migrate action.

* Move node over.

* Wrap in a box.

* Fix tests.

* Polish.

* Fix build.

* Fix tests.

* Fix version.
  • Loading branch information
milesj committed Apr 26, 2024
1 parent e5abf27 commit 4f28308
Show file tree
Hide file tree
Showing 28 changed files with 676 additions and 631 deletions.
23 changes: 15 additions & 8 deletions .yarn/versions/d3fb7bae.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
releases:
"@moonrepo/cli": minor
"@moonrepo/core-linux-arm64-gnu": minor
"@moonrepo/core-linux-arm64-musl": minor
"@moonrepo/core-linux-x64-gnu": minor
"@moonrepo/core-linux-x64-musl": minor
"@moonrepo/core-macos-arm64": minor
"@moonrepo/core-macos-x64": minor
"@moonrepo/core-windows-x64-msvc": minor
'@moonrepo/cli': minor
'@moonrepo/core-linux-arm64-gnu': minor
'@moonrepo/core-linux-arm64-musl': minor
'@moonrepo/core-linux-x64-gnu': minor
'@moonrepo/core-linux-x64-musl': minor
'@moonrepo/core-macos-arm64': minor
'@moonrepo/core-macos-x64': minor
'@moonrepo/core-windows-x64-msvc': minor
'@moonrepo/types': patch

declined:
- '@moonrepo/nx-compat'
- '@moonrepo/report'
- '@moonrepo/runtime'
- website
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/core/action-pipeline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
publish = false

[dependencies]
moon_action = { path = "../action" }
moon_action = { path = "../../../nextgen/action" }
moon_action_context = { path = "../../../nextgen/action-context" }
moon_action_graph = { path = "../../../nextgen/action-graph" }
moon_actions = { path = "../actions" }
Expand Down
10 changes: 5 additions & 5 deletions crates/core/action-pipeline/src/estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ impl Estimator {
}

match &*result.node {
ActionNode::SetupTool { .. }
| ActionNode::InstallDeps { .. }
| ActionNode::InstallProjectDeps { .. } => {
ActionNode::SetupTool(_)
| ActionNode::InstallDeps(_)
| ActionNode::InstallProjectDeps(_) => {
install_duration += task_duration;
}
ActionNode::RunTask { target, .. } => {
let task_id = target.task_id.to_string();
ActionNode::RunTask(inner) => {
let task_id = inner.target.task_id.to_string();

if let Some(task) = tasks.get_mut(&task_id) {
task.count += 1;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/action-pipeline/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl Pipeline {
console.out.print_checkpoint(
Checkpoint::RunFailed,
match &*result.node {
ActionNode::RunTask { target, .. } => target.as_str(),
ActionNode::RunTask(inner) => inner.target.as_str(),
_ => &result.label,
},
)?;
Expand Down
81 changes: 41 additions & 40 deletions crates/core/action-pipeline/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ pub async fn process_action(
let node = Arc::clone(&action.node);
let log_action_label = color::muted_light(&action.label);

trace!(
target: &action.log_target,
"Processing action {}",
log_action_label
);
trace!("Processing action {}", log_action_label);

emitter
.emit(Event::ActionStarted {
Expand All @@ -50,82 +46,87 @@ pub async fn process_action(
ActionNode::None => Ok(ActionStatus::Skipped),

// Setup and install the specific tool
ActionNode::SetupTool { runtime } => {
emitter.emit(Event::ToolInstalling { runtime }).await?;
ActionNode::SetupTool(inner) => {
emitter
.emit(Event::ToolInstalling {
runtime: &inner.runtime,
})
.await?;

let setup_result = setup_tool(&mut action, context, workspace, runtime).await;
let setup_result = setup_tool(&mut action, context, workspace, &inner.runtime).await;

emitter
.emit(Event::ToolInstalled {
error: extract_error(&setup_result),
runtime,
runtime: &inner.runtime,
})
.await?;

setup_result
}

// Install dependencies in the workspace root
ActionNode::InstallDeps { runtime } => {
ActionNode::InstallDeps(inner) => {
emitter
.emit(Event::DependenciesInstalling {
project: None,
runtime,
runtime: &inner.runtime,
})
.await?;

let install_result = install_deps(&mut action, context, workspace, runtime, None).await;
let install_result =
install_deps(&mut action, context, workspace, &inner.runtime, None).await;

emitter
.emit(Event::DependenciesInstalled {
error: extract_error(&install_result),
project: None,
runtime,
runtime: &inner.runtime,
})
.await?;

install_result
}

// Install dependencies in the project root
ActionNode::InstallProjectDeps {
runtime,
project: project_id,
} => {
let project = project_graph.get(project_id)?;
ActionNode::InstallProjectDeps(inner) => {
let project = project_graph.get(&inner.project)?;

emitter
.emit(Event::DependenciesInstalling {
project: Some(&project),
runtime,
runtime: &inner.runtime,
})
.await?;

let install_result =
install_deps(&mut action, context, workspace, runtime, Some(&project)).await;
let install_result = install_deps(
&mut action,
context,
workspace,
&inner.runtime,
Some(&project),
)
.await;

emitter
.emit(Event::DependenciesInstalled {
error: extract_error(&install_result),
project: Some(&project),
runtime,
runtime: &inner.runtime,
})
.await?;

install_result
}

// Sync a project within the graph
ActionNode::SyncProject {
runtime,
project: project_id,
} => {
let project = project_graph.get(project_id)?;
ActionNode::SyncProject(inner) => {
let project = project_graph.get(&inner.project)?;

emitter
.emit(Event::ProjectSyncing {
project: &project,
runtime,
runtime: &inner.runtime,
})
.await?;

Expand All @@ -135,15 +136,15 @@ pub async fn process_action(
workspace,
project_graph,
&project,
runtime,
&inner.runtime,
)
.await;

emitter
.emit(Event::ProjectSynced {
error: extract_error(&sync_result),
project: &project,
runtime,
runtime: &inner.runtime,
})
.await?;

Expand All @@ -166,12 +167,14 @@ pub async fn process_action(
}

// Run a task within a project
ActionNode::RunTask {
runtime, target, ..
} => {
let project = project_graph.get(target.get_project_id().unwrap())?;
ActionNode::RunTask(inner) => {
let project = project_graph.get(inner.target.get_project_id().unwrap())?;

emitter.emit(Event::TargetRunning { target }).await?;
emitter
.emit(Event::TargetRunning {
target: &inner.target,
})
.await?;

let run_result = run_task(
&mut action,
Expand All @@ -180,15 +183,15 @@ pub async fn process_action(
workspace,
console,
&project,
target,
runtime,
&inner.target,
&inner.runtime,
)
.await;

emitter
.emit(Event::TargetRan {
error: extract_error(&run_result),
target,
target: &inner.target,
})
.await?;

Expand Down Expand Up @@ -227,14 +230,12 @@ pub async fn process_action(

if action.has_failed() {
trace!(
target: &action.log_target,
"Failed to process action {} in {:?}",
log_action_label,
action.duration.unwrap()
);
} else {
trace!(
target: &action.log_target,
"Processed action {} in {:?}",
log_action_label,
action.duration.unwrap()
Expand Down
14 changes: 5 additions & 9 deletions crates/core/action-pipeline/src/subscribers/moonbase.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ci_env::get_environment;
use moon_action::{ActionNode, ActionStatus};
use moon_action::{ActionNode, ActionStatus, RunTaskNode};
use moon_api::{
endpoints::ArtifactWriteInput,
graphql::{
Expand Down Expand Up @@ -461,14 +461,10 @@ impl Subscriber for MoonbaseSubscriber {
let archive_path = archive_path.to_owned();

// Create a fake action label so that we can check the CI cache
let action_label = ActionNode::RunTask {
args: vec![],
env: vec![],
interactive: false,
persistent: false,
runtime: Runtime::system(),
target: (*target).to_owned(),
}
let action_label = ActionNode::run_task(RunTaskNode::new(
(*target).to_owned(),
Runtime::system(),
))
.label();
let job_id = self.job_ids.get(&action_label).cloned();

Expand Down
36 changes: 16 additions & 20 deletions crates/core/action-pipeline/tests/estimator_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use moon_action::{Action, ActionNode, ActionStatus};
use moon_action::*;
use moon_action_pipeline::estimator::{Estimator, TaskEstimate};
use moon_platform::Runtime;
use rustc_hash::FxHashMap;
Expand All @@ -9,14 +9,10 @@ const NANOS_PER_MILLI: u32 = 1_000_000;
const HALF_SECOND: u32 = NANOS_PER_MILLI * 500;

fn create_run_task_action(runtime: Runtime, target: &str) -> Arc<ActionNode> {
Arc::new(ActionNode::RunTask {
args: vec![],
env: vec![],
interactive: false,
persistent: false,
Arc::new(ActionNode::run_task(RunTaskNode::new(
target.into(),
runtime,
target: target.into(),
})
)))
}

mod estimator {
Expand Down Expand Up @@ -125,16 +121,16 @@ mod estimator {
&[
Action {
duration: Some(Duration::new(10, 0)),
node: Arc::new(ActionNode::SetupTool {
node: Arc::new(ActionNode::setup_tool(SetupToolNode {
runtime: Runtime::system(),
}),
})),
..Action::default()
},
Action {
duration: Some(Duration::new(25, 0)),
node: Arc::new(ActionNode::InstallDeps {
node: Arc::new(ActionNode::install_deps(InstallDepsNode {
runtime: Runtime::system(),
}),
})),
..Action::default()
},
Action {
Expand Down Expand Up @@ -197,16 +193,16 @@ mod estimator {
&[
Action {
duration: Some(Duration::new(10, 0)),
node: Arc::new(ActionNode::SetupTool {
node: Arc::new(ActionNode::setup_tool(SetupToolNode {
runtime: Runtime::system(),
}),
})),
..Action::default()
},
Action {
duration: Some(Duration::new(25, 0)),
node: Arc::new(ActionNode::InstallDeps {
node: Arc::new(ActionNode::install_deps(InstallDepsNode {
runtime: Runtime::system(),
}),
})),
..Action::default()
},
Action {
Expand Down Expand Up @@ -270,16 +266,16 @@ mod estimator {
&[
Action {
duration: Some(Duration::new(10, 0)),
node: Arc::new(ActionNode::SetupTool {
node: Arc::new(ActionNode::setup_tool(SetupToolNode {
runtime: Runtime::system(),
}),
})),
..Action::default()
},
Action {
duration: Some(Duration::new(25, 0)),
node: Arc::new(ActionNode::InstallDeps {
node: Arc::new(ActionNode::install_deps(InstallDepsNode {
runtime: Runtime::system(),
}),
})),
..Action::default()
},
Action {
Expand Down
Loading

0 comments on commit 4f28308

Please sign in to comment.