From feb9df7834365c146e435f59d72d761a51af3944 Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Fri, 28 Jul 2017 10:10:42 +0000 Subject: [PATCH] Added run_script which allows executing sub tasks --- Cargo.toml | 2 +- README.md | 49 ++++ docs/_includes/content.md | 47 ++++ docs/_includes/nav.md | 2 + docs/api/cargo_make/index.html | 14 +- docs/api/cargo_make/sidebar-items.js | 2 +- docs/api/cargo_make/types/CliArgs.t.html | 10 + docs/api/cargo_make/types/Config.t.html | 10 + .../api/cargo_make/types/ConfigSection.t.html | 10 + docs/api/cargo_make/types/CrateInfo.t.html | 10 + .../api/cargo_make/types/ExecutionPlan.t.html | 10 + .../cargo_make/types/ExternalConfig.t.html | 10 + docs/api/cargo_make/types/FlowInfo.t.html | 10 + docs/api/cargo_make/types/PackageInfo.t.html | 10 + .../types/PlatformOverrideTask.t.html | 10 + docs/api/cargo_make/types/Step.t.html | 10 + docs/api/cargo_make/types/Task.t.html | 10 + docs/api/cargo_make/types/Workspace.t.html | 10 + docs/api/cargo_make/types/index.html | 200 +++++++++++++++ docs/api/cargo_make/types/sidebar-items.js | 1 + docs/api/cargo_make/types/struct.CliArgs.html | 160 ++++++++++++ docs/api/cargo_make/types/struct.Config.html | 137 ++++++++++ .../types/struct.ConfigSection.html | 142 +++++++++++ .../cargo_make/types/struct.CrateInfo.html | 142 +++++++++++ .../types/struct.ExecutionPlan.html | 122 +++++++++ .../types/struct.ExternalConfig.html | 140 +++++++++++ .../api/cargo_make/types/struct.FlowInfo.html | 137 ++++++++++ .../cargo_make/types/struct.PackageInfo.html | 160 ++++++++++++ .../types/struct.PlatformOverrideTask.html | 190 ++++++++++++++ docs/api/cargo_make/types/struct.Step.html | 127 ++++++++++ docs/api/cargo_make/types/struct.Task.html | 233 ++++++++++++++++++ .../cargo_make/types/struct.Workspace.html | 130 ++++++++++ .../implementors/core/clone/trait.Clone.js | 10 + docs/api/implementors/core/fmt/trait.Debug.js | 10 + docs/api/search-index.js | 2 +- docs/api/src/cargo_make/cli.rs.html | 2 +- docs/api/src/cargo_make/main.rs.html | 6 +- docs/api/src/cargo_make/runner.rs.html | 64 ++++- docs/api/src/cargo_make/types.rs.html | 116 ++++++++- examples/run_task.toml | 11 + src/cli.rs | 2 +- src/default.toml | 8 +- src/main.rs | 4 +- src/runner.rs | 40 ++- src/runner_test.rs | 110 ++++++++- src/types.rs | 59 ++++- src/types_test.rs | 28 +++ 47 files changed, 2694 insertions(+), 35 deletions(-) create mode 100644 docs/api/cargo_make/types/CliArgs.t.html create mode 100644 docs/api/cargo_make/types/Config.t.html create mode 100644 docs/api/cargo_make/types/ConfigSection.t.html create mode 100644 docs/api/cargo_make/types/CrateInfo.t.html create mode 100644 docs/api/cargo_make/types/ExecutionPlan.t.html create mode 100644 docs/api/cargo_make/types/ExternalConfig.t.html create mode 100644 docs/api/cargo_make/types/FlowInfo.t.html create mode 100644 docs/api/cargo_make/types/PackageInfo.t.html create mode 100644 docs/api/cargo_make/types/PlatformOverrideTask.t.html create mode 100644 docs/api/cargo_make/types/Step.t.html create mode 100644 docs/api/cargo_make/types/Task.t.html create mode 100644 docs/api/cargo_make/types/Workspace.t.html create mode 100644 docs/api/cargo_make/types/index.html create mode 100644 docs/api/cargo_make/types/sidebar-items.js create mode 100644 docs/api/cargo_make/types/struct.CliArgs.html create mode 100644 docs/api/cargo_make/types/struct.Config.html create mode 100644 docs/api/cargo_make/types/struct.ConfigSection.html create mode 100644 docs/api/cargo_make/types/struct.CrateInfo.html create mode 100644 docs/api/cargo_make/types/struct.ExecutionPlan.html create mode 100644 docs/api/cargo_make/types/struct.ExternalConfig.html create mode 100644 docs/api/cargo_make/types/struct.FlowInfo.html create mode 100644 docs/api/cargo_make/types/struct.PackageInfo.html create mode 100644 docs/api/cargo_make/types/struct.PlatformOverrideTask.html create mode 100644 docs/api/cargo_make/types/struct.Step.html create mode 100644 docs/api/cargo_make/types/struct.Task.html create mode 100644 docs/api/cargo_make/types/struct.Workspace.html create mode 100644 docs/api/implementors/core/clone/trait.Clone.js create mode 100644 docs/api/implementors/core/fmt/trait.Debug.js create mode 100644 examples/run_task.toml diff --git a/Cargo.toml b/Cargo.toml index 146488f6..39ba8f01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-make" -version = "0.3.37" +version = "0.3.38" authors = ["Sagie Gur-Ari "] description = "Rust task runner and build tool." license = "Apache-2.0" diff --git a/README.md b/README.md index 5dd0e1c5..f6a558fc 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,13 @@ * [Usage](#usage) * [Simple Example](#usage-simple) * [Tasks, Dependencies and Aliases](#usage-task-dependencies-alias) + * [Commands, Scripts and Sub Tasks](#usage-task-command-script-task) * [Default Tasks and Extending](#usage-default-tasks) * [Ignoring Errors](#usage-ignoring-errors) * [Platform Override](#usage-platform-override) * [Environment Variables](#usage-env) * [Conditions](#usage-conditions) + * [Combining Conditions and Sub Tasks](#usage-conditions-and-subtasks) * [Continuous Integration](#usage-ci) * [Travis](#usage-ci-travis) * [AppVeyor](#usage-ci-appveyor) @@ -307,6 +309,18 @@ script = [ If you run task **my_task** on windows or mac, it will invoke the **do_nothing** task.
However, if executed on a linux platform, it will invoke the **run** task. + +### Commands, Scripts and Sub Tasks +The actual operation that a task invokes can be defined in 3 ways.
+The below explains each one and lists them by priority: + +* **run_task** - Invokes another task with the name defined in this attribute. Unlike dependencies which are invoked before the current task, the task defined in the **run_task** is invoked after the current task. +* **command** - The command attribute defines what executable to invoke. You can use the **args** attribute to define what attributes to provide as part of the command. +* **script** - Invokes the script. You can change the executable used to invoke the script using the **script_runner** attribute. If not defined, the default platform runner is used (cmd for windows, sh for others). + +Only one of the definitions will be used.
+If multiple attributes are defined (for example both command and script), only the higher priority attribute is used. + ### Default Tasks and Extending There is no real need to define the tasks that were shown in the previous example.
@@ -478,6 +492,40 @@ args = ["build"] Condition scripts can be used to ensure that the task is only invoked if a specific condition is met, for example if a specific environment variable is defined. + +### Combining Conditions and Sub Tasks +condition_script and run_task combined can enable you to define a conditional sub flow.
+For example, if you have a coverage flow that should only be invoked in a travis build, and only if the CARGO_MAKE_RUN_CODECOV environment variable is defined as "true": + +````toml +[tasks.ci-coverage-flow] +windows_alias = "empty" +condition_script = [ +''' +if [ "$TRAVIS" = "true" ]; then + if [ "$CARGO_MAKE_RUN_CODECOV" = "true" ]; then + exit 0 + fi +fi + +exit 1 +''' +] +run_task = "codecov-flow" + +[tasks.codecov-flow] +description = "Runs the full coverage flow and uploads the results to codecov." +windows_alias = "empty" +dependencies = [ + "coverage-flow", + "codecov" +] +```` + +The first task **ci-coverage-flow** defines the condition_script that checks we are in travis and the CARGO_MAKE_RUN_CODECOV environment variable.
+Only if both are defined, it will run the **codecov-flow** task.
+We can't define the condition directly on the **codecov-flow** task, as it will invoke the task dependencies before checking the condition. + ### Continuous Integration cargo-make comes with a predefined flow for continuous integration build executed by internal or online services such as travis-ci and appveyor.
@@ -858,6 +906,7 @@ See [contributing guide](.github/CONTRIBUTING.md) | Date | Version | Description | | ----------- | ------- | ----------- | +| 2017-07-28 | v0.3.38 | Added run_script which allows executing sub tasks | | 2017-07-25 | v0.3.37 | Added condition script capability for tasks | | 2017-07-22 | v0.3.36 | Added coverage-lcov task (not fully tested) | | 2017-07-21 | v0.3.34 | Added coverage-tarpaulin task | diff --git a/docs/_includes/content.md b/docs/_includes/content.md index 94b558b9..1848bd39 100644 --- a/docs/_includes/content.md +++ b/docs/_includes/content.md @@ -274,6 +274,18 @@ script = [ If you run task **my_task** on windows or mac, it will invoke the **do_nothing** task.
However, if executed on a linux platform, it will invoke the **run** task. + +### Commands, Scripts and Sub Tasks +The actual operation that a task invokes can be defined in 3 ways.
+The below explains each one and lists them by priority: + +* **run_task** - Invokes another task with the name defined in this attribute. Unlike dependencies which are invoked before the current task, the task defined in the **run_task** is invoked after the current task. +* **command** - The command attribute defines what executable to invoke. You can use the **args** attribute to define what attributes to provide as part of the command. +* **script** - Invokes the script. You can change the executable used to invoke the script using the **script_runner** attribute. If not defined, the default platform runner is used (cmd for windows, sh for others). + +Only one of the definitions will be used.
+If multiple attributes are defined (for example both command and script), only the higher priority attribute is used. + ### Default Tasks and Extending There is no real need to define the tasks that were shown in the previous example.
@@ -445,6 +457,40 @@ args = ["build"] Condition scripts can be used to ensure that the task is only invoked if a specific condition is met, for example if a specific environment variable is defined. + +### Combining Conditions and Sub Tasks +condition_script and run_task combined can enable you to define a conditional sub flow.
+For example, if you have a coverage flow that should only be invoked in a travis build, and only if the CARGO_MAKE_RUN_CODECOV environment variable is defined as "true": + +````toml +[tasks.ci-coverage-flow] +windows_alias = "empty" +condition_script = [ +''' +if [ "$TRAVIS" = "true" ]; then + if [ "$CARGO_MAKE_RUN_CODECOV" = "true" ]; then + exit 0 + fi +fi + +exit 1 +''' +] +run_task = "codecov-flow" + +[tasks.codecov-flow] +description = "Runs the full coverage flow and uploads the results to codecov." +windows_alias = "empty" +dependencies = [ + "coverage-flow", + "codecov" +] +```` + +The first task **ci-coverage-flow** defines the condition_script that checks we are in travis and the CARGO_MAKE_RUN_CODECOV environment variable.
+Only if both are defined, it will run the **codecov-flow** task.
+We can't define the condition directly on the **codecov-flow** task, as it will invoke the task dependencies before checking the condition. + ### Continuous Integration cargo-make comes with a predefined flow for continuous integration build executed by internal or online services such as travis-ci and appveyor.
@@ -825,6 +871,7 @@ See [contributing guide](https://github.com/sagiegurari/cargo-make/blob/master/. | Date | Version | Description | | ----------- | ------- | ----------- | +| 2017-07-28 | v0.3.38 | Added run_script which allows executing sub tasks | | 2017-07-25 | v0.3.37 | Added condition script capability for tasks | | 2017-07-22 | v0.3.36 | Added coverage-lcov task (not fully tested) | | 2017-07-21 | v0.3.34 | Added coverage-tarpaulin task | diff --git a/docs/_includes/nav.md b/docs/_includes/nav.md index 8f55f114..75111b9a 100644 --- a/docs/_includes/nav.md +++ b/docs/_includes/nav.md @@ -4,11 +4,13 @@ * [Usage](#usage) * [Simple Example](#usage-simple) * [Tasks, Dependencies and Aliases](#usage-task-dependencies-alias) + * [Commands, Scripts and Sub Tasks](#usage-task-command-script-task) * [Default Tasks and Extending](#usage-default-tasks) * [Ignoring Errors](#usage-ignoring-errors) * [Platform Override](#usage-platform-override) * [Environment Variables](#usage-env) * [Conditions](#usage-conditions) + * [Combining Conditions and Sub Tasks](#usage-conditions-and-subtasks) * [Continuous Integration](#usage-ci) * [Travis](#usage-ci-travis) * [AppVeyor](#usage-ci-appveyor) diff --git a/docs/api/cargo_make/index.html b/docs/api/cargo_make/index.html index e2caa7a9..c8aa0a3f 100644 --- a/docs/api/cargo_make/index.html +++ b/docs/api/cargo_make/index.html @@ -29,7 +29,7 @@