Skip to content

Commit

Permalink
Fix versions in order not to change their types in $Latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Démoulins committed Oct 31, 2017
1 parent d786ac9 commit c27ad35
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
18 changes: 8 additions & 10 deletions AU/Public/Update-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function Update-Package {
mkdir -Force $pkg_path | Out-Null

$Env:ChocolateyPackageName = "chocolatey\$($package.Name)"
$Env:ChocolateyPackageVersion = $global:Latest.Version
$Env:ChocolateyPackageVersion = $global:Latest.Version.ToString()
$Env:ChocolateyAllowEmptyChecksums = 'true'
foreach ($a in $arch) {
$Env:chocolateyForceX86 = if ($a -eq '32') { 'true' } else { '' }
Expand Down Expand Up @@ -207,16 +207,13 @@ function Update-Package {
if (!(is_version $Latest.Version)) { throw "Invalid version: $($Latest.Version)" }
$package.RemoteVersion = $Latest.Version

$Latest.NuspecVersion = [AUVersion] $Latest.NuspecVersion
$Latest.Version = [AUVersion] $Latest.Version

if (!$NoCheckUrl) { check_urls }

"nuspec version: " + $package.NuspecVersion | result
"remote version: " + $package.RemoteVersion | result

$script:is_forced = $false
if ($Latest.Version -gt $Latest.NuspecVersion) {
if ([AUVersion] $Latest.Version -gt [AUVersion] $Latest.NuspecVersion) {
if (!($NoCheckChocoVersion -or $Force)) {
$choco_url = "https://chocolatey.org/packages/{0}/{1}" -f $global:Latest.PackageName, $package.RemoteVersion
try {
Expand Down Expand Up @@ -266,25 +263,26 @@ function Update-Package {
"Overriding version to: $global:au_Version" | result
$package.RemoteVersion = $global:au_Version
if (!(is_version $global:au_Version)) { throw "Invalid version: $global:au_Version" }
$global:Latest.Version = [AUVersion] $package.RemoteVersion
$global:Latest.Version = $package.RemoteVersion
$global:au_Version = $null
return
}

$date_format = 'yyyyMMdd'
$d = (get-date).ToString($date_format)
$v = $Latest.NuspecVersion.Version
$nuspecVersion = [AUVersion] $Latest.NuspecVersion
$v = $nuspecVersion.Version
$rev = $v.Revision.ToString()
try { $revdate = [DateTime]::ParseExact($rev, $date_format,[System.Globalization.CultureInfo]::InvariantCulture, [System.Globalization.DateTimeStyles]::None) } catch {}
if (($rev -ne -1) -and !$revdate) { return }

$build = if ($v.Build -eq -1) {0} else {$v.Build}
$v = [version] ('{0}.{1}.{2}.{3}' -f $v.Major, $v.Minor, $build, $d)
$package.RemoteVersion = [AUVersion]::new($v, $Latest.NuspecVersion.Prerelease, $Latest.NuspecVersion.BuildMetadata)
$Latest.Version = $package.RemoteVersion
$package.RemoteVersion = [AUVersion]::new($v, $nuspecVersion.Prerelease, $nuspecVersion.BuildMetadata).ToString()
$Latest.Version = $package.RemoteVersion -as $Latest.Version.GetType()
}

function set_latest( [HashTable]$latest, [string] $version, $stream ) {
function set_latest( [HashTable] $latest, [string] $version, $stream ) {
if (!$latest.NuspecVersion) { $latest.NuspecVersion = $version }
if ($stream -and !$latest.Stream) { $latest.Stream = $stream }
$package.NuspecVersion = $latest.NuspecVersion
Expand Down
19 changes: 19 additions & 0 deletions tests/Update-Package.Streams.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,25 @@ Describe 'Update-Package using streams' -Tag updatestreams {
update -Include 1.2
$global:Latest.test | Should BeNullOrEmpty
}

It 'does not change type of $Latest.Version when calling au_BeforeUpdate and au_AfterUpdate' {
$return_value = @{
'1.4' = @{ Version = ConvertTo-AUVersion '1.4-beta1' }
'1.2' = @{ Version = '1.2.4' }
'1.3' = @{ Version = [version] '1.3.1' }
}
function global:au_GetLatest { @{ Streams = $return_value } }
function checkLatest {
$return_latest = $return_value[$global:Latest.Stream]
$return_latest.Keys | % {
$global:Latest[$_] | Should BeOfType $return_latest[$_].GetType()
$global:Latest[$_] | Should BeExactly $return_latest[$_]
}
}
function au_BeforeUpdate { checkLatest }
function au_BeforeUpdate { checkLatest }
update
}
}
}

Expand Down

0 comments on commit c27ad35

Please sign in to comment.