-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
8e1cee3
commit a8e186b
Showing
7 changed files
with
126 additions
and
2 deletions.
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
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,31 @@ | ||
if ($PSVersionTable.PSVersion.Major -eq 2) {return task skipV2} | ||
|
||
# Default task of case1 with default parameters. | ||
task case1 { | ||
($r = Invoke-Build -Case case1) | ||
assert ($r -like 'case file : case1\case1.tasks.ps1') | ||
assert ($r -like 'configuration : Release') | ||
assert ($r -like 'var1 : root value 1') | ||
} | ||
|
||
# Default task of case2 with custom parameters. | ||
task case2 { | ||
($r = Invoke-Build -Case case2 -Configuration Debug) | ||
assert ($r -like 'case file : case2\case2.tasks.ps1') | ||
assert ($r -like 'configuration : Debug') | ||
assert ($r -like 'var1 : changed by case2') | ||
} | ||
|
||
# Common root task in case1. | ||
task case1_root1 { | ||
($r = Invoke-Build root1 -Case case1) | ||
assert ($r -like 'case : *\case1') | ||
assert ($r -like 'var1 : root value 1') | ||
} | ||
|
||
# Common root task in case2. | ||
task case2_root1 { | ||
($r = Invoke-Build root1 -Case case2) | ||
assert ($r -like 'case : *\case2') | ||
assert ($r -like 'var1 : changed by case2') | ||
} |
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,46 @@ | ||
# SubCases | ||
|
||
Inspired by [#222](https://github.com/nightroman/Invoke-Build/issues/222). | ||
|
||
**File structure** | ||
|
||
- `root.build.ps1` | ||
- `case1` | ||
- `case1.tasks.ps1` | ||
- `case2` | ||
- `case2.tasks.ps1` | ||
|
||
**Build parameters** | ||
|
||
```powershell | ||
param( | ||
[Parameter(Mandatory=1)] | ||
[string]$Case | ||
, | ||
[string]$Configuration = 'Release' | ||
) | ||
``` | ||
|
||
In this example the parameter `$Case` is mandatory and the specified case script is always dot-sourced. | ||
|
||
But the script could be designed with an optional `$Case` or using the default case. | ||
|
||
Examples: | ||
|
||
```powershell | ||
# case1, default task with default parameters | ||
Invoke-Build -Case case1 | ||
# case2, common task with custom parameters | ||
Invoke-Build root1 -Case case2 -Configuration Debug | ||
``` | ||
|
||
**Some features** | ||
|
||
Let's use the term "assets" for script scope variables and functions. | ||
|
||
- `Invoke-Build` without `-File` works in the root and child folders. | ||
- The root script parameters and assets are available for case tasks. | ||
- The case specific assets are available for common root tasks. | ||
- Cases may change root assets defined before dot-sourcing. | ||
- See features in action shown by [.test.ps1](.test.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,11 @@ | ||
|
||
# Case assets, may be used by case tasks and root tasks. | ||
$CaseRoot = $PSScriptRoot | ||
|
||
# Synopsis: This task is case specific. | ||
# It may use assets from the root script. | ||
task task1 { | ||
"case file : $CaseFile" | ||
"configuration : $Configuration" | ||
"var1 : $Var1" | ||
} |
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,14 @@ | ||
|
||
# This case overrides the root variable. | ||
$Var1 = 'changed by case2' | ||
|
||
# Case assets, may be used by case tasks and root tasks. | ||
$CaseRoot = $PSScriptRoot | ||
|
||
# Synopsis: This task is case specific. | ||
# It may use assets from the root script. | ||
task task1 { | ||
"case file : $CaseFile" | ||
"configuration : $Configuration" | ||
"var1 : $Var1" | ||
} |
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,21 @@ | ||
param( | ||
[Parameter(Mandatory=1)] | ||
[string]$Case | ||
, | ||
[string]$Configuration = 'Release' | ||
) | ||
|
||
# Common variables. Case scripts may use them and may override them. | ||
$Var1 = 'root value 1' | ||
|
||
# Dot-source the specified case tasks. | ||
$CaseFile = "$Case\$Case.tasks.ps1" | ||
requires -Path $CaseFile | ||
. $CaseFile | ||
|
||
# Synopsis: This task is common for all cases. | ||
# It may use assets from the case script. | ||
task root1 { | ||
"case : $CaseRoot" # expected to be defined by cases | ||
"var1 : $Var1" # defined by root, may be changed by cases (case2) | ||
} |