diff --git a/AU/Public/Update-AUPackages.ps1 b/AU/Public/Update-AUPackages.ps1 index 2f5a4869..c853ed7f 100644 --- a/AU/Public/Update-AUPackages.ps1 +++ b/AU/Public/Update-AUPackages.ps1 @@ -171,6 +171,36 @@ 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 } + "AU ignored on: $($_.Exception)" | Out-File -Append $out + $res = 'ignore' + break main + } + # if ($pkg) { $pkg.Error = $_ } + } + } + $res + } + $Options = $using:Options cd $using:package_path @@ -187,36 +217,8 @@ 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] @@ -224,14 +226,14 @@ function Update-AUPackages { 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 + $pkg.Result += $r = repeat_ignore { Push-Package -All:$Options.PushAll } if ($LastExitCode -eq 0) { $pkg.Pushed = $true } else { $pkg.Error = "Push ERROR`n" + ($r | select -skip 1) } } - + if ($Options.AfterEach) { $s = [Scriptblock]::Create( $Options.AfterEach ) . $s $using:package_name $Options diff --git a/README.md b/README.md index b9f42e46..1d035da9 100644 --- a/README.md +++ b/README.md @@ -271,6 +271,8 @@ Points 2-4 do not apply if you set the explicit version using the variable `au_V Force can be triggered also from the `au_GetLatest` function. This may be needed if remote version doesn't change but there was nevertheless change on the vendor site. See the [example](https://github.com/majkinetor/au-packages/blob/master/cpu-z.install/update.ps1#L18-L39) on how to update the package when remote version is unchanged but hashsum of the installer changes. +**Note**: You can add the following function to your Powershell profile to speed up package development: `function fup { $global:au_force = $true; ./update.ps1 }` + ### Global variables To avoid changing the `./update.ps1` when troubleshooting or experimenting you can set up any **already unset** `update` parameter via global variable. The names of global variables are the same as the names of parameters with the prefix `au_`. As an example, the following code will change the update behavior so that URL is not checked for existence and MIME type and update is forced: