Skip to content

Commit

Permalink
remove requirement and version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLaPiana committed Dec 30, 2023
1 parent ce67f02 commit f61f602
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 378 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ clap = { version = "4.4.4", features = ["string", "cargo"] }
cli-table = "0.4.7"
colored = "2.0.4"
rayon = "1.8.0"
semver = "1.0.18"
serde = { version = "1.0.188", features = ["derive"] }
serde_yaml = "0.9.25"

Expand Down
11 changes: 0 additions & 11 deletions roxfile.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
version_requirements:
- command: "cargo nextest --version"
minimum_version: "0.9.0"
split: true

file_requirements:
- path: "Cargo.toml"

- path: ".env"
create_if_not_exists: true

templates:
- name: docker_build
command: "docker build {path} -t rox:{image_tag}"
Expand Down
35 changes: 0 additions & 35 deletions src/file_requirements.rs

This file was deleted.

19 changes: 0 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
mod cli;
mod execution;
mod file_requirements;
mod model_injection;
pub mod models;
mod output;
mod utils;
mod version_requirements;

use crate::cli::{cli_builder, construct_cli};
use crate::execution::{execute_stages, execute_tasks};
Expand Down Expand Up @@ -51,23 +49,6 @@ pub fn rox() -> RoxResult<()> {
let cli = construct_cli(&tasks, &pipelines);
let cli_matches = cli.get_matches();

// Run File and Version checks
if !cli_matches.get_flag("skip-checks") {
// Check Versions
if roxfile.version_requirements.is_some() {
for version_check in roxfile.version_requirements.into_iter().flatten() {
version_requirements::check_version(version_check);
}
}

// Check Files
if roxfile.file_requirements.is_some() {
for requirement in roxfile.file_requirements.into_iter().flatten() {
file_requirements::handle_file_requirement(requirement);
}
}
}

// Build Hashmaps for Tasks, Templates and Pipelines
let template_map: HashMap<String, models::Template> = std::collections::HashMap::from_iter(
roxfile
Expand Down
90 changes: 1 addition & 89 deletions src/models.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
//! Contains the Structs for the Schema of the Roxfile
//! as well as the validation logic.
use semver::{Version, VersionReq};
use crate::utils::{color_print, ColorEnum};
use serde::{Deserialize, Serialize};
use std::error::Error;
use std::fmt;
use std::str::FromStr;

use crate::utils::{color_print, ColorEnum};

/// Format for completed executions
#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -62,82 +59,6 @@ pub trait Validate {
fn validate(&self) -> Result<(), ValidationError>;
}

/// Schema for Version Requirement Checks
///
/// Runs the specified commands and checks that
/// output is a valid version that falls within
/// the defined minimum and maximum allowed versions.
#[derive(Deserialize, Debug, Clone, Default)]
#[serde(deny_unknown_fields)]
pub struct VersionRequirement {
pub command: String,
pub minimum_version: Option<String>,
pub maximum_version: Option<String>,
pub split: Option<bool>, // TODO: Make this name more clear, or let the user choose with item to take after split
}
impl Validate for VersionRequirement {
fn validate(&self) -> Result<(), ValidationError> {
let failure_message = format!(
"> Version Requirement '{}' failed validation!",
self.command
);

// Versions must be valid Semantic Versions
let versions: Vec<&String> = vec![&self.minimum_version, &self.maximum_version]
.into_iter()
.flatten()
.collect();
for version in versions.iter() {
if Version::from_str(version).is_err() {
color_print(vec![failure_message], ColorEnum::Red);
return Err(ValidationError {
message: "Mininum and Maximum versions must be valid semantic version!"
.to_owned(),
});
}
}

// Make sure that the Maximum version isn't smaller than the Minimum version
if self.maximum_version.is_some() && self.maximum_version.is_some() {
let valid_version_constraints =
VersionReq::from_str(&format!("> {}", self.minimum_version.as_ref().unwrap()))
.unwrap()
.matches(&Version::from_str(self.maximum_version.as_ref().unwrap()).unwrap());

if !valid_version_constraints {
color_print(vec![failure_message], ColorEnum::Red);
return Err(ValidationError {
message: "The Minimum version cannot be larger than the Maximum version!"
.to_owned(),
});
}
}

// If Split is Some, either Min or Max Version must be Some
if self.split.is_some() && versions.is_empty() {
color_print(vec![failure_message], ColorEnum::Red);
return Err(ValidationError {
message: "If 'split' is defined, either a 'minimum_version' or a 'maximum_version' is also required!"
.to_owned(),
});
}

Ok(())
}
}

/// Schema for File Requirement Checks
///
/// This verifies that the file exists locally,
/// or can be configured to create the file
/// if its missing.
#[derive(Deserialize, Debug, Clone, Default)]
#[serde(deny_unknown_fields)]
pub struct FileRequirement {
pub path: String,
pub create_if_not_exists: Option<bool>,
}

/// Schema for Tasks in the Roxfile
///
/// Tasks are discrete units of execution
Expand Down Expand Up @@ -241,8 +162,6 @@ pub struct Pipeline {
#[derive(Deserialize, Debug, Default, Clone)]
#[serde(deny_unknown_fields)]
pub struct RoxFile {
pub version_requirements: Option<Vec<VersionRequirement>>,
pub file_requirements: Option<Vec<FileRequirement>>,
pub tasks: Vec<Task>,
pub pipelines: Option<Vec<Pipeline>>,
pub templates: Option<Vec<Template>>,
Expand All @@ -263,13 +182,6 @@ impl Validate for RoxFile {
}
}

// Version Requirement Validation
if let Some(version_requirements) = &self.version_requirements {
for requirement in version_requirements {
requirement.validate()?
}
}

Ok(())
}
}
24 changes: 0 additions & 24 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,3 @@ where
pub fn print_horizontal_rule() {
println!("-------------------------------------------");
}

/// Split a string on spaces and return the head + the remainder
pub fn split_head_from_rest(snek: &str) -> (String, Vec<String>) {
let mut split_snek = snek.split(' ');
let head: String = split_snek.next().unwrap().to_owned();
let remainder: Vec<String> = split_snek.map(|x| x.to_owned()).collect();
(head, remainder)
}

#[test]
fn split_head_valid() {
assert_eq!(
(
"Foo".to_string(),
vec!["Bar".to_string(), "Baz".to_string()]
),
split_head_from_rest("Foo Bar Baz")
);
}

#[test]
fn split_head_single() {
assert_eq!(("Foo".to_string(), vec![]), split_head_from_rest("Foo"));
}
128 changes: 0 additions & 128 deletions src/version_requirements.rs

This file was deleted.

Loading

0 comments on commit f61f602

Please sign in to comment.