From 355d79f16e8751a5b70506a768d0d9cd7cce251c Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Wed, 8 Jul 2020 17:41:31 +0300 Subject: [PATCH 1/4] Add unstable version support --- packages-generation/manifest-generator.ps1 | 1 + packages-generation/manifest-utils.psm1 | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages-generation/manifest-generator.ps1 b/packages-generation/manifest-generator.ps1 index a1d8397..883348a 100644 --- a/packages-generation/manifest-generator.ps1 +++ b/packages-generation/manifest-generator.ps1 @@ -31,5 +31,6 @@ $configuration = Read-ConfigurationFile -Filepath $ConfigurationFile $gitHubApi = Get-GitHubApi -AccountName $GitHubRepositoryOwner -ProjectName $GitHubRepositoryName -AccessToken $GitHubAccessToken $releases = $gitHubApi.GetReleases() + $versionIndex = Build-VersionsManifest -Releases $releases -Configuration $configuration $versionIndex | ConvertTo-Json -Depth 5 | Out-File $OutputFile -Encoding UTF8NoBOM -Force 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 From 49e88e0a9d0eb99ec7aecdd2824e10f1bbd00afb Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Wed, 8 Jul 2020 18:08:21 +0300 Subject: [PATCH 2/4] Add unit tests --- packages-generation/manifest-utils.Tests.ps1 | 31 ++++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/packages-generation/manifest-utils.Tests.ps1 b/packages-generation/manifest-utils.Tests.ps1 index 83d9ab0..0305edc 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-alpha.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 From becb7933150decdcd902f658f0f285089b59fdae Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Thu, 9 Jul 2020 09:19:54 +0300 Subject: [PATCH 3/4] Minor fix --- packages-generation/manifest-utils.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages-generation/manifest-utils.Tests.ps1 b/packages-generation/manifest-utils.Tests.ps1 index 0305edc..2898d32 100644 --- a/packages-generation/manifest-utils.Tests.ps1 +++ b/packages-generation/manifest-utils.Tests.ps1 @@ -66,7 +66,7 @@ Describe "Get-VersionFromRelease" { 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-alpha.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" From 77bdb3bde8481a63ae2b9b2a31e08f66a429c2b5 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Thu, 9 Jul 2020 09:34:52 +0300 Subject: [PATCH 4/4] Minor fix --- packages-generation/manifest-generator.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/packages-generation/manifest-generator.ps1 b/packages-generation/manifest-generator.ps1 index 883348a..a1d8397 100644 --- a/packages-generation/manifest-generator.ps1 +++ b/packages-generation/manifest-generator.ps1 @@ -31,6 +31,5 @@ $configuration = Read-ConfigurationFile -Filepath $ConfigurationFile $gitHubApi = Get-GitHubApi -AccountName $GitHubRepositoryOwner -ProjectName $GitHubRepositoryName -AccessToken $GitHubAccessToken $releases = $gitHubApi.GetReleases() - $versionIndex = Build-VersionsManifest -Releases $releases -Configuration $configuration $versionIndex | ConvertTo-Json -Depth 5 | Out-File $OutputFile -Encoding UTF8NoBOM -Force