Skip to content

Commit

Permalink
Set environment variables during task invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Aug 18, 2017
1 parent c533304 commit 6c3d80d
Show file tree
Hide file tree
Showing 23 changed files with 270 additions and 43 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.55"
version = "0.3.56"
authors = ["Sagie Gur-Ari <sagiegurari@gmail.com>"]
description = "Rust task runner and build tool."
license = "Apache-2.0"
Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,15 @@ Environment variables can also be defined in the command line using the --env/-e
cargo make --env ENV1=VALUE1 --env ENV2=VALUE2 -e ENV3=VALUE3
````

In addition, cargo-make will also add few environment variables that can be helpful when running task scripts/commands:
Environment variables can also be defined inside tasks, so when a task is invoked (after its dependencies), the environment variables will be set, for example:

````yaml
[tasks.test-flow]
env = { "SOME_ENV_VAR" = "value" }
run_task = "actual-task"
````

In addition, cargo-make will also automatically add few environment variables that can be helpful when running task scripts, commands, conditions, etc:

* **CARGO_MAKE** - Set to "true" to help sub processes identify they are running from cargo make.
* **CARGO_MAKE_TASK** - Holds the name of the main task being executed.
Expand Down Expand Up @@ -615,15 +623,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.55
- wget -O ~/.cargo/bin/cargo-make https://bintray.com/sagiegurari/cargo-make/download_file?file_path=cargo-make_v0.3.56
- 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.55
https://bintray.com/sagiegurari/cargo-make/download_file?file_path=cargo-make_v0.3.56
````

In order to pull the latest prebuild cargo-make binary, use the following example:
Expand Down Expand Up @@ -908,6 +916,8 @@ pub struct Task {
pub condition_script: Option<Vec<String>>,
/// if true, any error while executing the task will be printed but will not break the build
pub force: Option<bool>,
/// The env vars to setup before running the task commands
pub env: Option<HashMap<String, String>>,
/// if defined, task points to another task and all other properties are ignored
pub alias: Option<String>,
/// acts like alias if runtime OS is Linux (takes precedence over alias)
Expand Down Expand Up @@ -952,6 +962,8 @@ pub struct PlatformOverrideTask {
pub condition_script: Option<Vec<String>>,
/// if true, any error while executing the task will be printed but will not break the build
pub force: Option<bool>,
/// The env vars to setup before running the task commands
pub env: Option<HashMap<String, String>>,
/// if defined, the provided crate will be installed (if needed) before running the task
pub install_crate: Option<String>,
/// if defined, the provided script will be executed before running the task
Expand Down Expand Up @@ -1073,7 +1085,7 @@ See [contributing guide](.github/CONTRIBUTING.md)

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2017-08-15 | v0.3.55 | Update executable name in help/version output |
| 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 |
| 2017-08-08 | v0.3.49 | Added condition attribute |
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.55
version: 0.3.56
16 changes: 14 additions & 2 deletions docs/_includes/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,15 @@ Environment variables can also be defined in the command line using the --env/-e
cargo make --env ENV1=VALUE1 --env ENV2=VALUE2 -e ENV3=VALUE3
````

In addition, cargo-make will also add few environment variables that can be helpful when running task scripts/commands:
Environment variables can also be defined inside tasks, so when a task is invoked (after its dependencies), the environment variables will be set, for example:

````yaml
[tasks.test-flow]
env = { "SOME_ENV_VAR" = "value" }
run_task = "actual-task"
````

In addition, cargo-make will also automatically add few environment variables that can be helpful when running task scripts, commands, conditions, etc:

* **CARGO_MAKE** - Set to "true" to help sub processes identify they are running from cargo make.
* **CARGO_MAKE_TASK** - Holds the name of the main task being executed.
Expand Down Expand Up @@ -868,6 +876,8 @@ pub struct Task {
pub condition_script: Option<Vec<String>>,
/// if true, any error while executing the task will be printed but will not break the build
pub force: Option<bool>,
/// The env vars to setup before running the task commands
pub env: Option<HashMap<String, String>>,
/// if defined, task points to another task and all other properties are ignored
pub alias: Option<String>,
/// acts like alias if runtime OS is Linux (takes precedence over alias)
Expand Down Expand Up @@ -912,6 +922,8 @@ pub struct PlatformOverrideTask {
pub condition_script: Option<Vec<String>>,
/// if true, any error while executing the task will be printed but will not break the build
pub force: Option<bool>,
/// The env vars to setup before running the task commands
pub env: Option<HashMap<String, String>>,
/// if defined, the provided crate will be installed (if needed) before running the task
pub install_crate: Option<String>,
/// if defined, the provided script will be executed before running the task
Expand Down Expand Up @@ -1033,7 +1045,7 @@ See [contributing guide](https://github.com/sagiegurari/cargo-make/blob/master/.

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2017-08-15 | v0.3.55 | Update executable name in help/version output |
| 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 |
| 2017-08-08 | v0.3.49 | Added condition attribute |
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-693' title='goto source code'>[src]</a></span></h1>
</span><a class='srclink' href='../../src/cargo_make/types.rs.html#1-707' 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#650-657' title='goto source code'>[src]</a></span></h1>
</span><a class='srclink' href='../../src/cargo_make/types.rs.html#664-671' 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#648' 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#662' 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#648' 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#662' 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
8 changes: 4 additions & 4 deletions docs/api/cargo_make/types/struct.ConfigSection.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#616-621' title='goto source code'>[src]</a></span></h1>
</span><a class='srclink' href='../../src/cargo_make/types.rs.html#630-635' 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;,
Expand All @@ -61,7 +61,7 @@ <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#623-646' title='goto source code'>[src]</a></span></h3>
</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 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 All @@ -71,10 +71,10 @@ <h1 id='arguments' class='section-header'><a href='#arguments'>Arguments</a></h1
<ul>
<li><code>task</code> - The task to copy from</li>
</ul>
</div></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.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#614' title='goto source code'>[src]</a></span></h3>
</div></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.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#628' 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.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#614' 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.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#628' 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.ConfigSection.html" title="struct cargo_make::types::ConfigSection">ConfigSection</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
Loading

0 comments on commit 6c3d80d

Please sign in to comment.