Skip to content

Commit 5a67a05

Browse files
authored
fix: Audit 07/01 (#2038)
* Fix preloading. * Fix dupes. * Fix node pm. * Fix ci panic. * Bump version. * Fix proto.
1 parent 2c4287b commit 5a67a05

8 files changed

Lines changed: 94 additions & 29 deletions

File tree

.yarn/versions/d0a6b463.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
releases:
2+
"@moonrepo/cli": patch
3+
"@moonrepo/core-linux-arm64-gnu": patch
4+
"@moonrepo/core-linux-arm64-musl": patch
5+
"@moonrepo/core-linux-x64-gnu": patch
6+
"@moonrepo/core-linux-x64-musl": patch
7+
"@moonrepo/core-macos-arm64": patch
8+
"@moonrepo/core-macos-x64": patch
9+
"@moonrepo/core-windows-x64-msvc": patch

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
#### 🚀 Updates
6+
7+
- More plugin pre-loading improvements.
8+
9+
#### 🐞 Fixes
10+
11+
- Potential fix for duplicate nodes in the action graph.
12+
- Potential fix for the node platform panicing for a missing package manager.
13+
- Potential fix for a fs rename error when installing proto.
14+
- Fixed a panic that would occur during `moon ci` job calculation.
15+
316
## 1.38.1
417

518
#### 🚀 Updates

crates/action-graph/src/action_graph_builder.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ use petgraph::prelude::*;
2222
use rustc_hash::{FxHashMap, FxHashSet};
2323
use std::mem;
2424
use std::sync::Arc;
25+
use tokio::sync::RwLock;
2526
use tracing::{debug, instrument, trace};
2627

2728
macro_rules! insert_node_or_exit {
2829
($builder:ident, $node:expr) => {{
2930
let node = $node;
3031

31-
match $builder.get_index_from_node(&node) {
32+
match $builder.get_index_from_node(&node).await {
3233
Some(index) => {
3334
return Ok(Some(index));
3435
}
35-
None => $builder.insert_node(node),
36+
None => $builder.insert_node(node).await,
3637
}
3738
}};
3839
}
@@ -78,7 +79,7 @@ pub struct ActionGraphBuilder<'query> {
7879
all_query: Option<Criteria<'query>>,
7980
app_context: Arc<AppContext>,
8081
graph: DiGraph<ActionNode, ()>,
81-
nodes: FxHashMap<ActionNode, NodeIndex>,
82+
nodes: RwLock<FxHashMap<ActionNode, NodeIndex>>,
8283
options: ActionGraphBuilderOptions,
8384
platform_manager: Option<PlatformManager>,
8485
workspace_graph: Arc<WorkspaceGraph>,
@@ -106,7 +107,7 @@ impl<'query> ActionGraphBuilder<'query> {
106107
all_query: None,
107108
app_context,
108109
graph: DiGraph::new(),
109-
nodes: FxHashMap::default(),
110+
nodes: RwLock::new(FxHashMap::default()),
110111
options,
111112
passthrough_targets: FxHashSet::default(),
112113
platform_manager: None,
@@ -269,10 +270,10 @@ impl<'query> ActionGraphBuilder<'query> {
269270
return Ok(None);
270271
};
271272

272-
let mut edges = vec![
273+
let mut edges = FxHashSet::from_iter([
273274
self.sync_workspace().await?,
274275
self.setup_toolchain_legacy(runtime).await?,
275-
];
276+
]);
276277

277278
let platform_manager = match &self.platform_manager {
278279
Some(manager) => manager,
@@ -312,7 +313,7 @@ impl<'query> ActionGraphBuilder<'query> {
312313
);
313314
}
314315

315-
edges.push(self.setup_toolchain_legacy(&new_runtime).await?);
316+
edges.insert(self.setup_toolchain_legacy(&new_runtime).await?);
316317

317318
let index = insert_node_or_exit!(
318319
self,
@@ -329,7 +330,7 @@ impl<'query> ActionGraphBuilder<'query> {
329330
}
330331
);
331332

332-
self.link_optional_requirements(index, edges);
333+
self.link_optional_requirements(index, edges.into_iter().collect());
333334

334335
Ok(Some(index))
335336
}
@@ -833,7 +834,7 @@ impl<'query> ActionGraphBuilder<'query> {
833834
});
834835

835836
// Check if the node exists to avoid all the overhead below
836-
if let Some(index) = self.get_index_from_node(&node) {
837+
if let Some(index) = self.get_index_from_node(&node).await {
837838
return Ok(Some(index));
838839
}
839840

@@ -851,7 +852,7 @@ impl<'query> ActionGraphBuilder<'query> {
851852
}
852853

853854
// Insert and then link edges
854-
let index = self.insert_node(node);
855+
let index = self.insert_node(node).await;
855856

856857
if !task.deps.is_empty() {
857858
child_reqs.skip_affected = true;
@@ -1037,8 +1038,8 @@ impl<'query> ActionGraphBuilder<'query> {
10371038

10381039
// PRIVATE
10391040

1040-
fn get_index_from_node(&self, node: &ActionNode) -> Option<NodeIndex> {
1041-
self.nodes.get(node).cloned()
1041+
async fn get_index_from_node(&self, node: &ActionNode) -> Option<NodeIndex> {
1042+
self.nodes.read().await.get(node).cloned()
10421043
}
10431044

10441045
fn link_first_requirement(&mut self, index: NodeIndex, edges: Vec<Option<NodeIndex>>) {
@@ -1069,11 +1070,13 @@ impl<'query> ActionGraphBuilder<'query> {
10691070
}
10701071
}
10711072

1072-
fn insert_node(&mut self, node: ActionNode) -> NodeIndex {
1073+
async fn insert_node(&mut self, node: ActionNode) -> NodeIndex {
1074+
let mut nodes = self.nodes.write().await;
1075+
10731076
let label = node.label();
10741077
let index = self.graph.add_node(node.clone());
10751078

1076-
self.nodes.insert(node, index);
1079+
nodes.insert(node, index);
10771080

10781081
debug!(
10791082
index = index.index(),

crates/app/src/commands/ci.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,23 +179,37 @@ fn distribute_targets_across_jobs(
179179
let job_index = args.job.unwrap_or_default();
180180
let job_total = args.job_total.unwrap_or_default();
181181
let batch_size = targets.len().div_ceil(job_total);
182-
let batched_targets;
183182

184183
console.print_header("Distributing targets across jobs")?;
185184
console.write_line(format!("Job index: {job_index}"))?;
186185
console.write_line(format!("Job total: {job_total}"))?;
187186
console.write_line(format!("Batch size: {batch_size}"))?;
188-
console.write_line("Batched targets:")?;
189187

188+
let (start, stop) =
189+
// beginning
190190
if job_index == 0 {
191-
batched_targets = targets[0..batch_size].to_vec();
192-
} else if job_index == job_total - 1 {
193-
batched_targets = targets[(batch_size * job_index)..].to_vec();
194-
} else {
195-
batched_targets =
196-
targets[(batch_size * job_index)..(batch_size * (job_index + 1))].to_vec();
191+
(0, batch_size)
192+
}
193+
// end
194+
else if job_index == job_total - 1 {
195+
((batch_size * job_index), targets.len())
196+
}
197+
// middle
198+
else {
199+
((batch_size * job_index), (batch_size * (job_index + 1)))
200+
};
201+
202+
let mut batched_targets = vec![];
203+
204+
if targets.get(start).is_some() {
205+
if targets.get(stop).is_some() {
206+
batched_targets = targets[start..stop].to_vec();
207+
} else {
208+
batched_targets = targets[start..].to_vec();
209+
}
197210
}
198211

212+
console.write_line("Batched targets:")?;
199213
console.print_targets(&batched_targets)?;
200214
console.print_footer()?;
201215

crates/app/src/systems/analyze.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,23 @@ pub async fn install_proto(
117117
let result = download_release(
118118
&target_triple,
119119
PROTO_CLI_VERSION,
120-
&proto_env.store.temp_dir,
120+
proto_env.store.temp_dir.join("proto"),
121121
|_, _| {},
122122
)
123123
.await?;
124124

125125
debug!("Unpacking archive and installing proto");
126126

127-
install_release(result, &install_dir, &proto_env.store.temp_dir, false)?;
127+
install_release(
128+
result,
129+
install_dir,
130+
proto_env
131+
.store
132+
.temp_dir
133+
.join("proto")
134+
.join(PROTO_CLI_VERSION),
135+
false,
136+
)?;
128137

129138
debug!("Successfully installed proto!");
130139

crates/config/src/toolchain_config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ impl ToolchainConfig {
239239
return true;
240240
}
241241

242+
for config in self.plugins.values() {
243+
if config.version.is_some() {
244+
return true;
245+
}
246+
}
247+
242248
false
243249
}
244250

crates/toolchain-plugin/src/toolchain_plugin.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use moon_feature_flags::glob_walk;
33
use moon_pdk_api::*;
44
use moon_plugin::{Plugin, PluginContainer, PluginId, PluginRegistration, PluginType};
55
use proto_core::flow::install::InstallOptions;
6-
use proto_core::{PluginLocator, Tool, ToolSpec, UnresolvedVersionSpec};
6+
use proto_core::{PluginLocator, Tool, ToolSpec, UnresolvedVersionSpec, locate_tool};
77
use starbase_utils::glob::GlobSet;
88
use std::fmt;
99
use std::ops::Deref;
@@ -433,10 +433,14 @@ impl ToolchainPlugin {
433433

434434
// Pre-load the tool plugin so that task executions
435435
// avoid network race conditions and collisions
436-
if let (Ok(loader), Some(locator)) =
437-
(tool.proto.get_plugin_loader(), tool.locator.as_ref())
438-
{
439-
let _ = loader.load_plugin(&tool.id, locator).await;
436+
if let Ok(loader) = tool.proto.get_plugin_loader() {
437+
if let Some(locator) = tool
438+
.locator
439+
.clone()
440+
.or_else(|| locate_tool(&tool.id, &tool.proto).ok())
441+
{
442+
let _ = loader.load_plugin(&tool.id, &locator).await;
443+
}
440444
}
441445
}
442446

legacy/node/tool/src/node_tool.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ impl NodeTool {
107107
}
108108
};
109109

110+
// Temp fix
111+
if node.bun.is_none() && node.npm.is_none() && node.pnpm.is_none() && node.yarn.is_none() {
112+
node.npm = Some(
113+
NpmTool::new(Arc::clone(&proto_env), Arc::clone(&console), &config.npm).await?,
114+
);
115+
}
116+
110117
Ok(node)
111118
}
112119

0 commit comments

Comments
 (0)