Skip to content

Commit

Permalink
Added run_script which allows executing sub tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Jul 28, 2017
1 parent 098f152 commit feb9df7
Show file tree
Hide file tree
Showing 47 changed files with 2,694 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-make"
version = "0.3.37"
version = "0.3.38"
authors = ["Sagie Gur-Ari <sagiegurari@gmail.com>"]
description = "Rust task runner and build tool."
license = "Apache-2.0"
Expand Down
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -307,6 +309,18 @@ script = [
If you run task **my_task** on windows or mac, it will invoke the **do_nothing** task.<br>
However, if executed on a linux platform, it will invoke the **run** task.

<a name="usage-task-command-script-task"></a>
### Commands, Scripts and Sub Tasks
The actual operation that a task invokes can be defined in 3 ways.<br>
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.<br>
If multiple attributes are defined (for example both command and script), only the higher priority attribute is used.

<a name="usage-default-tasks"></a>
### Default Tasks and Extending
There is no real need to define the tasks that were shown in the previous example.<br>
Expand Down Expand Up @@ -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.

<a name="usage-conditions-and-subtasks"></a>
### Combining Conditions and Sub Tasks
condition_script and run_task combined can enable you to define a conditional sub flow.<br>
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.<br>
Only if both are defined, it will run the **codecov-flow** task.<br>
We can't define the condition directly on the **codecov-flow** task, as it will invoke the task dependencies before checking the condition.

<a name="usage-ci"></a>
### 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.<br>
Expand Down Expand Up @@ -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 |
Expand Down
47 changes: 47 additions & 0 deletions docs/_includes/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,18 @@ script = [
If you run task **my_task** on windows or mac, it will invoke the **do_nothing** task.<br>
However, if executed on a linux platform, it will invoke the **run** task.

<a name="usage-task-command-script-task"></a>
### Commands, Scripts and Sub Tasks
The actual operation that a task invokes can be defined in 3 ways.<br>
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.<br>
If multiple attributes are defined (for example both command and script), only the higher priority attribute is used.

<a name="usage-default-tasks"></a>
### Default Tasks and Extending
There is no real need to define the tasks that were shown in the previous example.<br>
Expand Down Expand Up @@ -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.

<a name="usage-conditions-and-subtasks"></a>
### Combining Conditions and Sub Tasks
condition_script and run_task combined can enable you to define a conditional sub flow.<br>
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.<br>
Only if both are defined, it will run the **codecov-flow** task.<br>
We can't define the condition directly on the **codecov-flow** task, as it will invoke the task dependencies before checking the condition.

<a name="usage-ci"></a>
### 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.<br>
Expand Down Expand Up @@ -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 |
Expand Down
2 changes: 2 additions & 0 deletions docs/_includes/nav.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions docs/api/cargo_make/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<nav class="sidebar">

<p class='location'>Crate cargo_make</p><p class='location'></p><script>window.sidebarCurrent = {name: 'cargo_make', ty: 'mod', relpath: '../'};</script>
<p class='location'>Crate cargo_make</p><div class="block items"><ul><li><a href="#modules">Modules</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'cargo_make', ty: 'mod', relpath: '../'};</script>
</nav>

<nav class="sub">
Expand All @@ -48,7 +48,7 @@ <h1 class='fqn'><span class='in-band'>Crate <a class="mod" href=''>cargo_make</a
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>&#x2212;</span>]
</a>
</span><a class='srclink' href='../src/cargo_make/main.rs.html#1-119' title='goto source code'>[src]</a></span></h1>
</span><a class='srclink' href='../src/cargo_make/main.rs.html#1-121' title='goto source code'>[src]</a></span></h1>
<div class='docblock'>
<h1 id='cargo-make' class='section-header'><a href='#cargo-make'>cargo-make</a></h1>
<p>Rust task runner and build tool.<br>
Expand All @@ -73,7 +73,15 @@ <h1 id='contributing' class='section-header'><a href='#contributing'>Contributin
<h1 id='license' class='section-header'><a href='#license'>License</a></h1>
<p>Developed by Sagie Gur-Ari and licensed under the
<a href="https://github.com/sagiegurari/simple_redis/blob/master/LICENSE">Apache 2</a> open source license.</p>
</div></section>
</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
<table>
<tr class=' module-item'>
<td><a class="mod" href="types/index.html"
title='mod cargo_make::types'>types</a></td>
<td class='docblock-short'>

</td>
</tr></table></section>
<section id='search' class="content hidden"></section>

<section class="footer"></section>
Expand Down
2 changes: 1 addition & 1 deletion docs/api/cargo_make/sidebar-items.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
initSidebarItems({});
initSidebarItems({"mod":[["types","types"]]});
10 changes: 10 additions & 0 deletions docs/api/cargo_make/types/CliArgs.t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=struct.CliArgs.html">
</head>
<body>
<p>Redirecting to <a href="struct.CliArgs.html">struct.CliArgs.html</a>...</p>
<script>location.replace("struct.CliArgs.html" + location.search + location.hash);</script>
</body>
</html>
10 changes: 10 additions & 0 deletions docs/api/cargo_make/types/Config.t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=struct.Config.html">
</head>
<body>
<p>Redirecting to <a href="struct.Config.html">struct.Config.html</a>...</p>
<script>location.replace("struct.Config.html" + location.search + location.hash);</script>
</body>
</html>
10 changes: 10 additions & 0 deletions docs/api/cargo_make/types/ConfigSection.t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=struct.ConfigSection.html">
</head>
<body>
<p>Redirecting to <a href="struct.ConfigSection.html">struct.ConfigSection.html</a>...</p>
<script>location.replace("struct.ConfigSection.html" + location.search + location.hash);</script>
</body>
</html>
10 changes: 10 additions & 0 deletions docs/api/cargo_make/types/CrateInfo.t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=struct.CrateInfo.html">
</head>
<body>
<p>Redirecting to <a href="struct.CrateInfo.html">struct.CrateInfo.html</a>...</p>
<script>location.replace("struct.CrateInfo.html" + location.search + location.hash);</script>
</body>
</html>
10 changes: 10 additions & 0 deletions docs/api/cargo_make/types/ExecutionPlan.t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=struct.ExecutionPlan.html">
</head>
<body>
<p>Redirecting to <a href="struct.ExecutionPlan.html">struct.ExecutionPlan.html</a>...</p>
<script>location.replace("struct.ExecutionPlan.html" + location.search + location.hash);</script>
</body>
</html>
10 changes: 10 additions & 0 deletions docs/api/cargo_make/types/ExternalConfig.t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=struct.ExternalConfig.html">
</head>
<body>
<p>Redirecting to <a href="struct.ExternalConfig.html">struct.ExternalConfig.html</a>...</p>
<script>location.replace("struct.ExternalConfig.html" + location.search + location.hash);</script>
</body>
</html>
10 changes: 10 additions & 0 deletions docs/api/cargo_make/types/FlowInfo.t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=struct.FlowInfo.html">
</head>
<body>
<p>Redirecting to <a href="struct.FlowInfo.html">struct.FlowInfo.html</a>...</p>
<script>location.replace("struct.FlowInfo.html" + location.search + location.hash);</script>
</body>
</html>
10 changes: 10 additions & 0 deletions docs/api/cargo_make/types/PackageInfo.t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=struct.PackageInfo.html">
</head>
<body>
<p>Redirecting to <a href="struct.PackageInfo.html">struct.PackageInfo.html</a>...</p>
<script>location.replace("struct.PackageInfo.html" + location.search + location.hash);</script>
</body>
</html>
10 changes: 10 additions & 0 deletions docs/api/cargo_make/types/PlatformOverrideTask.t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=struct.PlatformOverrideTask.html">
</head>
<body>
<p>Redirecting to <a href="struct.PlatformOverrideTask.html">struct.PlatformOverrideTask.html</a>...</p>
<script>location.replace("struct.PlatformOverrideTask.html" + location.search + location.hash);</script>
</body>
</html>
10 changes: 10 additions & 0 deletions docs/api/cargo_make/types/Step.t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=struct.Step.html">
</head>
<body>
<p>Redirecting to <a href="struct.Step.html">struct.Step.html</a>...</p>
<script>location.replace("struct.Step.html" + location.search + location.hash);</script>
</body>
</html>
10 changes: 10 additions & 0 deletions docs/api/cargo_make/types/Task.t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=struct.Task.html">
</head>
<body>
<p>Redirecting to <a href="struct.Task.html">struct.Task.html</a>...</p>
<script>location.replace("struct.Task.html" + location.search + location.hash);</script>
</body>
</html>
10 changes: 10 additions & 0 deletions docs/api/cargo_make/types/Workspace.t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=struct.Workspace.html">
</head>
<body>
<p>Redirecting to <a href="struct.Workspace.html">struct.Workspace.html</a>...</p>
<script>location.replace("struct.Workspace.html" + location.search + location.hash);</script>
</body>
</html>
Loading

0 comments on commit feb9df7

Please sign in to comment.