Skip to content

Commit

Permalink
Merge pull request majkinetor#174 from Thilas/fix-updated-stream-version
Browse files Browse the repository at this point in the history
Fix updated stream version
  • Loading branch information
majkinetor authored Jan 2, 2019
2 parents 5770b88 + 6746f8a commit 46edb02
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 17 deletions.
6 changes: 3 additions & 3 deletions AU/Plugins/Report/text.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $Title = if ($Params.Title) { $Params.Title } else { 'Update-AUPackages'

#==============================================================================

function title($txt) { "r`n{0}`r`n{1}`r`n" -f $txt,('-'*$txt.Length) }
function title($txt) { "`r`n{0}`r`n{1}`r`n" -f $txt,('-'*$txt.Length) }
function indent($txt, $level=4) { $txt -split "`n" | % { ' '*$level + $_ } }

$now = $Info.startTime.ToUniversalTime().ToString('yyyy-MM-dd HH:mm')
Expand Down Expand Up @@ -31,15 +31,15 @@ if ($Info.pushed) {
$Info.result.pushed | select 'Name', 'Updated', 'Pushed', 'RemoteVersion', 'NuspecVersion' | ft | Out-String | set r
indent $r 2

$ok | % { $_.Name; indent $_.Result; "" }
$Info.result.pushed | % { $_.Name; indent $_.Result; "" }
}

if ($Info.error_count.total) {
title Errors
$Info.result.errors | select 'Name', 'NuspecVersion', 'Error' | ft | Out-String | set r
indent $r 2

$Info.result.errors | % { $_.Name; ident $_.Error; "" }
$Info.result.errors | % { $_.Name; indent $_.Error; "" }
}


Expand Down
6 changes: 5 additions & 1 deletion AU/Public/Update-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,11 @@ function Update-Package {
}
$package.Updated = $false
$package.Streams = $allStreams
$package.Streams.Values | ? { $_.Updated } | % { $package.Updated = $true }
$package.Streams.Values | ? { $_.Updated } | % {
$package.NuspecVersion = $_.NuspecVersion
$package.RemoteVersion = $_.RemoteVersion
$package.Updated = $true
}
} else {
'' | result
set_latest $res $package.NuspecVersion
Expand Down
98 changes: 98 additions & 0 deletions tests/Update-AUPackages.Streams.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,104 @@ Describe 'Update-AUPackages using streams' -Tag updateallstreams {
}

Context 'Plugins' {
It 'should execute text Report plugin' {
gc $global:au_Root\test_package_with_streams_1\update.ps1 | set content
$content -replace '@\{.+1\.3.+\}', "@{ Version = '1.3.2' }" | set content
$content -replace '@\{.+1\.2.+\}', "@{ Version = '1.2.4' }" | set content
$content | sc $global:au_Root\test_package_with_streams_1\update.ps1

$Options.Report = @{
Type = 'text'
Path = "$global:au_Root\report.txt"
}

$res = updateall -NoPlugins:$false -Options $Options 6> $null

$pattern = "\bFinished $pkg_no packages\b[\S\s]*"
$pattern += '\b1 updated\b[\S\s]*'
$pattern += '\b0 errors\b[\S\s]*'
$pattern += '\btest_package_with_streams_1 +True +1\.3\.2 +1\.3\.1\b[\S\s]*'
$pattern += "\btest_package_with_streams_2 +False +1\.4-beta1 +1\.4-beta1\b[\S\s]*"
$pattern += '\btest_package_with_streams_1\b[\S\s]*'
$pattern += '\bStream: 1\.2\b[\S\s]*'
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.2\.4\b[\S\s]*'
$pattern += '\bNew version is available\b[\S\s]*'
$pattern += '\bStream: 1\.3\b[\S\s]*'
$pattern += '\bnuspec version: 1\.3\.1\b[\S\s]*'
$pattern += '\bremote version: 1\.3\.2\b[\S\s]*'
$pattern += '\bNew version is available\b[\S\s]*'
$pattern += '\bStream: 1\.4\b[\S\s]*'
$pattern += '\bnuspec version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bremote version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$pattern += '\bPackage updated\b[\S\s]*'
$pattern += '\btest_package_with_streams_2\b[\S\s]*'
$pattern += '\bStream: 1\.2\b[\S\s]*'
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.2\.3\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$pattern += '\bStream: 1\.3\b[\S\s]*'
$pattern += '\bnuspec version: 1\.3\.1\b[\S\s]*'
$pattern += '\bremote version: 1\.3\.1\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$pattern += '\bStream: 1\.4\b[\S\s]*'
$pattern += '\bnuspec version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bremote version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$Options.Report.Path | Should Exist
$Options.Report.Path | Should FileContentMatchMultiline $pattern
}

It 'should execute markdown Report plugin' {
gc $global:au_Root\test_package_with_streams_1\update.ps1 | set content
$content -replace '@\{.+1\.3.+\}', "@{ Version = '1.3.2' }" | set content
$content -replace '@\{.+1\.2.+\}', "@{ Version = '1.2.4' }" | set content
$content | sc $global:au_Root\test_package_with_streams_1\update.ps1

$Options.Report = @{
Type = 'markdown'
Path = "$global:au_Root\report.md"
Params = @{ Github_UserRepo = 'majkinetor/chocolatey' }
}

$res = updateall -NoPlugins:$false -Options $Options 6> $null

$pattern = "\bFinished $pkg_no packages\b[\S\s]*"
$pattern += '\b1 updated\b[\S\s]*'
$pattern += '\b0 errors\b[\S\s]*'
$pattern += '\btest_package_with_streams_1\b.*\bTrue\b.*\bFalse\b.*\b1\.3\.2\b.*\b1\.3\.1\b[\S\s]*'
$pattern += "\btest_package_with_streams_2\b.*\bFalse\b.*\bFalse\b.*\b1\.4-beta1\b.*\b1\.4-beta1\b[\S\s]*"
$pattern += '\btest_package_with_streams_1\b[\S\s]*'
$pattern += '\bStream: 1\.2\b[\S\s]*'
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.2\.4\b[\S\s]*'
$pattern += '\bNew version is available\b[\S\s]*'
$pattern += '\bStream: 1\.3\b[\S\s]*'
$pattern += '\bnuspec version: 1\.3\.1\b[\S\s]*'
$pattern += '\bremote version: 1\.3\.2\b[\S\s]*'
$pattern += '\bNew version is available\b[\S\s]*'
$pattern += '\bStream: 1\.4\b[\S\s]*'
$pattern += '\bnuspec version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bremote version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$pattern += '\bPackage updated\b[\S\s]*'
$pattern += '\btest_package_with_streams_2\b[\S\s]*'
$pattern += '\bStream: 1\.2\b[\S\s]*'
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.2\.3\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$pattern += '\bStream: 1\.3\b[\S\s]*'
$pattern += '\bnuspec version: 1\.3\.1\b[\S\s]*'
$pattern += '\bremote version: 1\.3\.1\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$pattern += '\bStream: 1\.4\b[\S\s]*'
$pattern += '\bnuspec version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bremote version: 1\.4-beta1\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
$Options.Report.Path | Should Exist
$Options.Report.Path | Should FileContentMatchMultiline $pattern
}

It 'should execute GitReleases plugin when there are updates' {
gc $global:au_Root\test_package_with_streams_1\update.ps1 | set content
Expand Down
64 changes: 59 additions & 5 deletions tests/Update-AUPackages.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,45 @@ Describe 'Update-AUPackages' -Tag updateall {
(gc $TestDrive\tmp_test).Count | Should be 3
}

It 'should execute Report plugin' {
It 'should execute text Report plugin' {
gc $global:au_Root\test_package_1\update.ps1 | set content
$content -replace '@\{.+\}', "@{ Version = '1.3' }" | set content
$content | sc $global:au_Root\test_package_1\update.ps1

$Options.Report = @{
Type = 'text'
Path = "$global:au_Root\report.txt"
}

$res = updateall -NoPlugins:$false -Options $Options 6> $null

$pattern = "\bFinished $pkg_no packages\b[\S\s]*"
$pattern += '\b1 updated\b[\S\s]*'
$pattern += '\b0 errors\b[\S\s]*'
$pattern += '\btest_package_1 +True +1\.3 +1\.2\.3\b[\S\s]*'
foreach ( $i in 2..$pkg_no ) {
$pattern += "\btest_package_$i +False +1\.2\.3 +1\.2\.3\b[\S\s]*"
}
$pattern += '\btest_package_1\b[\S\s]*'
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.3\b[\S\s]*'
$pattern += '\bNew version is available\b[\S\s]*'
$pattern += '\bPackage updated\b[\S\s]*'
foreach ( $i in 2..$pkg_no ) {
$pattern += "\btest_package_$i\b[\S\s]*"
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.2\.3\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
}
$Options.Report.Path | Should Exist
$Options.Report.Path | Should FileContentMatchMultiline $pattern
}

It 'should execute markdown Report plugin' {
gc $global:au_Root\test_package_1\update.ps1 | set content
$content -replace '@\{.+\}', "@{ Version = '1.3' }" | set content
$content | sc $global:au_Root\test_package_1\update.ps1

$Options.Report = @{
Type = 'markdown'
Path = "$global:au_Root\report.md"
Expand All @@ -113,10 +151,26 @@ Describe 'Update-AUPackages' -Tag updateall {

$res = updateall -NoPlugins:$false -Options $Options 6> $null

Test-Path $Options.Report.Path | Should Be $true

$report = gc $Options.Report.Path
($report -match "test_package_[1-3]").Count | Should Be 9
$pattern = "\bFinished $pkg_no packages\b[\S\s]*"
$pattern += '\b1 updated\b[\S\s]*'
$pattern += '\b0 errors\b[\S\s]*'
$pattern += '\btest_package_1\b.*\bTrue\b.*\bFalse\b.*\b1\.3\b.*\b1\.2\.3\b[\S\s]*'
foreach ( $i in 2..$pkg_no ) {
$pattern += "\btest_package_$i\b.*\bFalse\b.*\bFalse\b.*\b1\.2\.3\b.*\b1\.2\.3\b[\S\s]*"
}
$pattern += '\btest_package_1\b[\S\s]*'
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.3\b[\S\s]*'
$pattern += '\bNew version is available\b[\S\s]*'
$pattern += '\bPackage updated\b[\S\s]*'
foreach ( $i in 2..$pkg_no ) {
$pattern += "\btest_package_$i\b[\S\s]*"
$pattern += '\bnuspec version: 1\.2\.3\b[\S\s]*'
$pattern += '\bremote version: 1\.2\.3\b[\S\s]*'
$pattern += '\bNo new version found\b[\S\s]*'
}
$Options.Report.Path | Should Exist
$Options.Report.Path | Should FileContentMatchMultiline $pattern
}

It 'should execute RunInfo plugin' {
Expand Down
23 changes: 15 additions & 8 deletions tests/Update-Package.Streams.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,14 @@ Describe 'Update-Package using streams' -Tag updatestreams {
$res = update

$res.Updated | Should Be $true
$res.Streams.'1.2'.RemoteVersion | Should Be 1.2.4
$res.Streams.'1.3'.RemoteVersion | Should Be 1.3.1
$res.Streams.'1.4'.RemoteVersion | Should Be 1.4-beta1
$res.NuspecVersion | Should Be 1.2.3
$res.RemoteVersion | Should Be 1.2.4
$res.Streams.'1.2'.NuspecVersion | Should Be 1.2.3
$res.Streams.'1.2'.RemoteVersion | Should Be 1.2.4
$res.Streams.'1.3'.NuspecVersion | Should Be 1.3.1
$res.Streams.'1.3'.RemoteVersion | Should Be 1.3.1
$res.Streams.'1.4'.NuspecVersion | Should Be 1.4-beta1
$res.Streams.'1.4'.RemoteVersion | Should Be 1.4-beta1
$res.Result[-1] | Should Be 'Package updated'
(nuspec_file).package.metadata.version | Should Be 1.2.4
(json_file).'1.2' | Should Be 1.2.4
Expand All @@ -175,21 +180,23 @@ Describe 'Update-Package using streams' -Tag updatestreams {
}

It 'updates package when multiple remote versions are higher' {
get_latest -Version 1.4.0
get_latest -Version 1.3.2

$res = update

$res.Updated | Should Be $true
$res.NuspecVersion | Should Be 1.3.1
$res.RemoteVersion | Should Be 1.3.2
$res.Streams.'1.2'.NuspecVersion | Should Be 1.2.3
$res.Streams.'1.2'.RemoteVersion | Should Be 1.2.4
$res.Streams.'1.3'.NuspecVersion | Should Be 1.3.1
$res.Streams.'1.3'.RemoteVersion | Should Be 1.3.1
$res.Streams.'1.3'.RemoteVersion | Should Be 1.3.2
$res.Streams.'1.4'.NuspecVersion | Should Be 1.4-beta1
$res.Streams.'1.4'.RemoteVersion | Should Be 1.4.0
$res.Streams.'1.4'.RemoteVersion | Should Be 1.4-beta1
$res.Result[-1] | Should Be 'Package updated'
(json_file).'1.2' | Should Be 1.2.4
(json_file).'1.3' | Should Be 1.3.1
(json_file).'1.4' | Should Be 1.4.0
(json_file).'1.3' | Should Be 1.3.2
(json_file).'1.4' | Should Be 1.4-beta1
}

It "does not update the package when remote version is not higher" {
Expand Down

0 comments on commit 46edb02

Please sign in to comment.