From 009c1f1b388e3163d7c76f30bd82273d4918af73 Mon Sep 17 00:00:00 2001 From: QIUZHILEI <2925212608@qq.com> Date: Tue, 25 Jul 2023 15:59:45 +0800 Subject: [PATCH 1/4] Remove the function of executing js command and use system command to execute any type of script Signed-off-by: QIUZHILEI <2925212608@qq.com> --- Cargo.toml | 1 - README.md | 41 ++++-------- examples/custom_parser.rs | 42 +++++------- examples/engine.rs | 2 +- src/lib.rs | 3 +- src/parser/error.rs | 9 --- src/parser/mod.rs | 80 +++++++++-------------- src/parser/yaml_parser.rs | 48 ++++---------- src/task/cmd.rs | 53 +++++++++++++++ src/task/error.rs | 29 ++------- src/task/mod.rs | 94 +++++++++++---------------- tests/config/correct.yaml | 32 +++------ tests/config/custom_file_task.txt | 16 ++--- tests/config/illegal_content.yaml | 4 +- tests/config/loop_error.yaml | 20 ++---- tests/config/no_script.yaml | 4 +- tests/config/no_start_with_dagrs.yaml | 32 +++------ tests/config/no_task_name.yaml | 4 +- tests/config/precursor_not_found.yaml | 4 +- tests/config/script_run_failed.yaml | 32 +++------ tests/config/self_loop_error.yaml | 4 +- tests/config/test.js | 1 + tests/config/test.py | 1 + tests/config/test.sh | 1 + tests/yaml_parser_test.rs | 18 ----- 25 files changed, 215 insertions(+), 360 deletions(-) create mode 100644 src/task/cmd.rs create mode 100644 tests/config/test.js create mode 100644 tests/config/test.py create mode 100644 tests/config/test.sh diff --git a/Cargo.toml b/Cargo.toml index 276151a..4ffec4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ keywords = ["DAG", "task", "async", "parallel", "concurrent"] [dependencies] yaml-rust = "0.4.5" bimap = "0.6.1" -deno_core = "0.191.0" clap = { version = "4.2.2", features = ["derive"] } anymap2 = "0.13.0" thiserror = "1.0.30" diff --git a/README.md b/README.md index b72afb4..8eeb7e9 100644 --- a/README.md +++ b/README.md @@ -136,9 +136,7 @@ Task executed successfully. [name: Task d] Process finished with exit code 0 ``` - - -### Yaml configuration file +### `Yaml` configuration file A standard yaml configuration file format is given below: @@ -147,50 +145,34 @@ dagrs: a: name: "Task 1" after: [ b, c ] - run: - type: sh - script: echo a + cmd: echo a b: name: "Task 2" after: [ c, f, g ] - run: - type: sh - script: echo b + cmd: echo b c: name: "Task 3" after: [ e, g ] - run: - type: sh - script: echo c + cmd: echo c d: name: "Task 4" after: [ c, e ] - run: - type: sh - script: echo d + cmd: echo d e: name: "Task 5" after: [ h ] - run: - type: sh - script: echo e + cmd: echo e f: name: "Task 6" after: [ g ] - run: - type: deno - script: Deno.core.print("f\n") + cmd: python3 ./tests/config/test.py g: name: "Task 7" after: [ h ] - run: - type: deno - script: Deno.core.print("g\n") + cmd: deno run ./tests/config/test.js h: name: "Task 8" - run: - type: sh - script: echo h + cmd: echo h ``` These yaml-defined task items form a complex dependency graph. In the yaml configuration file: @@ -199,7 +181,8 @@ These yaml-defined task items form a complex dependency graph. In the yaml confi - Similar to `a`, `b`, `c`... is the unique identifier of the task - `name` is a required attribute, which is the name of the task - `after` is an optional attribute (only the first executed task does not have this attribute), which represents which tasks are executed after the task, that is, specifies dependencies for tasks -- `run` is a required attribute, followed by `type` and `script`, they are all required attributes, where `type` represents the type of task. The framework provides default implementations of the `Action` trait for two types of script tasks, namely sh and javascript. If users want to customize other types of script tasks, or implement their own script execution logic, they can implement the `Action` trait by programming. Although this is cumbersome, this method will be more flexible. In addition, when parsing the configuration file, the user also needs to provide the parser with a specific type that implements the `Action` trait, and the method should be in the form of a key-value pair: +- `cmd` is a optional attribute. You need to point out the command to be executed, such as the basic shell command: `echo hello`, execute the python script `python test.py`, etc. The user must ensure that the interpreter that executes the script exists in the environment variable. `CommandAction` is the implementation of the specific execution logic of the script, which is put into a specific `Task` type. + If users want to customize other types of script tasks, or implement their own script execution logic, they can implement the "Action" feature through programming, and when parsing the configuration file, provide the parser with a specific type that implements the `Action` feature, and the method should be in the form of a key-value pair: . Although this is more troublesome, this method will be more flexible. To parse the yaml configured file, you need to compile this project, requiring rust version >= 1.70: @@ -230,9 +213,7 @@ $./target/release/dagrs --yaml=./tests/config/correct.yaml --log-path=./dagrs.lo Executing Task[name: Task 8] Executing Task[name: Task 5] Executing Task[name: Task 7] -g Executing Task[name: Task 6] -f Executing Task[name: Task 3] Executing Task[name: Task 2] Executing Task[name: Task 4] diff --git a/examples/custom_parser.rs b/examples/custom_parser.rs index e202266..c00b436 100644 --- a/examples/custom_parser.rs +++ b/examples/custom_parser.rs @@ -2,14 +2,14 @@ //! The content of the configuration file is as follows: //! //! ``` -//! a,Task a,b c,sh,echo a -//! b,Task b,c f g,sh,echo b -//! c,Task c,e g,sh,echo c -//! d,Task d,c e,sh,echo d -//! e,Task e,h,sh,echo e -//! f,Task f,g,deno,Deno.core.print("f\n") -//! g,Task g,h,deno,Deno.core.print("g\n") -//! h,Task h,,sh,echo h +//! a,Task a,b c,echo a +//! b,Task b,c f g,echo b +//! c,Task c,e g,echo c +//! d,Task d,c e,echo d +//! e,Task e,h,echo e +//! f,Task f,g,python3 tests/config/test.py +//! g,Task g,h,deno run tests/config/test.js +//! h,Task h,,echo h //! ``` extern crate dagrs; @@ -18,7 +18,7 @@ use std::{fs, sync::Arc}; use std::collections::HashMap; use std::fmt::{Display, Formatter}; -use dagrs::{Action, Dag, log,LogLevel, JavaScript, Parser, ParserError, ShScript, Task}; +use dagrs::{Action, Dag, log,LogLevel, Parser, ParserError, CommandAction, Task}; struct MyTask { tid: (String, usize), @@ -99,23 +99,13 @@ impl ConfigParser { let id = *attr.get(0).unwrap(); let name = attr.get(1).unwrap().to_string(); - let script = *attr.get(4).unwrap(); - let t_type = *attr.get(3).unwrap(); - if t_type.eq("sh") { - MyTask::new( - id, - pres, - name, - ShScript::new(script), - ) - } else { - MyTask::new( - id, - pres, - name, - JavaScript::new(script), - ) - } + let cmd = *attr.get(3).unwrap(); + MyTask::new( + id, + pres, + name, + CommandAction::new(cmd), + ) } } diff --git a/examples/engine.rs b/examples/engine.rs index e26cd42..6893e13 100644 --- a/examples/engine.rs +++ b/examples/engine.rs @@ -9,7 +9,7 @@ use dagrs::{ }; fn main() { // initialization log. - log::init_logger(LogLevel::Error, None); + log::init_logger(LogLevel::Info, None); // Create an Engine. let mut engine = Engine::default(); diff --git a/src/lib.rs b/src/lib.rs index 21b662c..650a8a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,11 @@ extern crate anymap2; extern crate bimap; extern crate clap; -extern crate deno_core; extern crate yaml_rust; pub use engine::{Dag, DagError, Engine}; pub use parser::*; -pub use task::{Action, DefaultTask, alloc_id, Input, JavaScript, Output, RunningError, ShScript, Task, YamlTask}; +pub use task::{Action, DefaultTask, alloc_id, Input, Output, RunningError, CommandAction, Task, YamlTask}; pub use utils::{EnvVar, gen_macro,LogLevel,Logger,log}; mod engine; diff --git a/src/parser/error.rs b/src/parser/error.rs index 56989ef..ab3216a 100644 --- a/src/parser/error.rs +++ b/src/parser/error.rs @@ -37,15 +37,6 @@ pub enum YamlTaskError { /// The specified task predecessor was not found. #[error("Task cannot find the specified predecessor. [{0}]")] NotFoundPrecursor(String), - /// `run` is not defined. - #[error("The 'run' attribute is not defined. [{0}]")] - NoRunAttr(String), - /// `type` is not defined. - #[error("The 'type' attribute is not defined. [{0}]")] - NoTypeAttr(String), - /// Unsupported script type. - #[error("Unsupported script type [{0}]")] - UnsupportedType(String), /// `script` is not defined. #[error("The 'script' attribute is not defined. [{0}]")] NoScriptAttr(String), diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 659eafb..5f798e5 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -14,56 +14,40 @@ //! # The basic format of the yaml configuration file is as follows: //! ```yaml //! dagrs: -//! a: -//! name: "Task 1" -//! after: [b, c] -//! run: -//! type: sh -//! script: echo a -//! b: -//! name: "Task 2" -//! after: [c, f, g] -//! run: -//! type: sh -//! script: echo b -//! c: -//! name: "Task 3" -//! after: [e, g] -//! run: -//! type: sh -//! script: echo c -//! d: -//! name: "Task 4" -//! after: [c, e] -//! run: -//! type: sh -//! script: echo d -//! e: -//! name: "Task 5" -//! after: [h] -//! run: -//! type: sh -//! script: echo e -//! f: -//! name: "Task 6" -//! after: [g] -//! run: -//! type: deno -//! script: Deno.core.print("f\n") -//! g: -//! name: "Task 7" -//! after: [h] -//! run: -//! type: deno -//! script: Deno.core.print("g\n") -//! h: -//! name: "Task 8" -//! run: -//! type: sh -//! script: echo h +//! a: +//! name: "Task 1" +//! after: [ b, c ] +//! cmd: echo a +//! b: +//! name: "Task 2" +//! after: [ c, f, g ] +//! cmd: echo b +//! c: +//! name: "Task 3" +//! after: [ e, g ] +//! cmd: echo c +//! d: +//! name: "Task 4" +//! after: [ c, e ] +//! cmd: echo d +//! e: +//! name: "Task 5" +//! after: [ h ] +//! cmd: echo e +//! f: +//! name: "Task 6" +//! after: [ g ] +//! cmd: python3 ./tests/config/test.py +//! g: +//! name: "Task 7" +//! after: [ h ] +//! cmd: deno run ./tests/config/test.js +//! h: +//! name: "Task 8" +//! cmd: echo h //! ``` //! -//! Currently, the framework supports sh and javascript script task types by default. If users +//! Users can execute arbitrary commands of the operating system. If users //! want to run other types of script tasks, they need to implement the [`Action`] trait by themselves, //! and before parsing the configuration file, they need to provide a specific type that implements //! the [`Action`] trait in the form of key-value pairs: . diff --git a/src/parser/yaml_parser.rs b/src/parser/yaml_parser.rs index 57f65c2..7432ae1 100644 --- a/src/parser/yaml_parser.rs +++ b/src/parser/yaml_parser.rs @@ -5,7 +5,7 @@ use std::{collections::HashMap, fs::File, io::Read, sync::Arc}; use yaml_rust::{Yaml, YamlLoader}; use crate::{ - task::{JavaScript, ShScript, Task, YamlTask}, + task::{CommandAction, Task, YamlTask}, Action, }; @@ -54,43 +54,19 @@ impl YamlParser { .map(|task_id| precursors.push(task_id.as_str().unwrap().to_owned())) .count(); } - // Get run script - let run = &item["run"]; - if run.is_badvalue() { - return Err(YamlTaskError::NoRunAttr(name)); - } - let script_type = run["type"] - .as_str() - .ok_or(YamlTaskError::NoTypeAttr(name.clone()))?; - + if let Some(action) = specific_action { Ok(YamlTask::new(id, precursors, name, action)) } else { - match script_type { - "sh" => { - let sh_script = run["script"] - .as_str() - .ok_or(YamlTaskError::NoScriptAttr(name.clone()))?; - Ok(YamlTask::new( - id, - precursors, - name, - Arc::new(ShScript::new(sh_script)) as Arc, - )) - } - "deno" => { - let js_script = run["script"] - .as_str() - .ok_or(YamlTaskError::NoScriptAttr(name.clone()))?; - Ok(YamlTask::new( - id, - precursors, - name, - Arc::new(JavaScript::new(js_script)) as Arc, - )) - } - _ => Err(YamlTaskError::UnsupportedType(name)), - } + let cmd = item["cmd"] + .as_str() + .ok_or(YamlTaskError::NoScriptAttr(name.clone()))?; + Ok(YamlTask::new( + id, + precursors, + name, + Arc::new(CommandAction::new(cmd)) as Arc, + )) } } } @@ -99,7 +75,7 @@ impl Parser for YamlParser { fn parse_tasks( &self, file: &str, - mut specific_actions: HashMap>, + mut specific_actions: HashMap>, ) -> Result>, ParserError> { let content = self.load_file(file)?; // Parse Yaml diff --git a/src/task/cmd.rs b/src/task/cmd.rs new file mode 100644 index 0000000..52a5ecd --- /dev/null +++ b/src/task/cmd.rs @@ -0,0 +1,53 @@ +//! OS command `Action`. +//! +//! # `cmd` attribute command wrapper. +//! +//! Specify the command to be executed in the `cmd` attribute of the `yaml` configuration +//! file, and the `Yaml` parser will package the command as a `CommandAction`, which implements +//! the `Action` trait and defines the specific logic of executing the command. + +use std::{process::Command, sync::Arc}; + +use crate::{log, utils::EnvVar}; + +use super::{Action, CmdExecuteError, Input, Output, RunningError}; + +/// Can be used to run a command. +pub struct CommandAction { + command: String, +} + +impl CommandAction { + pub fn new(cmd: &str) -> Self { + Self { + command: cmd.to_owned(), + } + } +} + +impl Action for CommandAction { + fn run(&self, input: Input, _env: Arc) -> Result { + let mut args = Vec::new(); + let mut cmd = if cfg!(target_os = "windows") { + args.push("/c"); + Command::new("cmd") + } else { + args.push("-c"); + Command::new("sh") + }; + args.push(&self.command); + input.get_iter().for_each(|input| { + if let Some(inp) = input.get::() { + args.push(inp) + } + }); + let out = cmd.args(args).output().unwrap(); + if !out.stderr.is_empty() { + let err_msg = String::from_utf8(out.stderr).unwrap(); + log::error(err_msg.clone()); + Err(CmdExecuteError::new(err_msg).into()) + } else { + Ok(Output::new(String::from_utf8(out.stdout).unwrap())) + } + } +} diff --git a/src/task/error.rs b/src/task/error.rs index 821ad95..c9e6e77 100644 --- a/src/task/error.rs +++ b/src/task/error.rs @@ -14,21 +14,12 @@ pub struct RunningError { msg: String, } -/// Sh script produces incorrect behavior when run. +/// command produces incorrect behavior when run. #[derive(Error, Debug)] -pub struct ShExecuteError { +pub struct CmdExecuteError { msg: String, } -/// Javascript script produces incorrect behavior when run. -#[derive(Error, Debug)] -pub enum JavaScriptExecuteError { - #[error("{0}")] - AnyHowError(deno_core::anyhow::Error), - #[error("{0}")] - SerializeError(deno_core::serde_v8::Error), -} - impl RunningError { pub fn new(msg: String) -> Self { Self { msg } @@ -46,26 +37,20 @@ impl Display for RunningError { } } -impl ShExecuteError { +impl CmdExecuteError { pub fn new(msg: String) -> Self { Self { msg } } } -impl Display for ShExecuteError { +impl Display for CmdExecuteError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "sh script execution error: {}", self.msg) - } -} - -impl From for RunningError { - fn from(value: ShExecuteError) -> Self { - RunningError { msg: value.to_string() } + write!(f, "cmd execution error: {}", self.msg) } } -impl From for RunningError { - fn from(value: JavaScriptExecuteError) -> Self { +impl From for RunningError { + fn from(value: CmdExecuteError) -> Self { RunningError { msg: value.to_string() } } } diff --git a/src/task/mod.rs b/src/task/mod.rs index db3e20e..ff4ad35 100644 --- a/src/task/mod.rs +++ b/src/task/mod.rs @@ -3,69 +3,49 @@ //! # Task execution mode of the Dag engine //! //! Currently, the Dag execution engine has two execution modes: -//! The first mode is to execute tasks through user-written yaml configuration file, -//! and then hand them over to the dag engine for execution. Currently, the yaml -//! configuration file supports two types of tasks, one is to execute sh scripts, -//! and the other is to execute javascript scripts. +//! The first mode is to execute tasks through user-written yaml configuration file, and then +//! hand them over to the dag engine for execution. The command to be executed can be specified in yaml. //! //!# The basic format of the yaml configuration file is as follows: //! ```yaml //! dagrs: -//! a: -//! name: "Task 1" -//! after: [b, c] -//! run: -//! type: sh -//! script: echo a -//! b: -//! name: "Task 2" -//! after: [c, f, g] -//! run: -//! type: sh -//! script: echo b -//! c: -//! name: "Task 3" -//! after: [e, g] -//! run: -//! type: sh -//! script: echo c -//! d: -//! name: "Task 4" -//! after: [c, e] -//! run: -//! type: sh -//! script: echo d -//! e: -//! name: "Task 5" -//! after: [h] -//! run: -//! type: sh -//! script: echo e -//! f: -//! name: "Task 6" -//! after: [g] -//! run: -//! type: deno -//! script: Deno.core.print("f\n") -//! g: -//! name: "Task 7" -//! after: [h] -//! run: -//! type: deno -//! script: Deno.core.print("g\n") -//! h: -//! name: "Task 8" -//! run: -//! type: sh -//! script: sh_script.sh +//! a: +//! name: "Task 1" +//! after: [ b, c ] +//! cmd: echo a +//! b: +//! name: "Task 2" +//! after: [ c, f, g ] +//! cmd: echo b +//! c: +//! name: "Task 3" +//! after: [ e, g ] +//! cmd: echo c +//! d: +//! name: "Task 4" +//! after: [ c, e ] +//! cmd: echo d +//! e: +//! name: "Task 5" +//! after: [ h ] +//! cmd: echo e +//! f: +//! name: "Task 6" +//! after: [ g ] +//! cmd: python3 ./tests/config/test.py +//! g: +//! name: "Task 7" +//! after: [ h ] +//! cmd: deno run ./tests/config/test.js +//! h: +//! name: "Task 8" +//! cmd: echo h //! ``` //! The necessary attributes for tasks in the yaml configuration file are: //! id: unique identifier, such as 'a' //! name: task name //! after: Indicates which task to execute after, this attribute is optional -//! run: -//! type: sh or deno -//! script: command or file path +//! cmd: command to execute, such as 'ls ./' //! //! //! The second mode is that the user program defines the task, which requires the @@ -116,14 +96,14 @@ use std::sync::atomic::AtomicUsize; use crate::utils::EnvVar; -pub use self::error::{RunningError,JavaScriptExecuteError,ShExecuteError}; -pub use self::script::{JavaScript,ShScript}; +pub use self::error::{RunningError,CmdExecuteError}; +pub use self::cmd::CommandAction; pub use self::specific_task::YamlTask; pub use self::state::{Output,Input}; pub(crate) use self::state::ExecState; mod error; -mod script; +mod cmd; mod specific_task; mod state; diff --git a/tests/config/correct.yaml b/tests/config/correct.yaml index 6f8b1c6..e05aefb 100644 --- a/tests/config/correct.yaml +++ b/tests/config/correct.yaml @@ -2,47 +2,31 @@ dagrs: a: name: "Task 1" after: [ b, c ] - run: - type: sh - script: echo a + cmd: echo a b: name: "Task 2" after: [ c, f, g ] - run: - type: sh - script: echo b + cmd: echo b c: name: "Task 3" after: [ e, g ] - run: - type: sh - script: echo c + cmd: echo c d: name: "Task 4" after: [ c, e ] - run: - type: sh - script: echo d + cmd: echo d e: name: "Task 5" after: [ h ] - run: - type: sh - script: echo e + cmd: echo e f: name: "Task 6" after: [ g ] - run: - type: deno - script: Deno.core.print("f\n") + cmd: python3 ./tests/config/test.py g: name: "Task 7" after: [ h ] - run: - type: deno - script: Deno.core.print("g\n") + cmd: deno run ./tests/config/test.js h: name: "Task 8" - run: - type: sh - script: echo h \ No newline at end of file + cmd: echo h \ No newline at end of file diff --git a/tests/config/custom_file_task.txt b/tests/config/custom_file_task.txt index 0d7129b..75b0ec3 100644 --- a/tests/config/custom_file_task.txt +++ b/tests/config/custom_file_task.txt @@ -1,8 +1,8 @@ -a,Task a,b c,sh,echo a -b,Task b,c f g,sh,echo b -c,Task c,e g,sh,echo c -d,Task d,c e,sh,echo d -e,Task e,h,sh,echo e -f,Task f,g,deno,Deno.core.print("f\n") -g,Task g,h,deno,Deno.core.print("g\n") -h,Task h,,sh,echo h \ No newline at end of file +a,Task a,b c,echo a +b,Task b,c f g,echo b +c,Task c,e g,echo c +d,Task d,c e,echo d +e,Task e,h,echo e +f,Task f,g,python3 tests/config/test.py +g,Task g,h,deno run tests/config/test.js +h,Task h,,echo h \ No newline at end of file diff --git a/tests/config/illegal_content.yaml b/tests/config/illegal_content.yaml index 0f9f560..1bc5c30 100644 --- a/tests/config/illegal_content.yaml +++ b/tests/config/illegal_content.yaml @@ -1,6 +1,4 @@ dagrs: a: name:"Task a" - run: - type: sh - script: sh_script.sh \ No newline at end of file + cmd: sh_script.sh \ No newline at end of file diff --git a/tests/config/loop_error.yaml b/tests/config/loop_error.yaml index b632029..36eb887 100644 --- a/tests/config/loop_error.yaml +++ b/tests/config/loop_error.yaml @@ -2,30 +2,20 @@ dagrs: a: name: "Task 1" after: [ b, c ] - run: - type: sh - script: echo x + cmd: echo x b: name: "Task 2" after: [ c ] - run: - type: sh - script: echo x + cmd: echo x c: name: "Task 3" after: [ d ] - run: - type: sh - script: echo x + cmd: echo x d: name: "Task 4" after: [ e ] - run: - type: sh - script: echo x + cmd: echo x e: name: "Task 5" after: [ c ] - run: - type: sh - script: echo x \ No newline at end of file + cmd: echo x \ No newline at end of file diff --git a/tests/config/no_script.yaml b/tests/config/no_script.yaml index f795e4a..0287fd4 100644 --- a/tests/config/no_script.yaml +++ b/tests/config/no_script.yaml @@ -1,6 +1,4 @@ dagrs: a: name: "Task 1" - run: - type: sh - \ No newline at end of file + \ No newline at end of file diff --git a/tests/config/no_start_with_dagrs.yaml b/tests/config/no_start_with_dagrs.yaml index acedaf7..c4a64e6 100644 --- a/tests/config/no_start_with_dagrs.yaml +++ b/tests/config/no_start_with_dagrs.yaml @@ -1,47 +1,31 @@ a: name: "Task 1" after: [ b, c ] - run: - type: sh - script: echo a + cmd: echo a b: name: "Task 2" after: [ c, f, g ] - run: - type: sh - script: echo b + cmd: echo b c: name: "Task 3" after: [ e, g ] - run: - type: sh - script: echo c + cmd: echo c d: name: "Task 4" after: [ c, e ] - run: - type: sh - script: echo d + cmd: echo d e: name: "Task 5" after: [ h ] - run: - type: sh - script: echo e + cmd: echo e f: name: "Task 6" after: [ g ] - run: - type: deno - script: Deno.core.print("f\n") + cmd: python3 ./test.py g: name: "Task 7" after: [ h ] - run: - type: deno - script: Deno.core.print("g\n") + cmd: deno run ./test.js h: name: "Task 8" - run: - type: sh - script: sh_script.sh \ No newline at end of file + cmd: sh_script.sh \ No newline at end of file diff --git a/tests/config/no_task_name.yaml b/tests/config/no_task_name.yaml index 886512e..7911f12 100644 --- a/tests/config/no_task_name.yaml +++ b/tests/config/no_task_name.yaml @@ -1,5 +1,3 @@ dagrs: a: - run: - type: sh - script: echo "Task 1" \ No newline at end of file + cmd: echo "Task 1" \ No newline at end of file diff --git a/tests/config/precursor_not_found.yaml b/tests/config/precursor_not_found.yaml index e43a3c0..f17303b 100644 --- a/tests/config/precursor_not_found.yaml +++ b/tests/config/precursor_not_found.yaml @@ -2,6 +2,4 @@ dagrs: a: name: "Task 1" after: [ b ] - run: - type: sh - script: echo x \ No newline at end of file + cmd: echo x \ No newline at end of file diff --git a/tests/config/script_run_failed.yaml b/tests/config/script_run_failed.yaml index 3446554..cb5a5f9 100644 --- a/tests/config/script_run_failed.yaml +++ b/tests/config/script_run_failed.yaml @@ -2,47 +2,31 @@ dagrs: a: name: "Task 1" after: [ b, c ] - run: - type: sh - script: error_cmd + cmd: error_cmd b: name: "Task 2" after: [ c, f, g ] - run: - type: sh - script: error_cmd + cmd: error_cmd c: name: "Task 3" after: [ e, g ] - run: - type: sh - script: echo c + cmd: echo c d: name: "Task 4" after: [ c, e ] - run: - type: sh - script: echo d + cmd: echo d e: name: "Task 5" after: [ h ] - run: - type: sh - script: echo e + cmd: echo e f: name: "Task 6" after: [ g ] - run: - type: deno - script: Deno.core.print("f\n") + cmd: Deno.core.print("f\n") g: name: "Task 7" after: [ h ] - run: - type: deno - script: Deno.core.print("g\n") + cmd: Deno.core.print("g\n") h: name: "Task 8" - run: - type: sh - script: echo h \ No newline at end of file + cmd: echo h \ No newline at end of file diff --git a/tests/config/self_loop_error.yaml b/tests/config/self_loop_error.yaml index 5542e1d..d6978db 100644 --- a/tests/config/self_loop_error.yaml +++ b/tests/config/self_loop_error.yaml @@ -2,6 +2,4 @@ dagrs: a: name: "Task 1" after: [ a ] - run: - type: sh - script: echo x \ No newline at end of file + cmd: echo x \ No newline at end of file diff --git a/tests/config/test.js b/tests/config/test.js new file mode 100644 index 0000000..c0b04e7 --- /dev/null +++ b/tests/config/test.js @@ -0,0 +1 @@ +console.log("hello javascript") \ No newline at end of file diff --git a/tests/config/test.py b/tests/config/test.py new file mode 100644 index 0000000..449ed46 --- /dev/null +++ b/tests/config/test.py @@ -0,0 +1 @@ +print("hello python") \ No newline at end of file diff --git a/tests/config/test.sh b/tests/config/test.sh new file mode 100644 index 0000000..0d381e9 --- /dev/null +++ b/tests/config/test.sh @@ -0,0 +1 @@ +echo "hello sh" \ No newline at end of file diff --git a/tests/yaml_parser_test.rs b/tests/yaml_parser_test.rs index 1820f52..87356a0 100644 --- a/tests/yaml_parser_test.rs +++ b/tests/yaml_parser_test.rs @@ -43,24 +43,6 @@ fn yaml_task_not_found_precursor() { assert!(matches!(not_found_pre,Err(ParserError::YamlTaskError(YamlTaskError::NotFoundPrecursor(_))))); } -#[test] -fn yaml_task_no_run_config() { - let no_run = YamlParser.parse_tasks("tests/config/no_run.yaml",HashMap::new()); - assert!(matches!(no_run,Err(ParserError::YamlTaskError(YamlTaskError::NoRunAttr(_))))); -} - -#[test] -fn yaml_task_no_run_type_config() { - let no_run_type = YamlParser.parse_tasks("tests/config/no_type.yaml",HashMap::new()); - assert!(matches!(no_run_type,Err(ParserError::YamlTaskError(YamlTaskError::NoTypeAttr(_))))); -} - -#[test] -fn yaml_task_unsupported_type_config() { - let unsupported_type = YamlParser.parse_tasks("tests/config/unsupported_type.yaml",HashMap::new()); - assert!(matches!(unsupported_type,Err(ParserError::YamlTaskError(YamlTaskError::UnsupportedType(_))))); -} - #[test] fn yaml_task_no_script_config() { let script = YamlParser.parse_tasks("tests/config/no_script.yaml",HashMap::new()); From 08360eab799029de0cc904df0fdae25dfc369e03 Mon Sep 17 00:00:00 2001 From: QIUZHILEI <2925212608@qq.com> Date: Wed, 26 Jul 2023 08:00:32 +0800 Subject: [PATCH 2/4] Adjust github action, add deno environment test Signed-off-by: QIUZHILEI <2925212608@qq.com> --- .github/workflows/base.yml | 3 +++ tests/config/test.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/base.yml b/.github/workflows/base.yml index 1dbe3e0..9d98eff 100644 --- a/.github/workflows/base.yml +++ b/.github/workflows/base.yml @@ -22,6 +22,9 @@ jobs: - uses: actions-rs/cargo@v1 with: command: check + - uses: denoland/setup-deno@v1 + with: + deno-version: v1.x test: name: Test Suite diff --git a/tests/config/test.js b/tests/config/test.js index c0b04e7..9974e9a 100644 --- a/tests/config/test.js +++ b/tests/config/test.js @@ -1 +1 @@ -console.log("hello javascript") \ No newline at end of file +console.log("hello js") \ No newline at end of file From 1376f3c283f8fc50d567754e469c5b88fb4a2194 Mon Sep 17 00:00:00 2001 From: QIUZHILEI <2925212608@qq.com> Date: Wed, 26 Jul 2023 08:20:50 +0800 Subject: [PATCH 3/4] Adjust github action, add deno environment test Signed-off-by: QIUZHILEI <2925212608@qq.com> --- .github/workflows/base.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/base.yml b/.github/workflows/base.yml index 9d98eff..c5501bd 100644 --- a/.github/workflows/base.yml +++ b/.github/workflows/base.yml @@ -22,9 +22,9 @@ jobs: - uses: actions-rs/cargo@v1 with: command: check - - uses: denoland/setup-deno@v1 + - uses: actions/setup-node@v3 with: - deno-version: v1.x + node-version: 16 test: name: Test Suite From c6e53b3f185af3f2c11f16e6a9965cec008e8dac Mon Sep 17 00:00:00 2001 From: QIUZHILEI <2925212608@qq.com> Date: Wed, 26 Jul 2023 08:23:40 +0800 Subject: [PATCH 4/4] Adjust github action, add deno environment test Signed-off-by: QIUZHILEI <2925212608@qq.com> --- README.md | 2 +- examples/custom_parser.rs | 2 +- src/parser/mod.rs | 2 +- src/task/mod.rs | 2 +- tests/config/correct.yaml | 2 +- tests/config/custom_file_task.txt | 2 +- tests/config/no_start_with_dagrs.yaml | 2 +- tests/config/unsupported_type.yaml | 5 ----- 8 files changed, 7 insertions(+), 12 deletions(-) delete mode 100644 tests/config/unsupported_type.yaml diff --git a/README.md b/README.md index 8eeb7e9..c2c7bff 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ dagrs: g: name: "Task 7" after: [ h ] - cmd: deno run ./tests/config/test.js + cmd: node ./tests/config/test.js h: name: "Task 8" cmd: echo h diff --git a/examples/custom_parser.rs b/examples/custom_parser.rs index c00b436..e3303e2 100644 --- a/examples/custom_parser.rs +++ b/examples/custom_parser.rs @@ -8,7 +8,7 @@ //! d,Task d,c e,echo d //! e,Task e,h,echo e //! f,Task f,g,python3 tests/config/test.py -//! g,Task g,h,deno run tests/config/test.js +//! g,Task g,h,node tests/config/test.js //! h,Task h,,echo h //! ``` diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 5f798e5..58fd68a 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -41,7 +41,7 @@ //! g: //! name: "Task 7" //! after: [ h ] -//! cmd: deno run ./tests/config/test.js +//! cmd: node ./tests/config/test.js //! h: //! name: "Task 8" //! cmd: echo h diff --git a/src/task/mod.rs b/src/task/mod.rs index ff4ad35..9ea4470 100644 --- a/src/task/mod.rs +++ b/src/task/mod.rs @@ -36,7 +36,7 @@ //! g: //! name: "Task 7" //! after: [ h ] -//! cmd: deno run ./tests/config/test.js +//! cmd: node ./tests/config/test.js //! h: //! name: "Task 8" //! cmd: echo h diff --git a/tests/config/correct.yaml b/tests/config/correct.yaml index e05aefb..3be113a 100644 --- a/tests/config/correct.yaml +++ b/tests/config/correct.yaml @@ -26,7 +26,7 @@ dagrs: g: name: "Task 7" after: [ h ] - cmd: deno run ./tests/config/test.js + cmd: node ./tests/config/test.js h: name: "Task 8" cmd: echo h \ No newline at end of file diff --git a/tests/config/custom_file_task.txt b/tests/config/custom_file_task.txt index 75b0ec3..e4ef131 100644 --- a/tests/config/custom_file_task.txt +++ b/tests/config/custom_file_task.txt @@ -4,5 +4,5 @@ c,Task c,e g,echo c d,Task d,c e,echo d e,Task e,h,echo e f,Task f,g,python3 tests/config/test.py -g,Task g,h,deno run tests/config/test.js +g,Task g,h,node tests/config/test.js h,Task h,,echo h \ No newline at end of file diff --git a/tests/config/no_start_with_dagrs.yaml b/tests/config/no_start_with_dagrs.yaml index c4a64e6..fd60518 100644 --- a/tests/config/no_start_with_dagrs.yaml +++ b/tests/config/no_start_with_dagrs.yaml @@ -25,7 +25,7 @@ f: g: name: "Task 7" after: [ h ] - cmd: deno run ./test.js + cmd: node ./test.js h: name: "Task 8" cmd: sh_script.sh \ No newline at end of file diff --git a/tests/config/unsupported_type.yaml b/tests/config/unsupported_type.yaml deleted file mode 100644 index c54e77d..0000000 --- a/tests/config/unsupported_type.yaml +++ /dev/null @@ -1,5 +0,0 @@ -dagrs: - a: - name: "Task 1" - run: - type: python \ No newline at end of file