Skip to content

Commit

Permalink
made ignore/repeat work with push errors
Browse files Browse the repository at this point in the history
  • Loading branch information
majkinetor committed Feb 19, 2019
1 parent 978a78c commit 8537f44
Showing 1 changed file with 45 additions and 36 deletions.
81 changes: 45 additions & 36 deletions AU/Public/Update-AUPackages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Author: Miodrag Milic <[email protected]>
# Last Change: 08-May-2018


<#
.SYNOPSIS
Update all automatic packages
Expand Down Expand Up @@ -171,6 +170,38 @@ function Update-AUPackages {
$package_name = Split-Path $package_path -Leaf
Write-Verbose "Starting $package_name"
Start-Job -Name $package_name { #TODO: fix laxxed variables in job for BE and AE
function repeat_ignore([ScriptBlock] $Action) { # requires $Options
$run_no = 0
$run_max = if ($Options.RepeatOn) { if (!$Options.RepeatCount) { 2 } else { $Options.RepeatCount+1 } } else {1}

:main while ($run_no -lt $run_max) {
$run_no++
try {
$res = & $Action 6> $out
break main
} catch {
if ($run_no -ne $run_max) {
foreach ($msg in $Options.RepeatOn) {
if ($_.Exception -notlike "*${msg}*") { continue }
Write-Warning "Repeating $using:package_name ($run_no): $($_.Exception)"
if ($Options.RepeatSleep) { Write-Warning "Sleeping $($Options.RepeatSleep) seconds before repeating"; sleep $Options.RepeatSleep }
continue main
}
}
foreach ($msg in $Options.IgnoreOn) {
if ($_.Exception -notlike "*${msg}*") { continue }
Write-Warning "Ignoring $using:package_name ($run_no): $($_.Exception)"
"AU ignored on: $($_.Exception)" | Out-File -Append $out
$res = 'ignore'
break main
}
$type = if ($res) { $res.GetType() }
if ( "$type" -eq 'AUPackage') { $res.Error = $_ } else { return $_ }
}
}
$res
}

$Options = $using:Options

cd $using:package_path
Expand All @@ -187,51 +218,29 @@ function Update-AUPackages {
. $s $using:package_name $Options
}

$run_no = 0
$run_max = $Options.RepeatCount
$run_max = if ($Options.RepeatOn) { if (!$Options.RepeatCount) { 2 } else { $Options.RepeatCount+1 } } else {1}

:main while ($run_no -lt $run_max) {
$run_no++
$pkg = $null #test double report when it fails
try {
$pkg = ./update.ps1 6> $out
break main
} catch {
if ($run_no -ne $run_max) {
foreach ($msg in $Options.RepeatOn) {
if ($_.Exception -notlike "*${msg}*") { continue }
Write-Warning "Repeating $using:package_name ($run_no): $($_.Exception)"
if ($Options.RepeatSleep) { Write-Warning "Sleeping $($Options.RepeatSleep) seconds before repeating"; sleep $Options.RepeatSleep }
continue main
}
}
foreach ($msg in $Options.IgnoreOn) {
if ($_.Exception -notlike "*${msg}*") { continue }
"AU ignored on: $($_.Exception)" | Out-File -Append $out
$pkg = 'ignore'
break main
}
if ($pkg) { $pkg.Error = $_ }
}
}
$pkg = repeat_ignore { ./update.ps1 }
if (!$pkg) { throw "'$using:package_name' update script returned nothing" }

if (($pkg -eq 'ignore') -or ($pkg[-1] -eq 'ignore')) { return 'ignore' }

$pkg = $pkg[-1]
$type = $pkg.GetType()
if ( "$type" -ne 'AUPackage') { throw "'$using:package_name' update script didn't return AUPackage but: $type" }

if ($pkg.Updated -and $Options.Push) {
$pkg.Result += $r = Push-Package -All:$Options.PushAll
if ($LastExitCode -eq 0) {
$pkg.Pushed = $true
} else {
$pkg.Error = "Push ERROR`n" + ($r | select -skip 1)
$res = repeat_ignore {
$r = Push-Package -All:$Options.PushAll
if ($LastExitCode -eq 0) { return $r } else { throw $r }
}
}
if (($res -eq 'ignore') -or ($res[-1] -eq 'ignore')) { return 'ignore' }

if ($res -is [System.Management.Automation.ErrorRecord]) {
$pkg.Error = "Push ERROR`n" + $res
} else {
$pkg.Pushed = $true
$pkg.Result += $res
}
}

if ($Options.AfterEach) {
$s = [Scriptblock]::Create( $Options.AfterEach )
. $s $using:package_name $Options
Expand Down

0 comments on commit 8537f44

Please sign in to comment.