File tree Expand file tree Collapse file tree 15 files changed +53
-52
lines changed
examples/4.complex/v1.0/includes Expand file tree Collapse file tree 15 files changed +53
-52
lines changed Original file line number Diff line number Diff line change 1
1
[ ![ GitHub workflows (all tests)] ( https://github.com/wild-devops/pwshake/workflows/all%20tests/badge.svg )] ( /actions/workflows/tests.yml )
2
- [ ![ GitHub release (latest by date)] ( https://img.shields.io/github/v/release/wild-devops/pwshake )] ( /releases/tag/v1.5.0 )
2
+ [ ![ GitHub release (latest by date)] ( https://img.shields.io/github/v/release/wild-devops/pwshake )] ( /releases/tag/v1.5.1 )
3
3
[ ![ PowerShell Gallery] ( https://img.shields.io/powershellgallery/v/pwshake )] ( https://www.powershellgallery.com/packages/pwshake )
4
4
[ ![ PowerShell Gallery] ( https://img.shields.io/powershellgallery/dt/pwshake )] ( https://www.powershellgallery.com/packages/pwshake )
5
5
@@ -123,7 +123,7 @@ invoke_tasks:
123
123
attributes:
124
124
pwshake_module_path: /path/to/pwshake/module/source
125
125
pwshake_path: /absolute/path/to/your/working/directory
126
- pwshake_version: 1.6.0
126
+ pwshake_version: 1.5.1
127
127
work_dir: /absolute/path/to/process/working/directory
128
128
pwshake_log_path: /absolute/path/to/your/working/directory/my_pwshake.log
129
129
some_attribute: this is an attribute value
Original file line number Diff line number Diff line change @@ -6,5 +6,5 @@ attributes_overrides:
6
6
tasks :
7
7
role1 : role3
8
8
apply_roles :
9
- - role1
10
- - role2
9
+ - role1
10
+ - role2
Original file line number Diff line number Diff line change 2
2
role2 : role2
3
3
role3 : role3
4
4
apply_roles :
5
- - role1
6
- - role2
7
- - role5
8
- - role6
5
+ - role1
6
+ - role2
7
+ - role5
8
+ - role6
Original file line number Diff line number Diff line change 12
12
RootModule = ' pwshake.psm1'
13
13
14
14
# Version number of this module.
15
- ModuleVersion = ' 1.6.0 '
15
+ ModuleVersion = ' 1.5.1 '
16
16
17
17
# Supported PSEditions
18
18
# CompatiblePSEditions = @()
Original file line number Diff line number Diff line change 1
1
function Arrange-Tasks {
2
2
[CmdletBinding ()]
3
3
param (
4
- [Parameter (Position = 0 , Mandatory = $true )]
5
- [hashtable ] $config ,
4
+ [Parameter (Position = 0 , Mandatory = $true , ValueFromPipeline = $true )]
5
+ [object []] $depends_on ,
6
6
7
- [Parameter (Position = 1 , Mandatory = $false )]
8
- [object []] $depends_on = $config .invoke_tasks ,
7
+ [Parameter (Mandatory = $false )]
8
+ [hashtable ] $config = (Peek - Config) ,
9
9
10
- [Parameter (Position = 2 , Mandatory = $false )]
10
+ [Parameter (Mandatory = $false )]
11
11
[int ]$depth = 0
12
12
)
13
13
process {
@@ -18,19 +18,21 @@ function Arrange-Tasks {
18
18
$tasks = @ ()
19
19
20
20
foreach ($name in $depends_on ) {
21
+ " Arrange-Tasks:foreach:`$ name:`n $ ( cty $name ) " | f- log- dbg
21
22
if (-not ($config.tasks.Keys -contains $name )) {
22
23
throw " Task '$name ' is undefined in the PWSHAKE config."
23
24
}
24
25
25
26
$task = Build-Task $config.tasks [$name ] $name
26
27
27
28
if ($task.depends_on ) {
28
- $tasks += (Arrange - Tasks $config $ task.depends_on ($depth + 1 ))
29
+ $tasks += ($ task.depends_on | Arrange - Tasks - depth ($depth + 1 ))
29
30
}
30
31
31
32
$tasks += $task
32
33
}
33
34
35
+ " Arrange-Tasks:Out:`$ tasks:`n $ ( cty $tasks ) " | f- log- dbg
34
36
return $tasks
35
37
}
36
38
}
Original file line number Diff line number Diff line change @@ -15,10 +15,10 @@ function Interpolate-Attributes {
15
15
" Interpolate-Attributes:$ ( $counter ) :`$ substitute:$substitute " | f- log- dbg
16
16
if ($substitute -match ' ^\$\((?<eval>.*)\)$' ) {
17
17
" Interpolate-Attributes:$ ( $counter ) :`$ eval:{$ ( $matches.eval ) }" | f- log- dbg
18
- $value = Invoke-Expression ( ConvertFrom-Json " `" $ ( $matches.eval ) `" " )
18
+ $value = " `" $ ( $matches.eval ) `" " | ConvertFrom-Json | Invoke-Expression
19
19
} elseif ($substitute -match ' ^(?<filter>\$\S+):(?<input>.*)' ) {
20
20
" Interpolate-Attributes:$ ( $counter ) :`$ filter:{$ ( $matches.filter ) }:`$ input:{$ ( $matches.input ) }" | f- log- dbg
21
- $value = $ matches.input | & " f-$ ( $matches.filter ) "
21
+ $value = " `" $ ( $ matches.input ) `" " | ConvertFrom-Json | & f- $ ($matches.filter )
22
22
" Interpolate-Attributes:$ ( $counter ) :`$ value:{$value }" | f- log- dbg
23
23
} else {
24
24
$value = Invoke-Expression " `$ config.attributes.$substitute " - ErrorAction Stop
Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ function Invoke-Step {
15
15
16
16
try {
17
17
" Invoke-Step:In:$ ( @ {' $_' = $_ } | ConvertTo-Yaml ) " | f- log- dbg
18
- $step = $step | Build-Step
19
- " Invoke-Step:Build-Step:$ ( @ {' $step ' = $step } | ConvertTo-Yaml ) " | f- log- dbg
18
+ $step = $_ = $_ | Build-Step
19
+ " Invoke-Step:Build-Step:$ ( @ {' $_ ' = $_ } | ConvertTo-Yaml ) " | f- log- dbg
20
20
21
21
if ($step [' $context' ].template_key) {
22
22
# add alias to simplify templates definition
@@ -59,7 +59,7 @@ function Invoke-Step {
59
59
} catch {
60
60
$_ | f- log- err
61
61
if ($step.on_error -eq ' throw' ) {
62
- (Peek- Context).thrown = $true
62
+ (Peek- Context).caught = $true
63
63
throw $_
64
64
}
65
65
} finally {
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ function Invoke-Task {
4
4
[Parameter (Position = 0 , Mandatory = $true , ValueFromPipeline = $true )]
5
5
[hashtable ]$task ,
6
6
7
- [Parameter (Position = 1 , Mandatory = $false )]
7
+ [Parameter (Mandatory = $false )]
8
8
[hashtable ]$config = (Coalesce (Peek- Config), @ {})
9
9
)
10
10
process {
@@ -21,11 +21,11 @@ function Invoke-Task {
21
21
Push-Location (Build-Path " $ ( $task.work_dir ) " $config )
22
22
23
23
foreach ($step in $task.steps ) {
24
- (Peek- Context).thrown = $false
24
+ (Peek- Context).caught = $false
25
25
$step | Invoke-Step - work_dir $task.work_dir
26
26
}
27
27
} catch {
28
- if (-not (Peek- Context).thrown ) {
28
+ if (-not (Peek- Context).caught ) {
29
29
# if it was not thrown in execution context, it should be logged
30
30
$_ | f- log- err
31
31
}
Original file line number Diff line number Diff line change @@ -61,15 +61,14 @@ function Invoke-pwshake {
61
61
}
62
62
}
63
63
64
- $arranged_tasks = Arrange - Tasks (Peek- Config)
64
+ $arranged_tasks = (Peek- Config).invoke_tasks | Arrange - Tasks
65
65
" Invoke-pwshake:`$ arranged_tasks:`n $ ( ConvertTo-Yaml $arranged_tasks ) " | f- log- dbg
66
66
67
67
Push-Location (Peek- Config).attributes.work_dir
68
- foreach ($task in $arranged_tasks ) {
69
- Invoke-Task $task
70
- }
68
+ $arranged_tasks | Invoke-Task
69
+
71
70
} catch {
72
- if (-not (Peek- Context).thrown ) {
71
+ if (-not (Peek- Context).caught ) {
73
72
# if it was not thrown in execution context, it should be logged
74
73
$_ | f- log- err
75
74
}
Original file line number Diff line number Diff line change 1
1
pwshake-context :
2
2
templates :
3
3
invoke_steps :
4
- each :
5
- items : $[[$_.invoke_steps]]
6
- action : $_ | Invoke-Step
4
+ powershell : $_.invoke_steps | Invoke-Step
Original file line number Diff line number Diff line change @@ -2,19 +2,10 @@ pwshake-context:
2
2
templates :
3
3
invoke_tasks :
4
4
powershell : |
5
- $tasks = Arrange-Tasks $config $_.invoke_tasks
6
- foreach ($task in $tasks) {
7
- Invoke-Task $task $config
8
- }
5
+ $_.invoke_tasks | Arrange-Tasks | Invoke-Task
9
6
apply_roles :
10
7
powershell : |
11
- $tasks = Arrange-Tasks $config $_.apply_roles
12
- foreach ($task in $tasks) {
13
- Invoke-Task $task $config
14
- }
8
+ $_.apply_roles | Arrange-Tasks | Invoke-Task
15
9
invoke_run_lists :
16
10
powershell : |
17
- $tasks = Arrange-Tasks $config $_.invoke_run_lists
18
- foreach ($task in $tasks) {
19
- Invoke-Task $task $config
20
- }
11
+ $_.invoke_run_lists | Arrange-Tasks | Invoke-Task
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ pwshake-context:
4
4
powershell : |
5
5
$paths = $config.scripts_directories | ForEach-Object { Join-Path $config.attributes.pwshake_path -ChildPath $_ }
6
6
$script_path = Get-ChildItem $paths -File `
7
- | Where-Object BaseName -eq $step .script `
7
+ | Where-Object BaseName -eq $_ .script `
8
8
| Select-Object -ExpandProperty FullName
9
9
"Script file: $script_path" | f-log-info
10
- if (-not $script_path) { throw "Script file: $($step .script).* not found." }
10
+ if (-not $script_path) { throw "Script file: $($_ .script).* not found." }
11
11
& $script_path -attributes $config.attributes
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ Context "Arrange-Tasks" {
8
8
$config.invoke_tasks = @ (' role1' )
9
9
10
10
It " Should return an Object[]" {
11
- (Arrange- Tasks $config ) -is [Object []] | Should - BeTrue
11
+ ($config .invoke_tasks | Arrange- Tasks) -is [Object []] | Should - BeTrue
12
12
}
13
13
14
14
It " Should throw on circular reference in depends_on" {
@@ -18,7 +18,7 @@ Context "Arrange-Tasks" {
18
18
depends_on = @ (' role1' )
19
19
}
20
20
21
- { Arrange- Tasks $config } `
21
+ { $config .invoke_tasks | Arrange- Tasks } `
22
22
| Should - Throw " Circular reference detected for dependant tasks in:"
23
23
}
24
24
}
Original file line number Diff line number Diff line change @@ -138,11 +138,10 @@ Context "Build-Template" {
138
138
'@ | ConvertFrom-Yaml | ForEach-Object steps | Select-Object - First 1 | `
139
139
Build-Template | Ensure- Template - sb { param ($actual )
140
140
$actual.on_error | Should - Be ' continue'
141
- $actual.powershell | Should - BeLike ' if (-not $each.items) { throw*'
142
- $actual.items [0 ].echo | Should - Be ' say'
143
- $actual.items [1 ].invoke_steps[0 ].echo | Should - Be ' hello'
144
- $actual.action | Should - Be ' $_ | Invoke-Step'
145
- $actual [' $context' ].template_key | Should - Be ' each'
141
+ $actual.powershell | Should - BeLike ' $_.invoke_steps | Invoke-Step'
142
+ $actual.invoke_steps [0 ].echo | Should - Be ' say'
143
+ $actual.invoke_steps [1 ].invoke_steps[0 ].echo | Should - Be ' hello'
144
+ $actual [' $context' ].template_key | Should - Be ' invoke_steps'
146
145
}
147
146
}
148
147
Original file line number Diff line number Diff line change @@ -121,4 +121,16 @@ Context "Interpolate-Attributes" {
121
121
}
122
122
} | Should - Throw " Circular reference detected for substitutions: {{a}} {{b}} {{c}}"
123
123
}
124
+
125
+ It " Should substitute special characters" {
126
+ $chars = ' `~!@#$qwest%^&*()_-=+\|][}{";?.,></№' + " '"
127
+
128
+ Interpolate- Attributes @ {
129
+ attributes = @ {a = " {{b}}" ;b = ' {{$secured:{{c}}}}' ;c = $chars };
130
+ } | Interpolate- Attributes | New-Variable - Name actual
131
+
132
+ $actual.attributes.a | Should - Be $chars
133
+ $actual.attributes.b | Should - Be $chars
134
+ $actual.attributes.c | Should - Be $chars
135
+ }
124
136
}
You can’t perform that action at this time.
0 commit comments