Skip to content

Commit

Permalink
Update starbase.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed May 23, 2024
1 parent d5c5a76 commit d625ea0
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 53 deletions.
8 changes: 4 additions & 4 deletions crates/cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ pub struct CheckArgs {
pub async fn check(
args: ArgsRef<CheckArgs>,
global_args: StateRef<GlobalArgs>,
resources: ResourcesMut,
resources: Resources,
) {
let project_graph = { generate_project_graph(resources.get_mut::<Workspace>()).await? };
let project_graph = { generate_project_graph(&mut resources.get::<Workspace>()).await? };
let mut projects: Vec<Arc<Project>> = vec![];

// Load projects
Expand Down Expand Up @@ -89,8 +89,8 @@ pub async fn check(
..RunArgs::default()
},
global_args.concurrency,
resources.get::<Workspace>(),
resources.get::<Console>(),
&resources.get::<Workspace>(),
&resources.get::<Console>(),
project_graph,
)
.await?;
Expand Down
12 changes: 6 additions & 6 deletions crates/cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,28 +239,28 @@ fn generate_action_graph(
}

#[system]
pub async fn ci(args: ArgsRef<CiArgs>, global_args: StateRef<GlobalArgs>, resources: ResourcesMut) {
let project_graph = { generate_project_graph(resources.get_mut::<Workspace>()).await? };
pub async fn ci(args: ArgsRef<CiArgs>, global_args: StateRef<GlobalArgs>, resources: Resources) {
let project_graph = { generate_project_graph(&mut resources.get::<Workspace>()).await? };
let workspace = resources.get::<Workspace>();
let mut console = CiConsole {
inner: resources.get::<Console>(),
inner: &resources.get::<Console>(),
output: ci_env::get_output().unwrap_or(CiOutput {
close_log_group: "",
open_log_group: "▪▪▪▪ {name}",
}),
last_title: String::new(),
};

let touched_files = gather_touched_files(&mut console, workspace, args).await?;
let targets = gather_runnable_targets(&mut console, &project_graph, args)?;
let touched_files = gather_touched_files(&mut console, &workspace, &args).await?;
let targets = gather_runnable_targets(&mut console, &project_graph, &args)?;

if targets.is_empty() {
console.write_line(color::invalid("No targets to run"))?;

return Ok(());
}

let targets = distribute_targets_across_jobs(&mut console, args, targets)?;
let targets = distribute_targets_across_jobs(&mut console, &args, targets)?;
let action_graph =
generate_action_graph(&mut console, &project_graph, &targets, &touched_files)?;

Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/commands/docker/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use starbase_utils::json;
use std::sync::Arc;

#[system]
pub async fn setup(resources: ResourcesMut) {
pub async fn setup(resources: Resources) {
let manifest_path = { resources.get::<Workspace>().root.join(MANIFEST_NAME) };

if !manifest_path.exists() {
Expand All @@ -23,7 +23,7 @@ pub async fn setup(resources: ResourcesMut) {
}

let manifest: DockerManifest = json::read_file(manifest_path)?;
let project_graph = { generate_project_graph(resources.get_mut::<Workspace>()).await? };
let project_graph = { generate_project_graph(&mut resources.get::<Workspace>()).await? };
let mut action_graph_builder = build_action_graph(&project_graph)?;

for project_id in &manifest.focused_projects {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub async fn generate(
console.flush()?;

// Gather variables
let mut context = gather_variables(args, &template, base_console)?;
let mut context = gather_variables(&args, &template, base_console)?;

// Determine the destination path
let relative_dest = PathBuf::from(match &args.dest {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/graph/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ pub async fn internal_action_graph(

#[system]
pub async fn action_graph(args: ArgsRef<ActionGraphArgs>, workspace: ResourceMut<Workspace>) {
internal_action_graph(args, workspace).await?;
internal_action_graph(&args, workspace).await?;
}
2 changes: 1 addition & 1 deletion crates/cli/src/commands/graph/dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ pub async fn dep_graph(args: ArgsRef<ActionGraphArgs>, workspace: ResourceMut<Wo
color::shell("moon action-graph")
);

internal_action_graph(args, workspace).await?;
internal_action_graph(&args, workspace).await?;
}
7 changes: 4 additions & 3 deletions crates/cli/src/commands/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ pub struct ProjectArgs {
}

#[system]
pub async fn project(args: ArgsRef<ProjectArgs>, resources: ResourcesMut) {
let mut project_graph_builder =
{ build_project_graph(resources.get_mut::<Workspace>()).await? };
pub async fn project(args: ArgsRef<ProjectArgs>, resources: Resources) {
let mut workspace = resources.get::<Workspace>();

let mut project_graph_builder = build_project_graph(&mut workspace).await?;
project_graph_builder.load(&args.id).await?;

let project_graph = project_graph_builder.build().await?;
Expand Down
12 changes: 6 additions & 6 deletions crates/cli/src/commands/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub struct QueryProjectsArgs {
}

#[system]
pub async fn projects(args: ArgsRef<QueryProjectsArgs>, resources: ResourcesMut) {
pub async fn projects(args: ArgsRef<QueryProjectsArgs>, resources: Resources) {
let args = args.to_owned();
let options = QueryProjectsOptions {
alias: args.alias,
Expand All @@ -171,14 +171,14 @@ pub async fn projects(args: ArgsRef<QueryProjectsArgs>, resources: ResourcesMut)
tags: args.tags,
tasks: args.tasks,
touched_files: if args.affected {
load_touched_files(resources.get::<Workspace>()).await?
load_touched_files(&resources.get::<Workspace>()).await?
} else {
FxHashSet::default()
},
type_of: args.type_of,
};

let mut projects = { query_projects(resources.get_mut::<Workspace>(), &options).await? };
let mut projects = { query_projects(&mut resources.get::<Workspace>(), &options).await? };

projects.sort_by(|a, d| a.id.cmp(&d.id));

Expand Down Expand Up @@ -241,7 +241,7 @@ pub struct QueryTasksArgs {
}

#[system]
pub async fn tasks(args: ArgsRef<QueryTasksArgs>, resources: ResourcesMut) {
pub async fn tasks(args: ArgsRef<QueryTasksArgs>, resources: Resources) {
let args = args.to_owned();
let options = QueryProjectsOptions {
alias: args.alias,
Expand All @@ -255,9 +255,9 @@ pub async fn tasks(args: ArgsRef<QueryTasksArgs>, resources: ResourcesMut) {
..QueryProjectsOptions::default()
};

let projects = { query_projects(resources.get_mut::<Workspace>(), &options).await? };
let projects = { query_projects(&mut resources.get::<Workspace>(), &options).await? };
let touched_files = if args.affected {
load_touched_files(resources.get::<Workspace>()).await?
load_touched_files(&resources.get::<Workspace>()).await?
} else {
FxHashSet::default()
};
Expand Down
14 changes: 5 additions & 9 deletions crates/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,15 @@ pub async fn run_target(
}

#[system]
pub async fn run(
args: ArgsRef<RunArgs>,
global_args: StateRef<GlobalArgs>,
resources: ResourcesMut,
) {
let project_graph = { generate_project_graph(resources.get_mut::<Workspace>()).await? };
pub async fn run(args: ArgsRef<RunArgs>, global_args: StateRef<GlobalArgs>, resources: Resources) {
let project_graph = { generate_project_graph(&mut resources.get::<Workspace>()).await? };

run_target(
&args.targets,
args,
&args,
global_args.concurrency,
resources.get::<Workspace>(),
resources.get::<Console>(),
&resources.get::<Workspace>(),
&resources.get::<Console>(),
project_graph,
)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use starbase_styles::color;
use tracing::warn;

#[system]
pub async fn sync(resources: ResourcesMut) {
pub async fn sync(resources: Resources) {
warn!(
"This command is deprecated. Use {} instead.",
color::shell("moon sync projects")
Expand Down
7 changes: 3 additions & 4 deletions crates/cli/src/commands/syncs/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use moon_app_components::Console;
use moon_workspace::Workspace;
use starbase::{system, ResourceManager, SystemResult};
use std::sync::Arc;
use tokio::sync::RwLockWriteGuard;

pub async fn internal_sync(mut resources: RwLockWriteGuard<'_, ResourceManager>) -> SystemResult {
pub async fn internal_sync(resources: Arc<ResourceManager>) -> SystemResult {
let done = create_progress_bar("Syncing projects...");

let project_graph = { generate_project_graph(resources.get_mut::<Workspace>()).await? };
let project_graph = { generate_project_graph(&mut resources.get::<Workspace>()).await? };

let mut project_count = 0;
let mut action_graph_builder = build_action_graph(&project_graph)?;
Expand Down Expand Up @@ -41,6 +40,6 @@ pub async fn internal_sync(mut resources: RwLockWriteGuard<'_, ResourceManager>)
}

#[system]
pub async fn sync(resources: ResourcesMut) {
pub async fn sync(resources: Resources) {
internal_sync(resources).await?;
}
9 changes: 4 additions & 5 deletions crates/cli/src/commands/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ pub struct TaskArgs {
}

#[system]
pub async fn task(args: ArgsRef<TaskArgs>, resources: ResourcesMut) {
pub async fn task(args: ArgsRef<TaskArgs>, resources: Resources) {
let TargetScope::Project(project_locator) = &args.target.scope else {
return Err(miette!(code = "moon::task", "A project ID is required."));
};

let mut project_graph_builder =
{ build_project_graph(resources.get_mut::<Workspace>()).await? };
let mut workspace = resources.get::<Workspace>();

let mut project_graph_builder = build_project_graph(&mut workspace).await?;
project_graph_builder.load(project_locator).await?;

let project_graph = project_graph_builder.build().await?;
Expand All @@ -38,8 +39,6 @@ pub async fn task(args: ArgsRef<TaskArgs>, resources: ResourcesMut) {
return Ok(());
}

let workspace = resources.get::<Workspace>();

console.print_header(&args.target.id)?;

if let Some(desc) = &task.description {
Expand Down
10 changes: 5 additions & 5 deletions crates/cli/src/systems/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tracing::debug;
// IN ORDER:

#[system]
pub async fn load_environments(states: StatesMut, resources: ResourcesMut) {
pub async fn load_environments(states: States, resources: Resources) {
let quiet = { states.get::<GlobalArgs>().quiet };

states.set(MoonEnv(Arc::new(MoonEnvironment::new()?)));
Expand All @@ -31,9 +31,9 @@ pub async fn load_environments(states: StatesMut, resources: ResourcesMut) {
}

#[system]
pub async fn load_workspace(states: StatesMut, resources: ResourcesMut) {
pub async fn load_workspace(states: States, resources: Resources) {
let workspace = moon::load_workspace_from(
Arc::clone(states.get::<ProtoEnv>()),
Arc::clone(&states.get::<ProtoEnv>()),
Arc::new(resources.get::<Console>().to_owned()),
)
.await?;
Expand All @@ -42,7 +42,7 @@ pub async fn load_workspace(states: StatesMut, resources: ResourcesMut) {

// Ensure our env instance is using the found workspace root,
// as this is required for plugins to function entirely!
Arc::get_mut(states.get_mut::<MoonEnv>())
Arc::get_mut(&mut states.get::<MoonEnv>())
.unwrap()
.workspace_root = workspace.root.clone();

Expand All @@ -51,7 +51,7 @@ pub async fn load_workspace(states: StatesMut, resources: ResourcesMut) {

#[system]
pub async fn create_plugin_registries(
resources: ResourcesMut,
resources: Resources,
moon_env: StateRef<MoonEnv>,
proto_env: StateRef<ProtoEnv>,
) {
Expand Down
10 changes: 5 additions & 5 deletions nextgen/app/src/systems/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tracing::debug;

/// Detect important information about the currently running moon process.
#[system]
pub fn detect_app_process_info(resources: ResourcesMut) {
pub fn detect_app_process_info(resources: Resources) {
let current_exe = env::current_exe().ok();
let version = env!("CARGO_PKG_VERSION");

Expand All @@ -38,7 +38,7 @@ pub fn detect_app_process_info(resources: ResourcesMut) {
/// Recursively attempt to find the workspace root by locating the ".moon"
/// configuration folder, starting from the current working directory.
#[system]
pub fn find_workspace_root(states: StatesMut) {
pub fn find_workspace_root(states: States) {
let working_dir = env::current_dir().map_err(|_| AppError::MissingWorkingDir)?;

debug!(
Expand Down Expand Up @@ -86,7 +86,7 @@ pub fn find_workspace_root(states: StatesMut) {
/// Load the workspace configuration file from the `.moon` directory in the workspace root.
/// This file is required to exist, so error if not found.
#[system]
pub fn load_workspace_config(workspace_root: StateRef<WorkspaceRoot>, resources: ResourcesMut) {
pub fn load_workspace_config(workspace_root: StateRef<WorkspaceRoot>, resources: Resources) {
let config_name = format!(
"{}/{}",
consts::CONFIG_DIRNAME,
Expand All @@ -113,7 +113,7 @@ pub fn load_workspace_config(workspace_root: StateRef<WorkspaceRoot>, resources:

/// Load the toolchain configuration file from the `.moon` directory if it exists.
#[system]
pub fn load_toolchain_config(workspace_root: StateRef<WorkspaceRoot>, resources: ResourcesMut) {
pub fn load_toolchain_config(workspace_root: StateRef<WorkspaceRoot>, resources: Resources) {
let config_name = format!(
"{}/{}",
consts::CONFIG_DIRNAME,
Expand Down Expand Up @@ -156,7 +156,7 @@ pub fn load_toolchain_config(workspace_root: StateRef<WorkspaceRoot>, resources:
/// Load the tasks configuration file from the `.moon` directory if it exists.
/// Also load all scoped tasks from the `.moon/tasks` directory and load into the manager.
#[system]
pub fn load_tasks_config(workspace_root: StateRef<WorkspaceRoot>, resources: ResourcesMut) {
pub fn load_tasks_config(workspace_root: StateRef<WorkspaceRoot>, resources: Resources) {
let config_name = format!(
"{}/{}",
consts::CONFIG_DIRNAME,
Expand Down

0 comments on commit d625ea0

Please sign in to comment.