Skip to content

Commit c514f0f

Browse files
authored
Merge pull request #11 from wild-devops/develop
v1.5.4
2 parents 594980c + 18b7466 commit c514f0f

File tree

10 files changed

+59
-31
lines changed

10 files changed

+59
-31
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![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.3)
2+
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/wild-devops/pwshake)](../../releases/tag/v1.5.4)
33
[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/pwshake)](https://www.powershellgallery.com/packages/pwshake)
44
[![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/pwshake)](https://www.powershellgallery.com/packages/pwshake)
55

@@ -123,7 +123,7 @@ invoke_tasks:
123123
attributes:
124124
pwshake_module_path: /path/to/pwshake/module/source
125125
pwshake_path: /absolute/path/to/your/working/directory
126-
pwshake_version: 1.5.3
126+
pwshake_version: 1.5.4
127127
work_dir: /absolute/path/to/process/working/directory
128128
pwshake_log_path: /absolute/path/to/your/working/directory/my_pwshake.log
129129
some_attribute: this is an attribute value

examples/4.complex/v1.0/module/pwshake.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,29 @@ includes:
77

88
tasks:
99
errors:
10+
- name: skip errors0
11+
on_error: continue
12+
cmd: "echo simulate error0 1>&2 && exit 0"
1013
- name: skip errors1
1114
on_error: continue
12-
cmd: "echo simulate error1 && exit 1"
15+
cmd: "echo simulate error1 1>&2 && exit 1"
1316
- name: skip errors2
1417
on_error: continue
15-
pwsh: python3 -c "import sys; print('simulate error2', file=sys.stderr, flush=True); exit(0)"
18+
pwsh: python3 -c "import sys; print('simulate error2', file=sys.stderr, flush=True); exit(0)" 2>&1
1619
- name: skip errors3
1720
on_error: continue
18-
pwsh: python3 -c "import sys; print('simulate error3', file=sys.stderr, flush=True); exit(1)"
21+
pwsh: python3 -c "import sys; print('simulate error3', file=sys.stderr, flush=True); exit(1)" 2>&1
1922
- name: skip errors4
2023
on_error: continue
2124
pwsh: throw 'simulate error4'
22-
- name: pwsh errors
25+
- name: python errors
2326
pwsh: |
2427
python3 {{pwshake_path}}/errs.py {{py_arg}} 2>&1
2528
- name: call remote powershell with errors
2629
pwsh: |
2730
Invoke-Command -ScriptBlock {
2831
if ($true) {
29-
& '{{pwshake_path}}/call_throw.ps1' 'dir{{pwsh_arg}}'
32+
& '{{pwshake_path}}/call_throw.ps1' dir{{pwsh_arg}}
3033
}
3134
} -InformationAction Ignore -ErrorAction Stop
3235

examples/5.templates/v1.4/nested_templates.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ tasks:
2222
- 'deep nested version':
2323
msbuild_version:
2424
- 'circular reference error':
25-
on_error: continue
26-
circular1:
25+
on_error: continue
26+
circular1:
2727

2828
test_all:
2929
depends_on:

pwshake/context/filters.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pwshake-context:
8787
f-log-err: |-
8888
{
8989
if ((Peek-Verbosity) -lt [PWSHAKE.VerbosityLevel]::Error) { return }
90+
$Host.UI.WriteLine([ConsoleColor]'Red',[Console]::BackgroundColor,($_ | f-error))
9091
if ((Peek-Verbosity) -eq [PWSHAKE.VerbosityLevel]::Debug) {
9192
$_.ScriptStackTrace.Split("`n") | Select-Object -First 5 | ForEach-Object {
9293
$Host.UI.WriteLine([ConsoleColor]::DarkYellow,[Console]::BackgroundColor,"TRACE: $_")

pwshake/pwshake.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'pwshake.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.5.3'
15+
ModuleVersion = '1.5.4'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()

pwshake/scripts/Build-Template.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ function Build-Template {
2020
$step = $step.Clone()
2121
}
2222

23-
if ($depth -gt ${global:pwshake-context}.options.max_depth) {
24-
throw "Circular reference detected for template:`n$($step | ConvertTo-Yaml)"
25-
}
26-
2723
$template_key = Compare-Object (@() + $step.Keys) (@() + ${global:pwshake-context}.templates.Keys) `
2824
-PassThru -IncludeEqual -ExcludeDifferent # intersection
2925
"Build-Template:`$template_key = '$template_key'" | f-log-dbg
@@ -36,6 +32,11 @@ function Build-Template {
3632
$step['$context'].template_key = "$template_key"
3733
}
3834

35+
if ($depth -gt ${global:pwshake-context}.options.max_depth) {
36+
"Build-Template:Circular-reference:`n$($step | ConvertTo-Yaml)" | f-log-dbg
37+
throw "Circular reference detected for template: $template_key"
38+
}
39+
3940
$template = ${global:pwshake-context}.templates.$($template_key).Clone()
4041
$template = Merge-Hashtables $template $step # add step attributes
4142
if ($step.$($template_key) -is [hashtable]) {

pwshake/scripts/Cmd-Shell.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ function Cmd-Shell {
2020
$errorMessage = "cmd-shell: '$cmd' failed."
2121
}
2222

23-
$lastErr = $null
23+
$lastErr = $null; ${log-Err} = @(); ${log-Out} = @()
2424
if (${is-Windows}) {
2525
Write-Host "cmd: $cmd"
26-
cmd /c $cmd *>&1 | Tee-Object -Variable cmdOut
26+
& cmd /c $cmd *>&1 -ErrorVariable log-Err | Tee-Object -Variable log-Out
2727
} else {
2828
Write-Host "bash: $cmd"
29-
bash -c $cmd *>&1 | Tee-Object -Variable cmdOut
29+
& bash -c $cmd *>&1 -ErrorVariable log-Err | Tee-Object -Variable log-Out
3030
}
3131

3232
if ($LASTEXITCODE -ne 0) {
3333
if ($retries -gt 1) {
3434
$cmd | Cmd-Shell -errorMessage $errorMessage -retries ($retries - 1) -throwOnError $throwOnError
3535
} elseif ($throwOnError) {
36-
$lastErr = $cmdOut | Where-Object {$_ -is [System.Management.Automation.ErrorRecord]} | Select-Object -Last 1
36+
$lastErr = (${log-Err} + ${log-Out}) | Where-Object {$_ -is [System.Management.Automation.ErrorRecord]} | Select-Object -Last 1
3737
if ($lastErr) {
3838
$errorMessage = $lastErr.Exception.Message
3939
}

pwshake/scripts/Invoke-Step.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,30 @@ function Invoke-Step {
4040
return;
4141
}
4242

43-
$logOutputs = @()
44-
$global:LASTEXITCODE = 0
43+
${log-Out} = @(); ${log-Err} = @(); $global:LASTEXITCODE = 0
4544
"Invoke-Step:powershell: {`n$($step.powershell)}" | f-log-dbg
4645
if ($config.attributes.pwshake_dry_run) {
4746
"`tBypassed because of -DryRun: $($config.attributes.pwshake_dry_run)" | f-log-info
48-
return
47+
return;
4948
}
50-
Invoke-Expression $step.powershell -ErrorAction 'Continue' *>&1 | Tee-Object -Variable logOutputs `
49+
Invoke-Expression $step.powershell *>&1 -ErrorVariable log-Err | Tee-Object -Variable log-Out `
5150
| f-log-min
5251
if ((($LASTEXITCODE -ne 0) -or (-not $?)) -and ($step.on_error -eq 'throw')) {
53-
$lastErr = $logOutputs | Where-Object { $_ -is [Management.Automation.ErrorRecord] } | Select-Object -Last 1
52+
$lastErr = (${log-Err} + ${log-Out}) | Where-Object { $_ -is [Management.Automation.ErrorRecord] } | Select-Object -Last 1
5453
if (-not $lastErr) {
5554
$lastErr = "$($step.name) failed."
5655
}
5756
throw $lastErr
5857
}
59-
} catch {
58+
}
59+
catch {
6060
$_ | f-log-err
6161
if ($step.on_error -eq 'throw') {
6262
(Peek-Context).caught = $true
6363
throw $_
6464
}
65-
} finally {
65+
}
66+
finally {
6667
${global:pwshake-context}.hooks['invoke-step'].onExit | ForEach-Object {
6768
"Invoke-Step:finally:{$_}" | f-log-dbg; Invoke-Expression $_
6869
}

pwshake/scripts/Log-Output.ps1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ function Log-Output {
1313
process {
1414
if ((Peek-Verbosity) -eq [PWSHAKE.VerbosityLevel]::Quiet) { return }
1515

16-
if ($message -is [Management.Automation.ErrorRecord]) {
17-
$message = "$message" | f-mask-secured
18-
"ERROR: ${message}" | f-tmstmp | Add-Content -Path $config.attributes.pwshake_log_path
16+
$message = "$message" | f-mask-secured
17+
$message | f-tmstmp | Add-Content -Path $config.attributes.pwshake_log_path
18+
if ($_ -is [Management.Automation.ErrorRecord]) {
1919
$Host.UI.WriteLine([ConsoleColor]"Red",[Console]::BackgroundColor,$message)
2020
} else {
21-
$message = "$message" | f-mask-secured
22-
$message | f-tmstmp | Add-Content -Path $config.attributes.pwshake_log_path
2321
if ($ForegroundColor) {
2422
$Host.UI.WriteLine([ConsoleColor]"$ForegroundColor",[Console]::BackgroundColor,$message)
2523
} else {

tests/3.public.Specs.ps1

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ Describe "PWSHAKE public functions" {
5050
Invoke-pwshake (Get-RelativePath 'examples\4.complex\v1.0\module\pwshake.yaml') -Roles 'errors' -Metadata @{py_arg='0'}
5151
} | Should -Throw 'ZeroDivisionError: division by zero'
5252
$pwshake_log = Get-Content (Get-RelativePath 'examples\4.complex\v1.0\module\pwshake.log')
53+
$pwshake_log | Select-String "] simulate error0" | Should -Not -BeNullOrEmpty
54+
$pwshake_log | Select-String "] simulate error1" | Should -Not -BeNullOrEmpty
55+
$pwshake_log | Select-String "] ERROR: simulate error1" | Should -Not -BeNullOrEmpty
56+
$pwshake_log | Select-String "] simulate error2" | Should -Not -BeNullOrEmpty
57+
$pwshake_log | Select-String "] simulate error3" | Should -Not -BeNullOrEmpty
58+
$pwshake_log | Select-String "] ERROR: simulate error4" | Should -Not -BeNullOrEmpty
5359
$pwshake_log | Select-String "] start0" | Should -Not -BeNullOrEmpty
5460
$pwshake_log | Select-String "] noerr0" | Should -Not -BeNullOrEmpty
55-
$pwshake_log | Select-String "] ERROR: err0" | Should -Not -BeNullOrEmpty
61+
$pwshake_log | Select-String "] err0" | Should -Not -BeNullOrEmpty
5662
$pwshake_log | Select-String "] ERROR: ZeroDivisionError: division by zero" | Should -Not -BeNullOrEmpty
5763
$pwshake_log | Select-String "] Try call file: pwshake0" | Should -BeNullOrEmpty
5864
}
@@ -63,6 +69,24 @@ Describe "PWSHAKE public functions" {
6369
-Roles 'errors' -Metadata @{pwsh_arg='42'} -Verbosity 'Minimal'
6470
} | Should -Throw -ExceptionType ([Management.Automation.CommandNotFoundException])
6571
$pwshake_log = Get-Content (Get-RelativePath 'examples\4.complex\v1.0\module\pwshake.log')
72+
$pwshake_log | Select-String "] simulate error0" | Should -Not -BeNullOrEmpty
73+
$pwshake_log | Select-String "] simulate error1" | Should -Not -BeNullOrEmpty
74+
$pwshake_log | Select-String "] ERROR: simulate error1" | Should -Not -BeNullOrEmpty
75+
$pwshake_log | Select-String "] simulate error2" | Should -Not -BeNullOrEmpty
76+
$pwshake_log | Select-String "] simulate error3" | Should -Not -BeNullOrEmpty
77+
$pwshake_log | Select-String "] ERROR: simulate error4" | Should -Not -BeNullOrEmpty
78+
$pwshake_log | Select-String "] start42" | Should -Not -BeNullOrEmpty
79+
$pwshake_log | Select-String "] noerr0" | Should -Not -BeNullOrEmpty
80+
$pwshake_log | Select-String "] err0" | Should -Not -BeNullOrEmpty
81+
$pwshake_log | Select-String "] noerr1" | Should -Not -BeNullOrEmpty
82+
$pwshake_log | Select-String "] err1" | Should -Not -BeNullOrEmpty
83+
$pwshake_log | Select-String "] noerr2" | Should -Not -BeNullOrEmpty
84+
$pwshake_log | Select-String "] err2" | Should -Not -BeNullOrEmpty
85+
$pwshake_log | Select-String "] noerr3" | Should -Not -BeNullOrEmpty
86+
$pwshake_log | Select-String "] err3" | Should -Not -BeNullOrEmpty
87+
$pwshake_log | Select-String "] noerr4" | Should -Not -BeNullOrEmpty
88+
$pwshake_log | Select-String "] err4" | Should -Not -BeNullOrEmpty
89+
$pwshake_log | Select-String "] end" | Should -Not -BeNullOrEmpty
6690
$pwshake_log | Select-String "] Try call file: dir42" | Should -Not -BeNullOrEmpty
6791
}
6892

0 commit comments

Comments
 (0)