diff --git a/packages-generation/manifest-utils.Tests.ps1 b/packages-generation/manifest-utils.Tests.ps1 index 83d9ab0..2898d32 100644 --- a/packages-generation/manifest-utils.Tests.ps1 +++ b/packages-generation/manifest-utils.Tests.ps1 @@ -60,6 +60,17 @@ Describe "Get-VersionFromRelease" { $release = @{ name = "3.8.3: Release title" } Get-VersionFromRelease -Release $release | Should -Be "3.8.3" } + + It "take alpha, beta or rc version" { + $release = @{ name = "3.8.3-alpha.1"} + Get-VersionFromRelease -Release $release | Should -Be "3.8.3-alpha.1" + + $release = @{ name = "3.8.3-beta.2"} + Get-VersionFromRelease -Release $release | Should -Be "3.8.3-beta.2" + + $release = @{ name = "3.8.3-rc.1"} + Get-VersionFromRelease -Release $release | Should -Be "3.8.3-rc.1" + } } Describe "Build-VersionsManifest" { @@ -78,14 +89,28 @@ Describe "Build-VersionsManifest" { It "build manifest with correct version order" { $releases = @( - @{ name = "3.8.1"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-14T09:54:06Z"; assets = $assets }, + @{ name = "3.8.1-beta.2"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-14T09:54:06Z"; assets = $assets }, @{ name = "3.5.2: Hello"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-06T11:45:36Z"; assets = $assets }, - @{ name = "3.8.3: Release title"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-06T11:43:38Z"; assets = $assets } + @{ name = "3.8.3-alpha.1"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-06T11:43:38Z"; assets = $assets } + @{ name = "3.8.1-rc.1"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-06T11:43:38Z"; assets = $assets } + @{ name = "3.8.1-beta.1"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-06T11:43:38Z"; assets = $assets } + @{ name = "3.4.7"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-06T11:43:38Z"; assets = $assets } + @{ name = "3.8.1-alpha.3"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-06T11:43:38Z"; assets = $assets } + @{ name = "3.8.1-beta.12"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-06T11:43:38Z"; assets = $assets } + @{ name = "3.5.2-beta.2"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-06T11:43:38Z"; assets = $assets } + @{ name = "3.8.1"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-06T11:43:38Z"; assets = $assets } ) $expectedManifest = @( - [PSCustomObject]@{ version = "3.8.3"; stable = $true; release_url = "fake_html_url"; files = $expectedManifestFiles }, + [PSCustomObject]@{ version = "3.8.3-alpha.1"; stable = $false; release_url = "fake_html_url"; files = $expectedManifestFiles }, [PSCustomObject]@{ version = "3.8.1"; stable = $true; release_url = "fake_html_url"; files = $expectedManifestFiles }, + [PSCustomObject]@{ version = "3.8.1-rc.1"; stable = $false; release_url = "fake_html_url"; files = $expectedManifestFiles } + [PSCustomObject]@{ version = "3.8.1-beta.12"; stable = $false; release_url = "fake_html_url"; files = $expectedManifestFiles } + [PSCustomObject]@{ version = "3.8.1-beta.2"; stable = $false; release_url = "fake_html_url"; files = $expectedManifestFiles } + [PSCustomObject]@{ version = "3.8.1-beta.1"; stable = $false; release_url = "fake_html_url"; files = $expectedManifestFiles } + [PSCustomObject]@{ version = "3.8.1-alpha.3"; stable = $false; release_url = "fake_html_url"; files = $expectedManifestFiles } [PSCustomObject]@{ version = "3.5.2"; stable = $true; release_url = "fake_html_url"; files = $expectedManifestFiles } + [PSCustomObject]@{ version = "3.5.2-beta.2"; stable = $false; release_url = "fake_html_url"; files = $expectedManifestFiles } + [PSCustomObject]@{ version = "3.4.7"; stable = $true; release_url = "fake_html_url"; files = $expectedManifestFiles } ) $actualManifest = Build-VersionsManifest -Releases $releases -Configuration $configuration Assert-Equivalent -Actual $actualManifest -Expected $expectedManifest diff --git a/packages-generation/manifest-utils.psm1 b/packages-generation/manifest-utils.psm1 index 2d4ef00..08bc3e5 100644 --- a/packages-generation/manifest-utils.psm1 +++ b/packages-generation/manifest-utils.psm1 @@ -35,8 +35,8 @@ function Get-VersionFromRelease { ) # Release name can contain additional information after ':' so filter it [string]$releaseName = $Release.name.Split(':')[0] - [Version]$version = $null - if (![Version]::TryParse($releaseName, [ref]$version)) { + [Semver]$version = $null + if (![Semver]::TryParse($releaseName, [ref]$version)) { throw "Release '$($Release.id)' has invalid title '$($Release.name)'. It can't be parsed as version. ( $($Release.html_url) )" } @@ -57,21 +57,22 @@ function Build-VersionsManifest { continue } - [Version]$version = Get-VersionFromRelease $release + [Semver]$version = Get-VersionFromRelease $release $versionKey = $version.ToString() if ($versionsHash.ContainsKey($versionKey)) { continue } - + + $stable = $version.PreReleaseLabel ? $false : $true $versionsHash.Add($versionKey, [PSCustomObject]@{ version = $versionKey - stable = $true + stable = $stable release_url = $release.html_url files = $release.assets | ForEach-Object { New-AssetItem -ReleaseAsset $_ -Configuration $Configuration } }) } # Sort versions by descending - return $versionsHash.Values | Sort-Object -Property @{ Expression = { [Version]$_.version }; Descending = $true } + return $versionsHash.Values | Sort-Object -Property @{ Expression = { [Semver]$_.version }; Descending = $true } } \ No newline at end of file