From 41a1acf1a4a54f294bc6b8c9d031936bf4ad0846 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 15 Jun 2021 19:24:00 +0000 Subject: [PATCH 1/4] first attempt to support lts --- node-manifest-config.json | 8 ++++ packages-generation/manifest-utils.psm1 | 50 +++++++++++++++++++++---- 2 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 node-manifest-config.json diff --git a/node-manifest-config.json b/node-manifest-config.json new file mode 100644 index 0000000..5562000 --- /dev/null +++ b/node-manifest-config.json @@ -0,0 +1,8 @@ +{ + "regex": "node-\\d+\\.\\d+\\.\\d+-(\\w+)-(x\\d+)", + "groups": { + "arch": 2, + "platform": 1 + }, + "lts_rule_expression": "(Invoke-RestMethod 'https://raw.githubusercontent.com/nodejs/Release/main/schedule.json').PSObject.Properties | Where-Object { $_.Value.codename } | ForEach-Object { @{ Name = $_.Name.TrimStart('v'); Value = $_.Value.codename } }" +} \ No newline at end of file diff --git a/packages-generation/manifest-utils.psm1 b/packages-generation/manifest-utils.psm1 index df2a8b2..71e7f85 100644 --- a/packages-generation/manifest-utils.psm1 +++ b/packages-generation/manifest-utils.psm1 @@ -50,6 +50,7 @@ function Build-VersionsManifest { ) $Releases = $Releases | Sort-Object -Property "published_at" -Descending + $ltsRules = Get-LtsRules -Configuration $Configuration $versionsHash = @{} foreach ($release in $Releases) { @@ -64,17 +65,52 @@ function Build-VersionsManifest { continue } + $ltsStatus = Get-VersionLtsStatus -Version $versionKey -LtsRules $ltsRules $stable = $version.PreReleaseLabel ? $false : $true [array]$releaseAssets = $release.assets | ForEach-Object { New-AssetItem -ReleaseAsset $_ -Configuration $Configuration } - $versionsHash.Add($versionKey, [PSCustomObject]@{ - version = $versionKey - stable = $stable - release_url = $release.html_url - files = $releaseAssets - }) + $versionHash = [PSCustomObject]@{} + $versionHash | Add-Member -Name "version" -Value $versionKey -MemberType NoteProperty + $versionHash | Add-Member -Name "stable" -Value $stable -MemberType NoteProperty + if ($ltsStatus) { $versionHash | Add-Member -Name "lts" -Value $ltsStatus -MemberType NoteProperty } + $versionHash | Add-Member -Name "release_url" -Value $release.html_url -MemberType NoteProperty + $versionHash | Add-Member -Name "files" -Value $releaseAssets -MemberType NoteProperty + $versionsHash.Add($versionKey, $versionHash) } # Sort versions by descending return $versionsHash.Values | Sort-Object -Property @{ Expression = { [Semver]$_.version }; Descending = $true } -} \ No newline at end of file +} + +function Get-LtsRules { + param ( + [Parameter(Mandatory)][object]$Configuration + ) + + $ruleExpression = $Configuration."lts_rule_expression" + if ($ruleExpression) { + Invoke-Expression $ruleExpression + } else { + @() + } +} + +function Get-VersionLtsStatus { + param ( + [Parameter(Mandatory)][string]$Version, + [array]$LtsRules + ) + + foreach ($ltsRule in $LtsRules) { + if (($Version -eq $ltsRule.Name) -or ($Version.StartsWith("$($ltsRule.Name)."))) { + return $ltsRule.Value + } + } + + return $null + +} + +# Invoke-RestMethod "https://raw.githubusercontent.com/nodejs/Release/main/schedule.json" +# $arr.PSObject.Properties | Where-Object { $_.Value.codename } | ForEach-Object { @( @{ $_.Name = $_.Value.codename }) } +# (Invoke-RestMethod 'https://raw.githubusercontent.com/nodejs/Release/main/schedule.json').PSObject.Properties | Where-Object { $_.Value.codename } | ForEach-Object { @{ Name = $_.Name.TrimStart('v'); Value = $_.Value.codename } } \ No newline at end of file From 878c283d3b631405976a7b2d66d97951b5016cc9 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 16 Jun 2021 05:46:31 +0000 Subject: [PATCH 2/4] implement pester tests --- node-manifest-config.json | 8 --- packages-generation/manifest-utils.Tests.ps1 | 52 +++++++++++++++++++- 2 files changed, 51 insertions(+), 9 deletions(-) delete mode 100644 node-manifest-config.json diff --git a/node-manifest-config.json b/node-manifest-config.json deleted file mode 100644 index 5562000..0000000 --- a/node-manifest-config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "regex": "node-\\d+\\.\\d+\\.\\d+-(\\w+)-(x\\d+)", - "groups": { - "arch": 2, - "platform": 1 - }, - "lts_rule_expression": "(Invoke-RestMethod 'https://raw.githubusercontent.com/nodejs/Release/main/schedule.json').PSObject.Properties | Where-Object { $_.Value.codename } | ForEach-Object { @{ Name = $_.Name.TrimStart('v'); Value = $_.Value.codename } }" -} \ No newline at end of file diff --git a/packages-generation/manifest-utils.Tests.ps1 b/packages-generation/manifest-utils.Tests.ps1 index 0fcaf05..15765d1 100644 --- a/packages-generation/manifest-utils.Tests.ps1 +++ b/packages-generation/manifest-utils.Tests.ps1 @@ -126,7 +126,7 @@ Describe "Build-VersionsManifest" { [PSCustomObject]@{ version = "3.8.3"; stable = $true; release_url = "fake_html_url"; files = $expectedManifestFiles } ) [array]$actualManifest = Build-VersionsManifest -Releases $releases -Configuration $configuration - Assert-Equivalent -Actual $actualManifest -Expected $expectedManifest + Assert-Equivalent -Actual $actualManifest -Expected $expectedManifest } It "take latest published release for each version" { @@ -161,4 +161,54 @@ Describe "Build-VersionsManifest" { [array]$actualManifest = Build-VersionsManifest -Releases $releases -Configuration $configuration Assert-Equivalent -Actual $actualManifest -Expected $expectedManifest } + + It "set correct lts value for versions" { + $releases = @( + @{ name = "14.2.1"; draft = false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-14T09:54:06Z"; assets = $assets }, + @{ name = "12.0.1"; draft = $false; prerelease = false; html_url = "fake_html_url"; published_at = "2020-05-06T11:45:36Z"; assets = $assets }, + @{ name = "16.2.2"; draft = $false; prerelease = $false; html_url = "fake_html_url"; published_at = "2020-05-06T11:43:38Z"; assets = $assets } + ) + $configuration = @{ + regex = "python-\d+\.\d+\.\d+-(\w+)-([\w\.]+)?-?(x\d+)"; + groups = [PSCustomObject]@{ platform = 1; platform_version = 2; arch = "x64"; } + lts_rule_expression = "@(@{ Name = '14'; Value = 'Fermium' }, @{ Name = '12'; Value = 'Erbium' })" + } + $expectedManifest = @( + [PSCustomObject]@{ version = "16.2.2"; stable = $true; release_url = "fake_html_url"; files = $expectedManifestFiles }, + [PSCustomObject]@{ version = "14.2.1"; stable = $true; lts = "Fermium"; release_url = "fake_html_url"; files = $expectedManifestFiles }, + [PSCustomObject]@{ version = "12.0.1"; stable = $true; lts = "Erbium"; release_url = "fake_html_url"; files = $expectedManifestFiles } + ) + [array]$actualManifest = Build-VersionsManifest -Releases $releases -Configuration $configuration + Assert-Equivalent -Actual $actualManifest -Expected $expectedManifest + } +} + +Describe "Get-VersionLtsStatus" { + $ltsRules = @( + @{ Name = "14"; Value = "Fermium" }, + @{ Name = "12"; Value = "Erbium" }, + @{ Name = "10"; Value = $true }, + @{ Name = "8.3"; Value = "LTS 8.3" } + ) + + It "lts label is matched" { + Get-VersionLtsStatus -Version "14.2.2" -LtsRules $ltsRules | Should -Be "Fermium" + Get-VersionLtsStatus -Version "12.3.1" -LtsRules $ltsRules | Should -Be "Erbium" + Get-VersionLtsStatus -Version "10.8.1" -LtsRules $ltsRules | Should -Be $true + Get-VersionLtsStatus -Version "8.3.2" -LtsRules $ltsRules | Should -Be "LTS 8.3" + Get-VersionLtsStatus -Version "14" -LtsRules $ltsRules | Should -Be "Fermium" + } + + It "lts label is not matched" { + Get-VersionLtsStatus -Version "9.1" -LtsRules $ltsRules | Should -Be $null + Get-VersionLtsStatus -Version "13.8" -LtsRules $ltsRules | Should -Be $null + Get-VersionLtsStatus -Version "5" -LtsRules $ltsRules | Should -Be $null + Get-VersionLtsStatus -Version "8.4" -LtsRules $ltsRules | Should -Be $null + Get-VersionLtsStatus -Version "142.5.1" -LtsRules $ltsRules | Should -Be $null + } + + It "no rules" { + Get-VersionLtsStatus -Version "14.2.2" | Should -Be $null + Get-VersionLtsStatus -Version "12.3.1" -LtsRules $null | Should -Be $null + } } \ No newline at end of file From 00039881baf4907b7c4df5c50ce0aa670d24fe0f Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 16 Jun 2021 05:48:00 +0000 Subject: [PATCH 3/4] remove comments --- packages-generation/manifest-utils.psm1 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages-generation/manifest-utils.psm1 b/packages-generation/manifest-utils.psm1 index 71e7f85..ea7ecba 100644 --- a/packages-generation/manifest-utils.psm1 +++ b/packages-generation/manifest-utils.psm1 @@ -110,7 +110,3 @@ function Get-VersionLtsStatus { return $null } - -# Invoke-RestMethod "https://raw.githubusercontent.com/nodejs/Release/main/schedule.json" -# $arr.PSObject.Properties | Where-Object { $_.Value.codename } | ForEach-Object { @( @{ $_.Name = $_.Value.codename }) } -# (Invoke-RestMethod 'https://raw.githubusercontent.com/nodejs/Release/main/schedule.json').PSObject.Properties | Where-Object { $_.Value.codename } | ForEach-Object { @{ Name = $_.Name.TrimStart('v'); Value = $_.Value.codename } } \ No newline at end of file From f19d5f4b3c51d47e2a8e3a64d2400cde14aee3a8 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 16 Jun 2021 09:17:33 +0000 Subject: [PATCH 4/4] fix comments --- packages-generation/manifest-utils.psm1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages-generation/manifest-utils.psm1 b/packages-generation/manifest-utils.psm1 index ea7ecba..b0da90b 100644 --- a/packages-generation/manifest-utils.psm1 +++ b/packages-generation/manifest-utils.psm1 @@ -72,7 +72,9 @@ function Build-VersionsManifest { $versionHash = [PSCustomObject]@{} $versionHash | Add-Member -Name "version" -Value $versionKey -MemberType NoteProperty $versionHash | Add-Member -Name "stable" -Value $stable -MemberType NoteProperty - if ($ltsStatus) { $versionHash | Add-Member -Name "lts" -Value $ltsStatus -MemberType NoteProperty } + if ($ltsStatus) { + $versionHash | Add-Member -Name "lts" -Value $ltsStatus -MemberType NoteProperty + } $versionHash | Add-Member -Name "release_url" -Value $release.html_url -MemberType NoteProperty $versionHash | Add-Member -Name "files" -Value $releaseAssets -MemberType NoteProperty $versionsHash.Add($versionKey, $versionHash) @@ -108,5 +110,4 @@ function Get-VersionLtsStatus { } return $null - }