Skip to content

Commit

Permalink
internal: Migrate workspace to next-gen. Rework some config versions. (
Browse files Browse the repository at this point in the history
…#1059)

* Move workspace over.

* Rework version handling.

* Update config.

* Fix lints.

* Fix test.

* Wrap config in arc.

* Fixes.

* Fix tests.
  • Loading branch information
milesj authored Sep 20, 2023
1 parent 0c5f27a commit ac04509
Show file tree
Hide file tree
Showing 55 changed files with 406 additions and 276 deletions.
22 changes: 14 additions & 8 deletions .yarn/versions/fa0ffbe8.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
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/report'
- '@moonrepo/runtime'
- 'website'
7 changes: 3 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ rustc-hash = "1.1.0"
schematic = { version = "0.11.5", default-features = false, features = [
"schema",
"yaml",
"type_semver",
"type_warpgate",
] }
semver = "1.0.18"
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ moon_tool = { path = "../core/tool" }
moon_typescript_lang = { path = "../typescript/lang" }
moon_utils = { path = "../core/utils" }
moon_vcs = { path = "../../nextgen/vcs" }
moon_workspace = { path = "../core/workspace" }
moon_workspace = { path = "../../nextgen/workspace" }
bytes = "1.4.0"
ci_env = { workspace = true }
clap = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/tests/misc_test.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use moon_test_utils::{
create_sandbox_with_config, get_cases_fixture_configs, predicates::prelude::*,
};
use proto_core::VersionReq;

#[test]
fn fails_on_version_constraint() {
let (mut workspace_config, _, _) = get_cases_fixture_configs();

workspace_config.version_constraint = Some(">=1000.0.0".into());
workspace_config.version_constraint = Some(VersionReq::parse(">=1000.0.0").unwrap());

let sandbox = create_sandbox_with_config("cases", Some(workspace_config), None, None);

Expand Down
2 changes: 1 addition & 1 deletion crates/core/action-pipeline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ moon_target = { path = "../../../nextgen/target" }
moon_terminal = { path = "../terminal" }
moon_tool = { path = "../tool" }
moon_utils = { path = "../utils" }
moon_workspace = { path = "../workspace" }
moon_workspace = { path = "../../../nextgen/workspace" }
ci_env = { workspace = true }
console = { workspace = true }
miette = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/core/action-pipeline/src/actions/setup_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tokio::sync::RwLock;

cache_item!(
pub struct ToolState {
pub last_versions: FxHashMap<String, String>,
pub last_versions: FxHashMap<String, proto_core::Version>,
pub last_version_check_time: u128,
}
);
Expand Down
2 changes: 1 addition & 1 deletion crates/core/actions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ moon_cache_item = { path = "../../../nextgen/cache-item" }
moon_codeowners = { path = "../../../nextgen/codeowners" }
moon_config = { path = "../../../nextgen/config" }
moon_project_graph = { path = "../../../nextgen/project-graph" }
moon_workspace = { path = "../workspace" }
moon_workspace = { path = "../../../nextgen/workspace" }
moon_vcs_hooks = { path = "../../../nextgen/vcs-hooks" }
miette = { workspace = true }
2 changes: 1 addition & 1 deletion crates/core/dep-graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ moon = { path = "../moon" }
moon_config = { path = "../../../nextgen/config" }
moon_test_utils = { path = "../test-utils" }
moon_utils = { path = "../utils" }
moon_workspace = { path = "../workspace" }
moon_workspace = { path = "../../../nextgen/workspace" }
criterion = { workspace = true }
tokio = { workspace = true }
6 changes: 3 additions & 3 deletions crates/core/dep-graph/tests/dep_graph_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use moon::{build_dep_graph, generate_project_graph, load_workspace_from};
use moon_common::path::WorkspaceRelativePathBuf;
use moon_config::{
PartialInheritedTasksConfig, PartialNodeConfig, PartialToolchainConfig, PartialWorkspaceConfig,
PartialWorkspaceProjects,
PartialWorkspaceProjects, Version,
};
use moon_dep_graph::BatchedTopoSort;
use moon_project_graph::ProjectGraph;
Expand Down Expand Up @@ -31,7 +31,7 @@ async fn create_project_graph() -> (Workspace, ProjectGraph, Sandbox) {
};
let toolchain_config = PartialToolchainConfig {
node: Some(PartialNodeConfig {
version: Some("16.0.0".into()),
version: Some(Version::parse("16.0.0").unwrap()),
dedupe_on_lockfile_change: Some(false),
..PartialNodeConfig::default()
}),
Expand Down Expand Up @@ -88,7 +88,7 @@ async fn create_tasks_project_graph() -> (Workspace, ProjectGraph, Sandbox) {
};
let toolchain_config = PartialToolchainConfig {
node: Some(PartialNodeConfig {
version: Some("16.0.0".into()),
version: Some(Version::parse("16.0.0").unwrap()),
..PartialNodeConfig::default()
}),
..PartialToolchainConfig::default()
Expand Down
2 changes: 1 addition & 1 deletion crates/core/emitter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ moon_project = { path = "../../../nextgen/project" }
moon_target = { path = "../../../nextgen/target" }
moon_task = { path = "../../../nextgen/task" }
moon_utils = { path = "../utils" }
moon_workspace = { path = "../workspace" }
moon_workspace = { path = "../../../nextgen/workspace" }
async-trait = { workspace = true }
miette = { workspace = true }
serde = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/core/moon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ moon_project_graph = { path = "../../../nextgen/project-graph" }
moon_rust_platform = { path = "../../rust/platform" }
moon_system_platform = { path = "../../system/platform" }
moon_utils = { path = "../utils" }
moon_workspace = { path = "../workspace" }
moon_workspace = { path = "../../../nextgen/workspace" }
miette = { workspace = true }
rustc-hash = { workspace = true }
starbase_events = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/core/notifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false
moon_emitter = { path = "../emitter" }
moon_logger = { path = "../logger" }
moon_utils = { path = "../utils" }
moon_workspace = { path = "../workspace" }
moon_workspace = { path = "../../../nextgen/workspace" }
async-trait = { workspace = true }
ci_env = { workspace = true }
miette = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions crates/core/platform-runtime/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pub struct Version {
}

impl Version {
pub fn new(version: &str) -> Self {
pub fn new<V: AsRef<str>>(version: V) -> Self {
Version {
number: version.to_owned(),
number: version.as_ref().to_owned(),
path_executable: false,
project_override: false,
}
Expand All @@ -30,9 +30,9 @@ impl Version {
}
}

pub fn new_override(version: &str) -> Self {
pub fn new_override<V: AsRef<str>>(version: V) -> Self {
Version {
number: version.to_owned(),
number: version.as_ref().to_owned(),
path_executable: false,
project_override: true,
}
Expand Down
3 changes: 2 additions & 1 deletion crates/core/platform/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use moon_process::Command;
use moon_project::Project;
use moon_task::Task;
use moon_tool::Tool;
use proto_core::Version as SemVersion;
use rustc_hash::FxHashMap;
use std::collections::BTreeMap;
use std::path::Path;
Expand Down Expand Up @@ -103,7 +104,7 @@ pub trait Platform: Send + Sync {
&mut self,
context: &ActionContext,
runtime: &Runtime,
last_versions: &mut FxHashMap<String, String>,
last_versions: &mut FxHashMap<String, SemVersion>,
) -> miette::Result<u8> {
Ok(0)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ moon_tool = { path = "../tool" }
moon_terminal = { path = "../terminal" }
moon_utils = { path = "../utils" }
moon_vcs = { path = "../../../nextgen/vcs" }
moon_workspace = { path = "../workspace" }
moon_workspace = { path = "../../../nextgen/workspace" }
console = { workspace = true }
miette = { workspace = true }
rustc-hash = { workspace = true }
Expand Down
9 changes: 7 additions & 2 deletions crates/core/runner/tests/inputs_collector_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use moon_runner::inputs_collector::collect_and_hash_inputs;
use moon_test_utils::{create_sandbox_with_config, get_cases_fixture_configs, Sandbox};
use moon_vcs::{BoxedVcs, Git};
use std::path::Path;
use std::sync::Arc;
use std::{env, fs};

fn cases_sandbox() -> Sandbox {
Expand Down Expand Up @@ -120,7 +121,9 @@ async fn filters_using_input_globs_in_glob_mode() {
let project_graph = generate_project_graph(&mut workspace).await.unwrap();
let vcs = load_vcs(&workspace.root, &workspace.config);

workspace.config.hasher.walk_strategy = HasherWalkStrategy::Glob;
let mut workspace_config = Arc::into_inner(workspace.config).unwrap();
workspace_config.hasher.walk_strategy = HasherWalkStrategy::Glob;
workspace.config = Arc::new(workspace_config);

let project = project_graph.get("outputsFiltering").unwrap();

Expand Down Expand Up @@ -261,7 +264,9 @@ async fn filters_using_input_files_in_glob_mode() {
let project_graph = generate_project_graph(&mut workspace).await.unwrap();
let vcs = load_vcs(&workspace.root, &workspace.config);

workspace.config.hasher.walk_strategy = HasherWalkStrategy::Glob;
let mut workspace_config = Arc::into_inner(workspace.config).unwrap();
workspace_config.hasher.walk_strategy = HasherWalkStrategy::Glob;
workspace.config = Arc::new(workspace_config);

let project = project_graph.get("outputsFiltering").unwrap();

Expand Down
1 change: 1 addition & 0 deletions crates/core/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ insta = "1.31.0"
predicates = "3.0.3"
pretty_assertions = "1.4.0"
rustc-hash = { workspace = true }
semver = { workspace = true }
serde_yaml = { workspace = true }
starbase_utils = { workspace = true }
# symlink = "0.1.0"
Expand Down
17 changes: 9 additions & 8 deletions crates/core/test-utils/src/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ use moon_config::{
PartialWorkspaceProjects, PartialWorkspaceProjectsConfig, PartialYarnConfig,
};
use rustc_hash::FxHashMap;
use semver::Version;
use std::collections::BTreeMap;
use std::str::FromStr;

// Turn everything off by default
pub fn get_default_toolchain() -> PartialToolchainConfig {
PartialToolchainConfig {
node: Some(PartialNodeConfig {
version: Some("18.0.0".into()),
version: Some(Version::parse("18.0.0").unwrap()),
add_engines_constraint: Some(false),
dedupe_on_lockfile_change: Some(false),
infer_tasks_from_scripts: Some(false),
sync_project_workspace_dependencies: Some(false),
npm: Some(PartialNpmConfig {
version: Some("8.19.0".into()),
version: Some(Version::parse("8.19.0").unwrap()),
..PartialNpmConfig::default()
}),
..PartialNodeConfig::default()
Expand Down Expand Up @@ -145,11 +146,11 @@ pub fn get_project_graph_aliases_fixture_configs() -> (

let toolchain_config = PartialToolchainConfig {
node: Some(PartialNodeConfig {
version: Some("18.0.0".into()),
version: Some(Version::parse("18.0.0").unwrap()),
add_engines_constraint: Some(false),
dedupe_on_lockfile_change: Some(false),
npm: Some(PartialNpmConfig {
version: Some("8.19.0".into()),
version: Some(Version::parse("8.19.0").unwrap()),
..PartialNpmConfig::default()
}),
..PartialNodeConfig::default()
Expand Down Expand Up @@ -348,29 +349,29 @@ pub fn get_node_depman_fixture_configs(
"npm" => {
node_config.package_manager = Some(NodePackageManager::Npm);
node_config.npm = Some(PartialNpmConfig {
version: Some("8.0.0".into()),
version: Some(Version::parse("8.0.0").unwrap()),
..PartialNpmConfig::default()
});
}
"pnpm" => {
node_config.package_manager = Some(NodePackageManager::Pnpm);
node_config.pnpm = Some(PartialPnpmConfig {
version: Some("7.5.0".into()),
version: Some(Version::parse("7.5.0").unwrap()),
..PartialPnpmConfig::default()
});
}
"yarn" => {
node_config.package_manager = Some(NodePackageManager::Yarn);
node_config.yarn = Some(PartialYarnConfig {
version: Some("3.3.0".into()),
version: Some(Version::parse("3.3.0").unwrap()),
plugins: Some(vec!["workspace-tools".into()]),
..PartialYarnConfig::default()
});
}
"yarn1" => {
node_config.package_manager = Some(NodePackageManager::Yarn);
node_config.yarn = Some(PartialYarnConfig {
version: Some("1.22.0".into()),
version: Some(Version::parse("1.22.0").unwrap()),
plugins: Some(vec![]),
..PartialYarnConfig::default()
});
Expand Down
3 changes: 2 additions & 1 deletion crates/core/tool/src/manager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::errors::ToolError;
use crate::tool::Tool;
use moon_platform_runtime::{Runtime, Version};
use proto_core::Version as SemVersion;
use rustc_hash::FxHashMap;

pub struct ToolManager<T: Tool> {
Expand Down Expand Up @@ -51,7 +52,7 @@ impl<T: Tool> ToolManager<T> {
pub async fn setup(
&mut self,
version: &Version,
last_versions: &mut FxHashMap<String, String>,
last_versions: &mut FxHashMap<String, SemVersion>,
) -> miette::Result<u8> {
match self.cache.get_mut(&version.number) {
Some(cache) => Ok(cache.setup(last_versions).await?),
Expand Down
3 changes: 2 additions & 1 deletion crates/core/tool/src/tool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use async_trait::async_trait;
use moon_lang::LockfileDependencyVersions;
use moon_process::Command;
use proto_core::Version;
use rustc_hash::FxHashMap;
use std::any::Any;
use std::path::{Path, PathBuf};
Expand All @@ -21,7 +22,7 @@ pub trait Tool: Any + Send + Sync {
/// Return a count of how many sub-tools were installed.
async fn setup(
&mut self,
_last_versions: &mut FxHashMap<String, String>,
_last_versions: &mut FxHashMap<String, Version>,
) -> miette::Result<u8> {
Ok(0)
}
Expand Down
Loading

0 comments on commit ac04509

Please sign in to comment.