-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from stknohg/feat-find-eol
Add Find-PowerShellSupportStatus function.
- Loading branch information
Showing
10 changed files
with
207 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
$RootPath = Join-Path (Split-Path $PSScriptRoot -Parent) 'PSCoreUpdate' | ||
Import-Module (Join-Path $RootPath 'PSCoreUpdate.psd1') -Force | ||
|
||
Describe "Find-PowerShellSupportStatus unit tests" { | ||
BeforeAll { | ||
# Get endoflife.date rawdata | ||
$EOSRawData = Invoke-RestMethod -Uri https://raw.githubusercontent.com/endoflife-date/release-data/main/releases/powershell.json | ||
} | ||
|
||
It "Returns proper data count" { | ||
$actual = Find-PowerShellSupportStatus | ||
$actual.Count | Should -Be @($EOSRawData.releases.PSObject.Properties).Length | ||
} | ||
|
||
It "Returns proper EOS date" { | ||
$actual = Find-PowerShellSupportStatus | ||
$actual.Where({ $_.Version -eq '6.0' }).EOSDate | Should -Be ([datetime]::new(2019, 2, 13)) | ||
$actual.Where({ $_.Version -eq '6.1' }).EOSDate | Should -Be ([datetime]::new(2019, 9, 28)) | ||
$actual.Where({ $_.Version -eq '6.2' }).EOSDate | Should -Be ([datetime]::new(2020, 9, 4)) | ||
$actual.Where({ $_.Version -eq '7.0' }).EOSDate | Should -Be ([datetime]::new(2022, 12, 3)) | ||
$actual.Where({ $_.Version -eq '7.1' }).EOSDate | Should -Be ([datetime]::new(2022, 5, 8)) | ||
$actual.Where({ $_.Version -eq '7.2' }).EOSDate | Should -Be ([datetime]::new(2024, 11, 8)) | ||
$actual.Where({ $_.Version -eq '7.3' }).EOSDate | Should -Be ([datetime]::new(2024, 05, 08)) | ||
$actual.Where({ $_.Version -eq '7.4' }).EOSDate | Should -Be ([datetime]::new(2026, 11, 10)) | ||
} | ||
|
||
$testCases = @( | ||
@{Pattern = 'PowerShell 6.0'; PSVersion = '6.0'; EOSDate = [datetime]::new(2019, 2, 13) }, | ||
@{Pattern = 'PowerShell 7.0'; PSVersion = '7.0'; EOSDate = [datetime]::new(2022, 12, 3) }, | ||
@{Pattern = 'PowerShell 7.4'; PSVersion = '7.4'; EOSDate = [datetime]::new(2026, 11, 10) } | ||
) | ||
It "Returns specific version EOS date (<Pattern>)" -TestCases $testCases { | ||
$actual = Find-PowerShellSupportStatus -Version $PSVersion | ||
# Check count | ||
$actual.Count | Should -Be 1 | ||
# Check EOS date | ||
$actual.EOSDate | Should -Be $EOSDate | ||
} | ||
|
||
It "Raise error when specified preview version" { | ||
{ Find-PowerShellSupportStatus -Version 7.5.0-preview.3 -ErrorAction Stop } | Should -Throw | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<# | ||
.SYNOPSIS | ||
Find PowerShell support status. | ||
#> | ||
function Find-PowerShellSupportStatus { | ||
[CmdletBinding(DefaultParameterSetName = 'Default')] | ||
param ( | ||
[Parameter(ParameterSetName = 'Default', Mandatory = $false)] | ||
[SemVer]$Version, | ||
[Parameter(ParameterSetName = 'ExcludeEOS', Mandatory = $true)] | ||
[Switch]$ExcludeEOS | ||
) | ||
begin { | ||
# validate parameters | ||
$_AbortProcess = $false | ||
switch ($PSCmdlet.ParameterSetName) { | ||
'Default' { | ||
if ( $Version -and ($Version.PreReleaseLabel -or $Version.BuildLabel)) { | ||
Write-Error ($Messages.Find_PowerShellSupportStatus_001 -f $Version) | ||
$_AbortProcess = $true | ||
return | ||
} | ||
} | ||
|
||
} | ||
} | ||
process { | ||
if ($_AbortProcess) { | ||
$objectsForOutput = @() | ||
return | ||
} | ||
|
||
# Get PowerShell EOS information | ||
try { | ||
# Use endoflife.date raw data to get PowerShell EOS. | ||
Write-Verbose 'Request to https://raw.githubusercontent.com/endoflife-date/release-data/main/releases/powershell.json' | ||
$eols = Invoke-RestMethod -Uri https://raw.githubusercontent.com/endoflife-date/release-data/main/releases/powershell.json | ||
} catch { | ||
Write-Error 'Failed to get PowerShell EOS information.' | ||
return $null | ||
} | ||
|
||
# Create PowerShellEOS objects | ||
$objectsForOutput = [System.Collections.ArrayList]::new() | ||
foreach ($r in $eols.releases.PSObject.Properties.Name) { | ||
$obj = [PowerShellSupportStatus]::new() | ||
$obj.Version = [semver]$r | ||
$obj.EOSDate = [datetime]::Parse($eols.releases.$r.eol) | ||
# filter objcets | ||
if ($PSCmdlet.ParameterSetName -eq 'Default') { | ||
if ($Version -and | ||
-not ($Version.Major -eq $obj.Version.Major -and $Version.Minor -eq $obj.Version.Minor)) { | ||
Write-Verbose "-Version filter excludes version $($obj.Version)" | ||
continue | ||
} | ||
} | ||
if ($PSCmdlet.ParameterSetName -eq 'ExcludeEOS') { | ||
if ($obj.IsEOS() -eq $ExcludeEOS) { | ||
Write-Verbose "-ExcludeEOS filter excludes version $($obj.Version)" | ||
continue | ||
} | ||
} | ||
[void]$objectsForOutput.Add($obj) | ||
} | ||
} | ||
end { | ||
switch ($objectsForOutput.Count) { | ||
0 { | ||
# do nothing | ||
} | ||
1 { | ||
$objectsForOutput[0] | ||
} | ||
Default { | ||
$objectsForOutput | Sort-Object -Property Version -Descending | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters