Skip to content

Commit

Permalink
Added load_script capability
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Aug 19, 2017
1 parent 04be961 commit dd21b3e
Show file tree
Hide file tree
Showing 18 changed files with 250 additions and 24 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.56"
version = "0.3.57"
authors = ["Sagie Gur-Ari <sagiegurari@gmail.com>"]
description = "Rust task runner and build tool."
license = "Apache-2.0"
Expand Down
35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [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)
* [Load Scripts](#usage-load-scripts)
* [Ignoring Errors](#usage-ignoring-errors)
* [Platform Override](#usage-platform-override)
* [Environment Variables](#usage-env)
Expand Down Expand Up @@ -372,6 +373,31 @@ The file path in the extend attribute is always relative to the current toml fil
The extend attribute can be very usefull when you have a workspace with a Makefile.toml that contains all of the common custom tasks and in each project you can have a simple Makefile.toml which just has
the extend attribute pointing to the workspace makefile.

<a name="usage-load-scripts"></a>
#### Load Scripts
In more complex scenarios, you may want multiple unrelated projects to share some common cutom tasks, for example if you wish to notify some internal company server of the build status.<br>
Instead of redefining those tasks in each project you can create a single toml file with those definitions and have all projects extend that file.<br>
The extend however, only knows to find the extending files in the file system, so in order to pull some common toml from a remote resource (using http or git clone and so on...), you can use the load scripts.

Load scripts are defined in the config section using the load_script attribute and are invoked **before** the extend attribute is evaluated.<br>
This allows you to first pull the toml file from the remote server and put it in a location defined by the extend attribute.

Here is an example of a load script which downloads the common toml from a remote server using HTTP:

````toml
[config]
load_script = ["wget -O /home/myuser/common.toml companyserver.com/common.toml"]
````

Here is an example of pulling the common toml file from some git repo:

````toml
[config]
load_script = ["git clone git@mygitserver:user/project.git /home/myuser/common"]
````

You can run any command or set of commands you want, so you can build a more complex flow of how and where to fetch the toml file from and where to put it.

<a name="usage-ignoring-errors"></a>
### Ignoring Errors
In some cases you want to run optional tasks as part of a bigger flow, but do not want to break your entire build in case of any error in those optional tasks.<br>
Expand Down Expand Up @@ -643,15 +669,15 @@ For faster cargo-make installation as part of the build, you can also pull the b

````yml
script:
- wget -O ~/.cargo/bin/cargo-make https://bintray.com/sagiegurari/cargo-make/download_file?file_path=cargo-make_v0.3.56
- wget -O ~/.cargo/bin/cargo-make https://bintray.com/sagiegurari/cargo-make/download_file?file_path=cargo-make_v0.3.57
- chmod 777 ~/.cargo/bin/cargo-make
- cargo-make make ci-flow
````

The specific version of cargo-make requested is defined in the suffix of the cargo-make file name in the form of: cargo-make_v[VERSION], for example

````sh
https://bintray.com/sagiegurari/cargo-make/download_file?file_path=cargo-make_v0.3.56
https://bintray.com/sagiegurari/cargo-make/download_file?file_path=cargo-make_v0.3.57
````

In order to pull the latest prebuild cargo-make binary, use the following example:
Expand Down Expand Up @@ -909,7 +935,9 @@ pub struct ConfigSection {
/// Init task name which will be invoked at the start of every run
pub init_task: Option<String>,
/// End task name which will be invoked at the end of every run
pub end_task: Option<String>
pub end_task: Option<String>,
/// Invoked while loading the descriptor file but before loading any extended descriptor
pub load_script: Option<Vec<String>>
}

/// Holds the entire externally read configuration such as task definitions and env vars where all values are optional
Expand Down Expand Up @@ -1105,6 +1133,7 @@ See [contributing guide](.github/CONTRIBUTING.md)

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2017-08-19 | v0.3.57 | Added load_script capability |
| 2017-08-18 | v0.3.56 | Set environment variables during task invocation |
| 2017-08-09 | v0.3.53 | Added new condition types: env, env_set and env_not_set |
| 2017-08-09 | v0.3.51 | Added experimental cli arg to enable access unsupported experimental predefined tasks |
Expand Down
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ theme: jekyll-theme-cayman
title: cargo-make
description: Rust task runner and build tool.
show_downloads: false
version: 0.3.56
version: 0.3.57
30 changes: 29 additions & 1 deletion docs/_includes/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,31 @@ The file path in the extend attribute is always relative to the current toml fil
The extend attribute can be very usefull when you have a workspace with a Makefile.toml that contains all of the common custom tasks and in each project you can have a simple Makefile.toml which just has
the extend attribute pointing to the workspace makefile.

<a name="usage-load-scripts"></a>
#### Load Scripts
In more complex scenarios, you may want multiple unrelated projects to share some common cutom tasks, for example if you wish to notify some internal company server of the build status.<br>
Instead of redefining those tasks in each project you can create a single toml file with those definitions and have all projects extend that file.<br>
The extend however, only knows to find the extending files in the file system, so in order to pull some common toml from a remote resource (using http or git clone and so on...), you can use the load scripts.

Load scripts are defined in the config section using the load_script attribute and are invoked **before** the extend attribute is evaluated.<br>
This allows you to first pull the toml file from the remote server and put it in a location defined by the extend attribute.

Here is an example of a load script which downloads the common toml from a remote server using HTTP:

````toml
[config]
load_script = ["wget -O /home/myuser/common.toml companyserver.com/common.toml"]
````

Here is an example of pulling the common toml file from some git repo:

````toml
[config]
load_script = ["git clone git@mygitserver:user/project.git /home/myuser/common"]
````

You can run any command or set of commands you want, so you can build a more complex flow of how and where to fetch the toml file from and where to put it.

<a name="usage-ignoring-errors"></a>
### Ignoring Errors
In some cases you want to run optional tasks as part of a bigger flow, but do not want to break your entire build in case of any error in those optional tasks.<br>
Expand Down Expand Up @@ -865,7 +890,9 @@ pub struct ConfigSection {
/// Init task name which will be invoked at the start of every run
pub init_task: Option<String>,
/// End task name which will be invoked at the end of every run
pub end_task: Option<String>
pub end_task: Option<String>,
/// Invoked while loading the descriptor file but before loading any extended descriptor
pub load_script: Option<Vec<String>>
}

/// Holds the entire externally read configuration such as task definitions and env vars where all values are optional
Expand Down Expand Up @@ -1061,6 +1088,7 @@ See [contributing guide](https://github.com/sagiegurari/cargo-make/blob/master/.

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2017-08-19 | v0.3.57 | Added load_script capability |
| 2017-08-18 | v0.3.56 | Set environment variables during task invocation |
| 2017-08-09 | v0.3.53 | Added new condition types: env, env_set and env_not_set |
| 2017-08-09 | v0.3.51 | Added experimental cli arg to enable access unsupported experimental predefined tasks |
Expand Down
1 change: 1 addition & 0 deletions docs/_includes/nav.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [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)
* [Load Scripts](#usage-load-scripts)
* [Ignoring Errors](#usage-ignoring-errors)
* [Platform Override](#usage-platform-override)
* [Environment Variables](#usage-env)
Expand Down
2 changes: 1 addition & 1 deletion docs/api/cargo_make/types/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h1 class='fqn'><span class='in-band'>Module <a href='../index.html'>cargo_make<
<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/types.rs.html#1-707' title='goto source code'>[src]</a></span></h1>
</span><a class='srclink' href='../../src/cargo_make/types.rs.html#1-713' title='goto source code'>[src]</a></span></h1>
<div class='docblock'>
<h1 id='types' class='section-header'><a href='#types'>types</a></h1>
<p>Defines the various types and aliases used by cargo-make.</p>
Expand Down
6 changes: 3 additions & 3 deletions docs/api/cargo_make/types/struct.Config.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>cargo_make<
<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/types.rs.html#664-671' title='goto source code'>[src]</a></span></h1>
</span><a class='srclink' href='../../src/cargo_make/types.rs.html#670-677' title='goto source code'>[src]</a></span></h1>
<pre class='rust struct'>pub struct Config {
pub config: <a class="struct" href="../../cargo_make/types/struct.ConfigSection.html" title="struct cargo_make::types::ConfigSection">ConfigSection</a>,
pub env: <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,
Expand All @@ -66,10 +66,10 @@ <h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>cargo_make<
<span id='tasks.v' class='invisible'>
<code>tasks: <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <a class="struct" href="../../cargo_make/types/struct.Task.html" title="struct cargo_make::types::Task">Task</a>&gt;</code>
</span></span><div class='docblock'><p>All task definitions</p>
</div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../../cargo_make/types/struct.Config.html" title="struct cargo_make::types::Config">Config</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/cargo_make/types.rs.html#662' title='goto source code'>[src]</a></span></h3>
</div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../../cargo_make/types/struct.Config.html" title="struct cargo_make::types::Config">Config</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/cargo_make/types.rs.html#668' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, __arg_0: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span></h4>
<div class='docblock'><p>Formats the value using the given formatter.</p>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../../cargo_make/types/struct.Config.html" title="struct cargo_make::types::Config">Config</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/cargo_make/types.rs.html#662' title='goto source code'>[src]</a></span></h3>
</div></div><h3 class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../../cargo_make/types/struct.Config.html" title="struct cargo_make::types::Config">Config</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/cargo_make/types.rs.html#668' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.clone' class="method"><span id='clone.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&amp;self) -&gt; <a class="struct" href="../../cargo_make/types/struct.Config.html" title="struct cargo_make::types::Config">Config</a></code></span></h4>
<div class='docblock'><p>Returns a copy of the value. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone">Read more</a></p>
</div><h4 id='method.clone_from' class="method"><span id='clone_from.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&amp;mut self, source: &amp;Self)</code><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div></span></h4>
Expand Down
9 changes: 7 additions & 2 deletions docs/api/cargo_make/types/struct.ConfigSection.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ <h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>cargo_make<
<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/types.rs.html#630-635' title='goto source code'>[src]</a></span></h1>
</span><a class='srclink' href='../../src/cargo_make/types.rs.html#630-637' title='goto source code'>[src]</a></span></h1>
<pre class='rust struct'>pub struct ConfigSection {
pub init_task: <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,
pub end_task: <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,
pub load_script: <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;&gt;,
}</pre><div class='docblock'><p>Holds the configuration found in the makefile toml config section.</p>
</div><h2 id='fields' class='fields'>Fields</h2><span id='structfield.init_task' class="structfield">
<span id='init_task.v' class='invisible'>
Expand All @@ -61,7 +62,11 @@ <h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>cargo_make<
<span id='end_task.v' class='invisible'>
<code>end_task: <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;</code>
</span></span><div class='docblock'><p>End task name which will be invoked at the end of every run</p>
</div><h2 id='methods'>Methods</h2><h3 class='impl'><span class='in-band'><code>impl <a class="struct" href="../../cargo_make/types/struct.ConfigSection.html" title="struct cargo_make::types::ConfigSection">ConfigSection</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/cargo_make/types.rs.html#637-660' title='goto source code'>[src]</a></span></h3>
</div><span id='structfield.load_script' class="structfield">
<span id='load_script.v' class='invisible'>
<code>load_script: <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;&gt;</code>
</span></span><div class='docblock'><p>Invoked while loading the descriptor file but before loading any extended descriptor</p>
</div><h2 id='methods'>Methods</h2><h3 class='impl'><span class='in-band'><code>impl <a class="struct" href="../../cargo_make/types/struct.ConfigSection.html" title="struct cargo_make::types::ConfigSection">ConfigSection</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/cargo_make/types.rs.html#639-666' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><code>fn <a href='#method.new' class='fnname'>new</a>() -&gt; <a class="struct" href="../../cargo_make/types/struct.ConfigSection.html" title="struct cargo_make::types::ConfigSection">ConfigSection</a></code></span></h4>
<div class='docblock'><p>Creates and returns a new instance.</p>
</div><h4 id='method.extend' class="method"><span id='extend.v' class='invisible'><code>fn <a href='#method.extend' class='fnname'>extend</a>(self: &amp;mut <a class="struct" href="../../cargo_make/types/struct.ConfigSection.html" title="struct cargo_make::types::ConfigSection">ConfigSection</a>, extended: &amp;mut <a class="struct" href="../../cargo_make/types/struct.ConfigSection.html" title="struct cargo_make::types::ConfigSection">ConfigSection</a>)</code></span></h4>
Expand Down
Loading

0 comments on commit dd21b3e

Please sign in to comment.