Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
majkinetor committed Feb 4, 2019
1 parent 0f0c0ad commit 41775cb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
64 changes: 33 additions & 31 deletions AU/Public/Update-AUPackages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -187,51 +217,23 @@ 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
$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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 41775cb

Please sign in to comment.