From 9bc5858febf1a29736f07ea8267987ec95de1fc8 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Sun, 8 Oct 2023 00:02:29 -0700 Subject: [PATCH 1/3] Start on. --- .../src/actions/install_deps.rs | 10 +++ .../core/action-pipeline/src/actions/mod.rs | 68 +++++++++++++++++++ .../action-pipeline/src/actions/setup_tool.rs | 13 ++++ .../src/actions/sync_project.rs | 10 +++ .../src/actions/sync_workspace.rs | 10 +++ 5 files changed, 111 insertions(+) diff --git a/crates/core/action-pipeline/src/actions/install_deps.rs b/crates/core/action-pipeline/src/actions/install_deps.rs index c0b7eca3d15..117bedabaf8 100644 --- a/crates/core/action-pipeline/src/actions/install_deps.rs +++ b/crates/core/action-pipeline/src/actions/install_deps.rs @@ -1,3 +1,4 @@ +use super::should_skip_action_matching; use miette::IntoDiagnostic; use moon_action::{Action, ActionStatus}; use moon_action_context::ActionContext; @@ -63,6 +64,15 @@ pub async fn install_deps( return Ok(ActionStatus::Skipped); } + if should_skip_action_matching("MOON_SKIP_INSTALL_DEPS", &install_key) { + debug!( + target: LOG_TARGET, + "Skipping install deps action because MOON_SKIP_INSTALL_DEPS is set", + ); + + return Ok(ActionStatus::Skipped); + } + // When the install is happening as a child process of another install, avoid recursion if env::var("MOON_INSTALLING_DEPS").unwrap_or_default() == install_key { debug!( diff --git a/crates/core/action-pipeline/src/actions/mod.rs b/crates/core/action-pipeline/src/actions/mod.rs index d2b07d67dd5..02145e2250c 100644 --- a/crates/core/action-pipeline/src/actions/mod.rs +++ b/crates/core/action-pipeline/src/actions/mod.rs @@ -1,5 +1,73 @@ +use std::env; + pub mod install_deps; pub mod run_target; pub mod setup_tool; pub mod sync_project; pub mod sync_workspace; + +pub fn should_skip_action(key: &str) -> bool { + env::var(key).is_ok_and(|v| matches_pattern(&v, "")) +} + +pub fn should_skip_action_matching>(key: &str, pattern: V) -> bool { + env::var(key).is_ok_and(|v| matches_pattern(&v, pattern.as_ref())) +} + +fn matches_pattern(value: &str, pattern: &str) -> bool { + if value.contains(',') { + return value.split(',').any(|v| matches_pattern(v, pattern)); + } + + let pattern = pattern.to_lowercase(); + + if value == "*" || value == "*:*" || value == "true" || value == pattern { + return true; + } + + if pattern.contains(':') { + let mut left = pattern.split(':'); + let mut right = value.split(':'); + + return match ((left.next(), left.next()), (right.next(), right.next())) { + ((Some(a1), Some(a2)), (Some(b1), Some(b2))) => { + // foo:bar == foo:bar + a1 == b1 && a2 == b2 || + // foo:bar == foo:* + a1 == b1 && b2 == "*" || + // foo:bar == *:bar + a2 == b2 && b1 == "*" + } + ((Some(a1), Some(_)), (Some(b1), None)) => { + // foo:bar == foo + a1 == b1 + } + _ => false, + }; + } + + false +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn patterns() { + assert!(matches_pattern("*", "")); + assert!(matches_pattern("*:*", "")); + assert!(matches_pattern("true", "")); + + assert!(matches_pattern("*", "node:20.0.0")); + assert!(matches_pattern("node:*", "node:20.0.0")); + assert!(matches_pattern("node", "node:20.0.0")); + assert!(matches_pattern("node:20.0.0", "node:20.0.0")); + assert!(!matches_pattern("rust", "node:20.0.0")); + assert!(!matches_pattern("node:19.0.0", "node:20.0.0")); + + assert!(matches_pattern("foo", "foo,bar")); + assert!(matches_pattern("bar", "foo,bar")); + assert!(!matches_pattern("baz", "foo,bar")); + } +} diff --git a/crates/core/action-pipeline/src/actions/setup_tool.rs b/crates/core/action-pipeline/src/actions/setup_tool.rs index f2b4582f9b0..f2332fe8a68 100644 --- a/crates/core/action-pipeline/src/actions/setup_tool.rs +++ b/crates/core/action-pipeline/src/actions/setup_tool.rs @@ -1,3 +1,4 @@ +use super::should_skip_action_matching; use moon_action::{Action, ActionStatus}; use moon_action_context::ActionContext; use moon_cache_item::cache_item; @@ -38,6 +39,18 @@ pub async fn setup_tool( runtime.label() ); + if should_skip_action_matching( + "MOON_SKIP_SETUP_TOOL", + format!("{}:{}", runtime, runtime.requirement), + ) { + debug!( + target: LOG_TARGET, + "Skipping setup tool action because MOON_SKIP_SETUP_TOOL is set", + ); + + return Ok(ActionStatus::Skipped); + } + let workspace = workspace.write().await; let context = context.read().await; diff --git a/crates/core/action-pipeline/src/actions/sync_project.rs b/crates/core/action-pipeline/src/actions/sync_project.rs index 9f02277f7b7..ae55242425d 100644 --- a/crates/core/action-pipeline/src/actions/sync_project.rs +++ b/crates/core/action-pipeline/src/actions/sync_project.rs @@ -1,3 +1,4 @@ +use super::should_skip_action_matching; use moon_action::{Action, ActionStatus}; use moon_action_context::ActionContext; use moon_logger::debug; @@ -34,6 +35,15 @@ pub async fn sync_project( color::id(&project.id) ); + if should_skip_action_matching("MOON_SKIP_SYNC_PROJECT", &project.id) { + debug!( + target: LOG_TARGET, + "Skipping sync project action because MOON_SKIP_SYNC_PROJECT is set", + ); + + return Ok(ActionStatus::Skipped); + } + // Create a snapshot for tasks to reference workspace .cache_engine diff --git a/crates/core/action-pipeline/src/actions/sync_workspace.rs b/crates/core/action-pipeline/src/actions/sync_workspace.rs index fef41499c47..6c1b17a7e0b 100644 --- a/crates/core/action-pipeline/src/actions/sync_workspace.rs +++ b/crates/core/action-pipeline/src/actions/sync_workspace.rs @@ -1,3 +1,4 @@ +use super::should_skip_action; use moon_action::{Action, ActionStatus}; use moon_action_context::ActionContext; use moon_actions::{sync_codeowners, sync_vcs_hooks}; @@ -28,6 +29,15 @@ pub async fn sync_workspace( debug!(target: LOG_TARGET, "Syncing workspace"); + if should_skip_action("MOON_SKIP_SYNC_WORKSPACE") { + debug!( + target: LOG_TARGET, + "Skipping sync workspace action because MOON_SKIP_SYNC_WORKSPACE is set", + ); + + return Ok(ActionStatus::Skipped); + } + if workspace.config.codeowners.sync_on_run { debug!( target: LOG_TARGET, From e161f20ae62c43d55bf849d1197bb0f117172773 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Sun, 8 Oct 2023 00:39:11 -0700 Subject: [PATCH 2/3] Update tests. --- .../run_node_test__inherits_moon_env_vars.snap | 2 +- .../run_rust_test__inherits_moon_env_vars.snap | 2 +- ...stem_test__unix__inherits_moon_env_vars.snap | 2 +- crates/core/action-pipeline/src/actions/mod.rs | 17 +++++++++-------- .../src/actions/{run_target.rs => run_task.rs} | 8 ++++---- crates/core/action-pipeline/src/processor.rs | 4 ++-- crates/node/platform/src/actions/run_target.rs | 2 +- website/src/utils/renderGraph.ts | 7 +++++++ 8 files changed, 26 insertions(+), 18 deletions(-) rename crates/core/action-pipeline/src/actions/{run_target.rs => run_task.rs} (96%) diff --git a/crates/cli/tests/snapshots/run_node_test__inherits_moon_env_vars.snap b/crates/cli/tests/snapshots/run_node_test__inherits_moon_env_vars.snap index d0f06aad674..ffc9bdd73a3 100644 --- a/crates/cli/tests/snapshots/run_node_test__inherits_moon_env_vars.snap +++ b/crates/cli/tests/snapshots/run_node_test__inherits_moon_env_vars.snap @@ -12,7 +12,7 @@ MOON_PROJECT_ID=node MOON_PROJECT_ROOT=/base MOON_PROJECT_SNAPSHOT=/.moon/cache/states/node/snapshot.json MOON_PROJECT_SOURCE=base -MOON_RUNNING_ACTION=run-target +MOON_RUNNING_ACTION=run-task MOON_TARGET=node:envVarsMoon MOON_TOOLCHAIN_DIR=~/.proto MOON_WORKING_DIR= diff --git a/crates/cli/tests/snapshots/run_rust_test__inherits_moon_env_vars.snap b/crates/cli/tests/snapshots/run_rust_test__inherits_moon_env_vars.snap index 357a9e1044c..4cdfd4a9bd7 100644 --- a/crates/cli/tests/snapshots/run_rust_test__inherits_moon_env_vars.snap +++ b/crates/cli/tests/snapshots/run_rust_test__inherits_moon_env_vars.snap @@ -12,7 +12,7 @@ MOON_PROJECT_ID=rust MOON_PROJECT_ROOT= MOON_PROJECT_SNAPSHOT=/.moon/cache/states/rust/snapshot.json MOON_PROJECT_SOURCE=. -MOON_RUNNING_ACTION=run-target +MOON_RUNNING_ACTION=run-task MOON_TARGET=rust:envVarsMoon MOON_TOOLCHAIN_DIR=~/.proto MOON_WORKING_DIR= diff --git a/crates/cli/tests/snapshots/run_system_test__unix__inherits_moon_env_vars.snap b/crates/cli/tests/snapshots/run_system_test__unix__inherits_moon_env_vars.snap index a7b53256da3..e207b53c5ba 100644 --- a/crates/cli/tests/snapshots/run_system_test__unix__inherits_moon_env_vars.snap +++ b/crates/cli/tests/snapshots/run_system_test__unix__inherits_moon_env_vars.snap @@ -11,7 +11,7 @@ MOON_PROJECT_ID=unix MOON_PROJECT_ROOT=/unix MOON_PROJECT_SNAPSHOT=/.moon/cache/states/unix/snapshot.json MOON_PROJECT_SOURCE=unix -MOON_RUNNING_ACTION=run-target +MOON_RUNNING_ACTION=run-task MOON_TARGET=unix:envVarsMoon MOON_TOOLCHAIN_DIR=~/.proto MOON_WORKING_DIR= diff --git a/crates/core/action-pipeline/src/actions/mod.rs b/crates/core/action-pipeline/src/actions/mod.rs index 02145e2250c..b05f60452e2 100644 --- a/crates/core/action-pipeline/src/actions/mod.rs +++ b/crates/core/action-pipeline/src/actions/mod.rs @@ -1,7 +1,7 @@ use std::env; pub mod install_deps; -pub mod run_target; +pub mod run_task; pub mod setup_tool; pub mod sync_project; pub mod sync_workspace; @@ -30,13 +30,14 @@ fn matches_pattern(value: &str, pattern: &str) -> bool { let mut right = value.split(':'); return match ((left.next(), left.next()), (right.next(), right.next())) { + #[allow(clippy::nonminimal_bool)] ((Some(a1), Some(a2)), (Some(b1), Some(b2))) => { // foo:bar == foo:bar a1 == b1 && a2 == b2 || - // foo:bar == foo:* - a1 == b1 && b2 == "*" || - // foo:bar == *:bar - a2 == b2 && b1 == "*" + // foo:bar == foo:* + a1 == b1 && b2 == "*" || + // foo:bar == *:bar + a2 == b2 && b1 == "*" } ((Some(a1), Some(_)), (Some(b1), None)) => { // foo:bar == foo @@ -66,8 +67,8 @@ mod tests { assert!(!matches_pattern("rust", "node:20.0.0")); assert!(!matches_pattern("node:19.0.0", "node:20.0.0")); - assert!(matches_pattern("foo", "foo,bar")); - assert!(matches_pattern("bar", "foo,bar")); - assert!(!matches_pattern("baz", "foo,bar")); + assert!(matches_pattern("foo,bar", "foo")); + assert!(matches_pattern("foo,bar", "bar")); + assert!(!matches_pattern("foo,bar", "baz")); } } diff --git a/crates/core/action-pipeline/src/actions/run_target.rs b/crates/core/action-pipeline/src/actions/run_task.rs similarity index 96% rename from crates/core/action-pipeline/src/actions/run_target.rs rename to crates/core/action-pipeline/src/actions/run_task.rs index 3f256a457ba..ec6c9e1fa55 100644 --- a/crates/core/action-pipeline/src/actions/run_target.rs +++ b/crates/core/action-pipeline/src/actions/run_task.rs @@ -13,9 +13,9 @@ use std::env; use std::sync::Arc; use tokio::sync::RwLock; -const LOG_TARGET: &str = "moon:action:run-target"; +const LOG_TARGET: &str = "moon:action:run-task"; -pub async fn run_target( +pub async fn run_task( action: &mut Action, context: Arc>, emitter: Arc>, @@ -24,7 +24,7 @@ pub async fn run_target( target: &Target, runtime: &Runtime, ) -> miette::Result { - env::set_var("MOON_RUNNING_ACTION", "run-target"); + env::set_var("MOON_RUNNING_ACTION", "run-task"); let emitter = emitter.read().await; let workspace = workspace.read().await; @@ -33,7 +33,7 @@ pub async fn run_target( debug!( target: LOG_TARGET, - "Running target {}", + "Running task {}", color::label(&task.target) ); diff --git a/crates/core/action-pipeline/src/processor.rs b/crates/core/action-pipeline/src/processor.rs index cc939b1002e..af3ed5693a4 100644 --- a/crates/core/action-pipeline/src/processor.rs +++ b/crates/core/action-pipeline/src/processor.rs @@ -1,5 +1,5 @@ use crate::actions::install_deps::install_deps; -use crate::actions::run_target::run_target; +use crate::actions::run_task::run_task; use crate::actions::setup_tool::setup_tool; use crate::actions::sync_project::sync_project; use crate::actions::sync_workspace::sync_workspace; @@ -178,7 +178,7 @@ pub async fn process_action( local_emitter.emit(Event::TargetRunning { target }).await?; - let run_result = run_target( + let run_result = run_task( &mut action, context, emitter, diff --git a/crates/node/platform/src/actions/run_target.rs b/crates/node/platform/src/actions/run_target.rs index 8f34ed35770..94137aef49e 100644 --- a/crates/node/platform/src/actions/run_target.rs +++ b/crates/node/platform/src/actions/run_target.rs @@ -16,7 +16,7 @@ use rustc_hash::FxHashMap; use starbase_styles::color; use std::path::Path; -const LOG_TARGET: &str = "moon:node-platform:run-target"; +const LOG_TARGET: &str = "moon:node-platform:run-task"; fn create_node_options( node_config: &NodeConfig, diff --git a/website/src/utils/renderGraph.ts b/website/src/utils/renderGraph.ts index 6a6e0e8089f..cf91cd2385f 100644 --- a/website/src/utils/renderGraph.ts +++ b/website/src/utils/renderGraph.ts @@ -50,6 +50,13 @@ export function renderGraph(element: HTMLElement, graph: cytoscape.ElementsDefin width: 60, }, }, + { + selector: 'node[type="run-task"], node[type="sm"]', + style: { + // @ts-expect-error Types incorrect + 'background-gradient-stop-colors': '#6e58d1 #4a2ec6 #3b259e', + }, + }, { selector: 'node[type="run-target"], node[type="sm"]', style: { From 89f42628ed59f0cff3b2ca26448297fdb5773f62 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Sun, 8 Oct 2023 01:04:42 -0700 Subject: [PATCH 3/3] Update types. --- .yarn/versions/22a0caa2.yml | 6 ++++ nextgen/action-graph/src/action_node.rs | 1 + nextgen/platform-runtime/src/lib.rs | 1 + packages/types/src/common.ts | 5 +-- packages/types/src/pipeline.ts | 46 +++++++++++++++++-------- 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/.yarn/versions/22a0caa2.yml b/.yarn/versions/22a0caa2.yml index ead60d33b1b..997894edcae 100644 --- a/.yarn/versions/22a0caa2.yml +++ b/.yarn/versions/22a0caa2.yml @@ -8,3 +8,9 @@ releases: '@moonrepo/core-macos-x64': minor '@moonrepo/core-windows-x64-msvc': minor '@moonrepo/visualizer': minor + '@moonrepo/types': minor + '@moonrepo/report': minor + +declined: + - '@moonrepo/runtime' + - website diff --git a/nextgen/action-graph/src/action_node.rs b/nextgen/action-graph/src/action_node.rs index 365e13ffde5..8c15a04ba7b 100644 --- a/nextgen/action-graph/src/action_node.rs +++ b/nextgen/action-graph/src/action_node.rs @@ -5,6 +5,7 @@ use serde::Serialize; use std::hash::{Hash, Hasher}; #[derive(Clone, Debug, Eq, PartialEq, Serialize)] +#[serde(tag = "action", content = "params")] pub enum ActionNode { /// Install tool dependencies in the workspace root. InstallDeps { runtime: Runtime }, diff --git a/nextgen/platform-runtime/src/lib.rs b/nextgen/platform-runtime/src/lib.rs index b3627dc60a5..872419ee011 100644 --- a/nextgen/platform-runtime/src/lib.rs +++ b/nextgen/platform-runtime/src/lib.rs @@ -4,6 +4,7 @@ use std::fmt; use std::hash::{Hash, Hasher}; #[derive(Clone, Debug, Eq, PartialEq, Serialize)] +#[serde(untagged)] pub enum RuntimeReq { // Use tool available on PATH Global, diff --git a/packages/types/src/common.ts b/packages/types/src/common.ts index dc18029f2ea..196b6cd03e0 100644 --- a/packages/types/src/common.ts +++ b/packages/types/src/common.ts @@ -8,6 +8,7 @@ export interface Duration { } export interface Runtime { - platform: Capitalize; - version?: string; + platform: PlatformType; + requirement?: string; + overridden?: boolean; } diff --git a/packages/types/src/pipeline.ts b/packages/types/src/pipeline.ts index 22008cecc66..a03a78b5533 100644 --- a/packages/types/src/pipeline.ts +++ b/packages/types/src/pipeline.ts @@ -19,6 +19,7 @@ export interface Attempt { } export interface Action { + allowFailure?: boolean; attempts: Attempt[] | null; createdAt: string; duration: Duration | null; @@ -75,37 +76,52 @@ export interface RunReport { export type ActionNode = | ActionNodeInstallDeps | ActionNodeInstallProjectDeps - | ActionNodeRunPersistentTarget - | ActionNodeRunTarget + | ActionNodeRunTask | ActionNodeSetupTool - | ActionNodeSyncProject; + | ActionNodeSyncProject + | ActionNodeSyncWorkspace; export interface ActionNodeInstallDeps { action: 'InstallDeps'; - params: Runtime; + params: { + runtime: Runtime; + }; } export interface ActionNodeInstallProjectDeps { action: 'InstallProjectDeps'; - params: [Runtime, string]; -} - -export interface ActionNodeRunTarget { - action: 'RunTarget'; - params: [Runtime, string]; + params: { + runtime: Runtime; + project: string; + }; } -export interface ActionNodeRunPersistentTarget { - action: 'RunPersistentTarget'; - params: [Runtime, string]; +export interface ActionNodeRunTask { + action: 'RunTask'; + params: { + interactive: boolean; + persistent: boolean; + runtime: Runtime; + target: string; + }; } export interface ActionNodeSetupTool { action: 'SetupTool'; - params: Runtime; + params: { + runtime: Runtime; + }; } export interface ActionNodeSyncProject { action: 'SyncProject'; - params: [Runtime, string]; + params: { + runtime: Runtime; + project: string; + }; +} + +export interface ActionNodeSyncWorkspace { + action: 'SyncWorkspace'; + params: {}; }