Merge pull request #8 from actions/v-vlsafo/add-unstable-python-versions

Add support unstable tool versions
pull/10/head
Vladimir Safonkin 5 years ago committed by GitHub
commit c3d08f5736
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -60,6 +60,17 @@ Describe "Get-VersionFromRelease" {
$release = @{ name = "3.8.3: Release title" } $release = @{ name = "3.8.3: Release title" }
Get-VersionFromRelease -Release $release | Should -Be "3.8.3" 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" { Describe "Build-VersionsManifest" {
@ -78,14 +89,28 @@ Describe "Build-VersionsManifest" {
It "build manifest with correct version order" { It "build manifest with correct version order" {
$releases = @( $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.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 = @( $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"; 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"; 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 $actualManifest = Build-VersionsManifest -Releases $releases -Configuration $configuration
Assert-Equivalent -Actual $actualManifest -Expected $expectedManifest Assert-Equivalent -Actual $actualManifest -Expected $expectedManifest

@ -35,8 +35,8 @@ function Get-VersionFromRelease {
) )
# Release name can contain additional information after ':' so filter it # Release name can contain additional information after ':' so filter it
[string]$releaseName = $Release.name.Split(':')[0] [string]$releaseName = $Release.name.Split(':')[0]
[Version]$version = $null [Semver]$version = $null
if (![Version]::TryParse($releaseName, [ref]$version)) { 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) )" 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 continue
} }
[Version]$version = Get-VersionFromRelease $release [Semver]$version = Get-VersionFromRelease $release
$versionKey = $version.ToString() $versionKey = $version.ToString()
if ($versionsHash.ContainsKey($versionKey)) { if ($versionsHash.ContainsKey($versionKey)) {
continue continue
} }
$stable = $version.PreReleaseLabel ? $false : $true
$versionsHash.Add($versionKey, [PSCustomObject]@{ $versionsHash.Add($versionKey, [PSCustomObject]@{
version = $versionKey version = $versionKey
stable = $true stable = $stable
release_url = $release.html_url release_url = $release.html_url
files = $release.assets | ForEach-Object { New-AssetItem -ReleaseAsset $_ -Configuration $Configuration } files = $release.assets | ForEach-Object { New-AssetItem -ReleaseAsset $_ -Configuration $Configuration }
}) })
} }
# Sort versions by descending # 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 }
} }
Loading…
Cancel
Save