-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5ddf55
commit 8fb540f
Showing
6 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
task all { | ||
./Build.ps1 | ||
} | ||
|
||
task show { | ||
./Build.ps1 ? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<# | ||
.Synopsis | ||
Directly invocable script with build tasks (variant 2). | ||
#> | ||
|
||
[CmdletBinding()] | ||
param( | ||
# Choose the default: '*' ~ run all; '?' - show tasks; '.' or nothing ~ default task. | ||
[string[]]$Tasks = '*' | ||
, | ||
# Other parameters as usual. | ||
[string]$Param1 = 'Value1' | ||
) | ||
|
||
# Outer script scope, suitable for common functions and variables for reading. | ||
|
||
# This function is available for tasks. | ||
function Get-CommonSomething { | ||
'CommonSomething' | ||
} | ||
|
||
# This variable is available for reading as $Var1 and not "easily" available for writing. | ||
$Var1 = 10 | ||
|
||
# Call the engine with the script block adding tasks. | ||
Invoke-Build $Tasks { | ||
# Inner script scope, this is the usual build script body with tasks, variables, functions. | ||
|
||
# This variable is available for reading as $Var1 or $Script:Var2 and for writing as $Script:Var2 | ||
$Var2 = 20 | ||
|
||
# Synopsis: $ErrorActionPreference is set to 1, equivalent "Stop" or [System.Management.Automation.ActionPreference]::Stop. | ||
task ErrorActionPreferenceIsStop { | ||
equals $ErrorActionPreference 1 | ||
} | ||
|
||
# Synopsis: The build folder is this script folder regardless of the location where this script is invoked from. | ||
task BuildRootIsThisScriptRoot { | ||
equals $BuildRoot $PSScriptRoot | ||
equals "$PWD" $PSScriptRoot | ||
} | ||
|
||
# Synopsis: Script functions are available for tasks. | ||
task ScriptFunctions { | ||
Get-CommonSomething | ||
} | ||
|
||
# Synopsis: Script parameters. | ||
task ScriptParameters { | ||
"Tasks = $Tasks" | ||
"Param1 = $Param1" | ||
} | ||
|
||
# Synopsis: Script variables. | ||
task ScriptVariables { | ||
"Var1 = $Var1" | ||
"Var2 = $Var2" | ||
++$Script:Var2 | ||
"Var2 = $Var2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Directly invokable build scripts (variant 2) | ||
|
||
Build scripts are normally invoked by the engine `Invoke-Build`, not directly. | ||
If this is inconvenient then decorate a script to make it directly invokable. | ||
Variant 1 is described here: [Direct](../Direct), with scripts either invoked | ||
directly or by `Invoke-Build`. | ||
|
||
Another way, variant 2, is defining build tasks in a script like this: | ||
|
||
```powershell | ||
[CmdletBinding()] | ||
param( | ||
[string[]]$Tasks | ||
) | ||
Invoke-Build $Tasks { | ||
task build { | ||
... | ||
} | ||
task clean { | ||
... | ||
} | ||
... | ||
} | ||
``` | ||
|
||
Such scripts cannot be invoked by `Invoke-Build`, they are not composed as | ||
build scripts. They are normal PowerShell scripts but they have tasks and | ||
work similar to build scripts. | ||
|
||
See the example script [Build.ps1](Build.ps1) and comments, try some calls: | ||
|
||
```powershell | ||
# run all tasks (because $Tasks default is set to '*') | ||
./Build.ps1 | ||
# run with parameters | ||
./Build.ps1 -Param1 testing | ||
# run specified tasks | ||
./Build.ps1 ScriptParameters, ScriptVariables | ||
# show task descriptions | ||
./Build.ps1 ? | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters