Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
381 changes: 312 additions & 69 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,21 @@ path = "src/makers.rs"

[dependencies]
cargo_metadata = "^0.18"
ci_info = "^0.14.14"
ci_info = { version = "^0.14.14", features = ["serde-1"] }
cliparser = "^0.1.2"
colored = "^2"
ctrlc = "^3"
diesel = { version = "^2", optional = true, features = ["serde_json", "r2d2"] }
diesel_migrations = { version = "^2", optional = true }
dirs-next = "^2"
duckscript = "^0.8.0"
duckscriptsdk = { version = "^0.9.3", default-features = false }
envmnt = "^0.10.4"
fern = "^0.6"
fsio = { version = "^0.4", features = ["temp-path"] }
git_info = "^0.1.2"
git_info = { git = "https://github.com/SamuelMarks/git_info", branch = "serde", features = [
Comment thread
SamuelMarks marked this conversation as resolved.
Outdated
"serde",
] }
glob = "^0.3.1"
home = "^0.5"
ignore = "^0.4"
Expand All @@ -67,7 +71,10 @@ once_cell = "^1.19.0"
petgraph = "^0.6.5"
regex = "^1.10"
run_script = "^0.10"
rust_info = "^0.3.1"
# rust_info = "^0.3.1"
rust_info = { git = "https://github.com/SamuelMarks/rust_info", branch = "serde", features = [
Comment thread
SamuelMarks marked this conversation as resolved.
Outdated
"serde",
] }
semver = "^1"
serde = "^1"
serde_derive = "^1"
Expand All @@ -87,7 +94,9 @@ expect-test = "^1"
nu-ansi-term = "^0.50"

[features]
diesel = ["dep:diesel"]
diesel_migrations = ["dep:diesel_migrations"]
tls-rustls = ["duckscriptsdk/tls-rustls"]
tls-native = ["duckscriptsdk/tls-native"]
tls = ["tls-rustls"] # alias for backward compatibility
tls = ["tls-rustls"] # alias for backward compatibility
default = ["tls-rustls"]
26 changes: 20 additions & 6 deletions src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::recursion_level;
use crate::runner;
use crate::time_summary;
use crate::toolchain;
use crate::types::{CliArgs, GlobalConfig};
use crate::types::{CliArgs, Config, EnvInfo, GlobalConfig};
use crate::version;
use std::time::SystemTime;

Expand All @@ -32,11 +32,11 @@ pub(crate) static DEFAULT_LOG_LEVEL: &str = "info";
pub(crate) static DEFAULT_TASK_NAME: &str = "default";
pub(crate) static DEFAULT_OUTPUT_FORMAT: &str = "default";

pub fn run(
cli_args: &CliArgs,
pub fn prepare_for_execution_plan<'a>(
cli_args: &'a CliArgs,
global_config: &GlobalConfig,
logger_options: Option<LoggerOptions>,
) -> Result<(), CargoMakeError> {
) -> Result<(EnvInfo, Config, &'a String, Vec<(String, u128)>, SystemTime), CargoMakeError> {
let start_time = SystemTime::now();

recursion_level::increment();
Expand Down Expand Up @@ -103,7 +103,7 @@ pub fn run(
let experimental = cli_args.experimental;
let config = descriptor::load(&build_file, force_makefile, env, experimental)?;

let mut time_summary_vec = vec![];
let mut time_summary_vec = Vec::<(String, u128)>::new();
time_summary::add(
&mut time_summary_vec,
"[Load Makefiles]",
Expand All @@ -130,6 +130,19 @@ pub fn run(
// ensure profile env was not overridden
profile::set(&normalized_profile_name);

Ok((env_info, config, task, time_summary_vec, start_time))
}

pub fn run(
cli_args: &CliArgs,
global_config: &GlobalConfig,
logger_options: Option<LoggerOptions>,
) -> Result<(), CargoMakeError> {
let (env_info, config, task, time_summary_vec, start_time) =
prepare_for_execution_plan(cli_args, global_config, logger_options)?;

// let execution_plan: ExecutionPlan;

if cli_args.list_all_steps || cli_args.list_category_steps.is_some() {
cli_commands::list_steps::run(
&config,
Expand All @@ -139,7 +152,8 @@ pub fn run(
cli_args.hide_uninteresting,
)
} else if cli_args.diff_execution_plan {
let default_config = descriptor::load_internal_descriptors(true, experimental, None)?;
let default_config =
descriptor::load_internal_descriptors(true, cli_args.experimental, None)?;
cli_commands::diff_steps::run(
&default_config,
&config,
Expand Down
10 changes: 7 additions & 3 deletions src/lib/cli_commands/diff_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ use crate::command;
use crate::error::CargoMakeError;
use crate::execution_plan::ExecutionPlanBuilder;
use crate::io::{create_file, delete_file};
use crate::types::{CliArgs, Config, CrateInfo, ExecutionPlan};
use crate::types::{CliArgs, Config, CrateInfo, ExecutionPlan, SerdeRegex};
use regex::Regex;
use std::fs::File;
use std::io;
use std::io::{BufWriter, Write};

fn write_as_string(execution_plan: &ExecutionPlan, file: &File) -> io::Result<()> {
let mut writer = BufWriter::new(file);
writeln!(&mut writer, "{:#?}", &execution_plan.steps)
writeln!(
&mut writer,
"{:#?}",
&execution_plan.steps[execution_plan.steps_to_run.clone()]
)
}

/// Runs the execution plan diff
Expand All @@ -32,7 +36,7 @@ pub(crate) fn run(
) -> Result<(), CargoMakeError> {
let skip_tasks_pattern = match cli_args.skip_tasks_pattern {
Some(ref pattern) => match Regex::new(pattern) {
Ok(reg) => Some(reg),
Ok(reg) => Some(SerdeRegex(reg)),
Err(_) => {
warn!("Invalid skip tasks pattern provided: {}", pattern);
None
Expand Down
23 changes: 18 additions & 5 deletions src/lib/cli_commands/print_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::error::CargoMakeError;
use std::io;

use crate::execution_plan::ExecutionPlanBuilder;
use crate::types::{Config, CrateInfo, ExecutionPlan};
use crate::types::{Config, CrateInfo, ExecutionPlan, SerdeRegex};
use regex::Regex;

#[derive(Debug)]
Expand Down Expand Up @@ -50,7 +50,7 @@ fn print_short_description(
execution_plan: &ExecutionPlan,
) -> io::Result<()> {
let mut counter = 1;
for step in &execution_plan.steps {
for step in &execution_plan.steps[execution_plan.steps_to_run.clone()] {
let task = &step.config;
let description = match &task.description {
Some(value) => value,
Expand All @@ -62,7 +62,7 @@ fn print_short_description(
counter, &step.name, &description
)?;

counter = counter + 1;
counter += 1;
}
Ok(())
}
Expand All @@ -71,7 +71,20 @@ fn print_default(
output_buffer: &mut impl io::Write,
execution_plan: &ExecutionPlan,
) -> io::Result<()> {
writeln!(output_buffer, "{:#?}", &execution_plan)
let steps: Vec<crate::types::Step> = {
let mut _steps =
Vec::<crate::types::Step>::with_capacity(execution_plan.steps_to_run.len());
execution_plan.steps[execution_plan.steps_to_run.clone()].clone_into(&mut _steps);
_steps
};
writeln!(
output_buffer,
"{:#?}",
ExecutionPlan {
steps,
..ExecutionPlan::default()
}
)
}

/// Only prints the execution plan
Expand All @@ -87,7 +100,7 @@ pub fn print(
) -> Result<(), CargoMakeError> {
let skip_tasks_pattern_regex = match skip_tasks_pattern {
Some(ref pattern) => match Regex::new(pattern) {
Ok(reg) => Some(reg),
Ok(reg) => Some(SerdeRegex(reg)),
Err(_) => {
warn!("Invalid skip tasks pattern provided: {}", pattern);
None
Expand Down
4 changes: 2 additions & 2 deletions src/lib/cli_commands/print_steps_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn print_default_valid() {
config: Task::new(),
};
let steps = vec![step];
let execution_plan = ExecutionPlan { steps };
let execution_plan = ExecutionPlan::new(steps);

print_default(&mut std::io::stdout(), &execution_plan).expect("print should succeed");
}
Expand All @@ -122,7 +122,7 @@ fn print_short_description_valid() {
config: Task::new(),
};
let steps = vec![step];
let execution_plan = ExecutionPlan { steps };
let execution_plan = ExecutionPlan::new(steps);

print_short_description(&mut std::io::stdout(), &execution_plan).expect("print should succeed");
}
Expand Down
49 changes: 49 additions & 0 deletions src/lib/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub enum CargoMakeError {
#[strum(to_string = "Task {0:#?} is {1}")]
TaskIs(String, &'static str) = 110,

#[strum(to_string = "Task error detected, exit code: {0}")]
TaskErrorExitCode(i32) = 111,

#[strum(to_string = "{0}")]
NotFound(String) = 404,

Expand All @@ -55,6 +58,24 @@ pub enum CargoMakeError {
#[strum(to_string = "`std::io::Error` error. {error:?}")]
StdIoError { error: std::io::Error } = 700,

#[cfg(feature = "diesel")]
#[strum(to_string = "`diesel::result::Error` error. {error:?}")]
DieselError { error: diesel::result::Error } = 705,

#[cfg(feature = "diesel")]
#[strum(to_string = "`diesel::r2d2::Error` error. {error:?}")]
DieselR2d2Error { error: diesel::r2d2::Error } = 706,

#[cfg(feature = "diesel_migrations")]
#[strum(to_string = "`diesel_migrations::MigrationError` error. {error:?}")]
DieselMigrationError {
error: diesel_migrations::MigrationError,
} = 707,

#[cfg(feature = "diesel")]
#[strum(to_string = "`r2d2::Error` error. {error:?}")]
R2d2Error { error: diesel::r2d2::PoolError } = 708,

#[strum(to_string = "`std::fmt::Error` error. {error:?}")]
StdFmtError { error: std::fmt::Error } = 709,

Expand Down Expand Up @@ -130,6 +151,34 @@ impl std::process::Termination for CargoMakeError {
}
}

#[cfg(feature = "diesel")]
impl From<diesel::result::Error> for CargoMakeError {
fn from(error: diesel::result::Error) -> Self {
Self::DieselError { error }
}
}

#[cfg(feature = "diesel")]
impl From<diesel::r2d2::Error> for CargoMakeError {
fn from(error: diesel::r2d2::Error) -> Self {
Self::DieselR2d2Error { error }
}
}

#[cfg(feature = "diesel")]
impl From<diesel::r2d2::PoolError> for CargoMakeError {
fn from(error: diesel::r2d2::PoolError) -> Self {
Self::R2d2Error { error }
}
}

#[cfg(feature = "diesel_migrations")]
impl From<diesel_migrations::MigrationError> for CargoMakeError {
fn from(error: diesel_migrations::MigrationError) -> Self {
Self::DieselMigrationError { error }
}
}

pub enum SuccessOrCargoMakeError<T> {
Ok(T),
Err(CargoMakeError),
Expand Down
14 changes: 7 additions & 7 deletions src/lib/execution_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use crate::logger;
use crate::profile;
use crate::proxy_task::create_proxy_task;
use crate::types::{
Config, CrateInfo, EnvValue, ExecutionPlan, ScriptValue, Step, Task, TaskIdentifier, Workspace,
Config, CrateInfo, EnvValue, ExecutionPlan, ScriptValue, SerdeRegex, Step, Task,
TaskIdentifier, Workspace,
};
use fsio::path::{get_basename, get_parent_directory};
use glob::Pattern;
use indexmap::IndexMap;
use regex::Regex;
use std::collections::HashSet;
use std::env;
use std::path::Path;
Expand Down Expand Up @@ -342,10 +342,10 @@ fn create_for_step(
task_names: &mut HashSet<String>,
root: bool,
allow_private: bool,
skip_tasks_pattern: Option<&Regex>,
skip_tasks_pattern: Option<&SerdeRegex>,
) -> Result<(), CargoMakeError> {
if let Some(skip_tasks_pattern_regex) = skip_tasks_pattern {
if skip_tasks_pattern_regex.is_match(&task.name) {
if skip_tasks_pattern_regex.0.is_match(&task.name) {
debug!("Skipping task: {} due to skip pattern.", &task.name);
return Ok(());
}
Expand Down Expand Up @@ -452,7 +452,7 @@ pub(crate) struct ExecutionPlanBuilder<'a> {
pub disable_workspace: bool,
pub allow_private: bool,
pub sub_flow: bool,
pub skip_tasks_pattern: Option<&'a Regex>,
pub skip_tasks_pattern: Option<&'a SerdeRegex>,
pub skip_init_end_tasks: bool,
}

Expand Down Expand Up @@ -507,7 +507,7 @@ impl<'a> ExecutionPlanBuilder<'a> {
}

let skip = match skip_tasks_pattern {
Some(pattern) => pattern.is_match(task),
Some(pattern) => pattern.0.is_match(task),
None => false,
};

Expand Down Expand Up @@ -549,6 +549,6 @@ impl<'a> ExecutionPlanBuilder<'a> {
};
}

Ok(ExecutionPlan { steps })
Ok(ExecutionPlan::new(steps))
}
}
Loading