Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Find-PowerShellSupportStatus function. #8

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions PSCoreUpdate.Tests/Find-PowerShellSupportStatus.Tests.ps1
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
}
}
80 changes: 80 additions & 0 deletions PSCoreUpdate/Find-PowerShellSupportStatus.ps1
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
}
}
}
}

1 change: 1 addition & 0 deletions PSCoreUpdate/Messages.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ConvertFrom-StringData @'
Find_PowerShellRelease_001 = PowerShell releases was not found.
Find_PowerShellRelease_002 = "{0}" is not correct version tag name.
Find_PowerShellRelease_003 = "{0}" is not correct version range.\r\nVersion range must follow NuGet range syntax.\r\nSee : https://docs.microsoft.com/en-us/nuget/concepts/package-versioning#version-ranges
Find_PowerShellSupportStatus_001 = Preview version of PowerShell is provided for testing and feedback only. (Version = {0})
Get_PowerShellGitHubApiToken_001 = GitHub API token is not saved.
Get_PowerShellGitHubApiToken_002 = Saved GitHub API token is {0} .
Save_PowerShellAsset_001 = Invalid AssetType.
Expand Down
36 changes: 36 additions & 0 deletions PSCoreUpdate/PSCoreUpdate.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,42 @@
</TableControl>
</View>

<!-- PowerShellSupportStatus table view -->
<View>
<Name>Default</Name>
<ViewSelectedBy>
<TypeName>PowerShellSupportStatus</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>Version</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Is EOS</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>EOS Date</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<ScriptBlock>"{0}.{1}" -f $_.Version.Major, $_.Version.Minor</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.IsEOS()</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.EOSDate.ToString("d")</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

<!-- PowerShellCoreRelease table view -->
<View>
<Name>Default</Name>
Expand Down
2 changes: 1 addition & 1 deletion PSCoreUpdate/PSCoreUpdate.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
TypesToProcess = @('PSCoreUpdate.types.ps1xml')
FormatsToProcess = @('PSCoreUpdate.format.ps1xml')
RootModule = 'PSCoreUpdate.psm1'
FunctionsToExport = @('Find-PowerShellBuildStatus', 'Find-PowerShellRelease',
FunctionsToExport = @('Find-PowerShellBuildStatus', 'Find-PowerShellSupportStatus', 'Find-PowerShellRelease',
'Test-LatestVersion', 'Update-PowerShellRelease', 'Save-PowerShellAsset',
'Get-PowerShellGitHubApiToken', 'Remove-PowerShellGitHubApiToken', 'Set-PowerShellGitHubApiToken',
'Enable-PSCoreUpdateLegacyAlias')
Expand Down
1 change: 1 addition & 0 deletions PSCoreUpdate/PSCoreUpdate.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Import-LocalizedData -BindingVariable "Messages" -FileName "Messages"
. (Join-Path $PSScriptRoot 'Utils.ps1')
. (Join-Path $PSScriptRoot 'PowerShellGitHubApiToken.ps1')
. (Join-Path $PSScriptRoot 'Find-PowerShellBuildStatus.ps1')
. (Join-Path $PSScriptRoot 'Find-PowerShellSupportStatus.ps1')
. (Join-Path $PSScriptRoot 'Find-PowerShellRelease.ps1')
. (Join-Path $PSScriptRoot 'Save-PowerShellAsset.ps1')
. (Join-Path $PSScriptRoot 'Test-LatestVersion.ps1')
Expand Down
11 changes: 11 additions & 0 deletions PSCoreUpdate/Utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ enum ReleaseTypes {
LTS = 2
}

class PowerShellSupportStatus {

[semver]$Version;

[datetime]$EOSDate;

[bool] IsEOS() {
return (([datetime]::Now.Date + 1) -ge $this.EOSDate.Date)
}
}

class PowerShellCoreRelease {

[int]$ReleaseId;
Expand Down
1 change: 1 addition & 0 deletions PSCoreUpdate/ja-JP/Messages.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ConvertFrom-StringData @'
Find_PowerShellRelease_001 = PowerShell のリリース情報が見つかりません。
Find_PowerShellRelease_002 = "{0}" は正しいバージョンタグではありません。
Find_PowerShellRelease_003 = "{0}" は正しいバージョン範囲ではありません。\r\nバージョン範囲はNuGetの文法に従う必要があります。\r\n参考 : https://docs.microsoft.com/ja-jp/nuget/concepts/package-versioning#version-ranges
Find_PowerShellSupportStatus_001 = プレビュー版PowerShellはテストおよびフィードバック専用です。 (Version = {0})
Get_PowerShellGitHubApiToken_001 = GitHub API token は保存されていません。
Get_PowerShellGitHubApiToken_002 = 保存された GitHub API token は {0} です。
Save_PowerShellAsset_001 = 不正な AssetType 。
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,39 @@ Version Release ReleaseDate
7.4.3 LTS 2024/06/18 23:26:06
```

### Find-PowerShellSupportStatus

Find PowerShell support status.

* Official information : [PowerShell end-of-support dates](https://learn.microsoft.com/en-us/powershell/scripting/install/powershell-support-lifecycle?view=powershell-7.4#powershell-end-of-support-dates)

> [!NOTE]
> This function uses [endoflife.date raw data on GitHub](https://github.com/endoflife-date/release-data/blob/main/releases/powershell.json).

```powershell
# Find all versions
PS C:\> Find-PowerShellSupportStatus

Version Is EOS EOS Date
------- ------- --------
7.4 False 2026/11/10
7.3 True 2024/05/08
7.2 False 2024/11/08
7.1 True 2022/05/08
7.0 True 2022/12/03
6.2 True 2020/09/04
6.1 True 2019/09/28
6.0 True 2019/02/13

# Find supported version only
PS C:\> Find-PowerShellSupportStatus -ExcludeEOS

Version Is EOS EOS Date
------- ------ --------
7.4 False 2026/11/10
7.2 False 2024/11/08
```

### Save-PowerShellAsset

Download PowerShell release assets.
Expand Down