diff --git a/PSCoreUpdate.Tests/Find-PowerShellBuildStatus.Test.ps1 b/PSCoreUpdate.Tests/Find-PowerShellBuildStatus.Tests.ps1 similarity index 100% rename from PSCoreUpdate.Tests/Find-PowerShellBuildStatus.Test.ps1 rename to PSCoreUpdate.Tests/Find-PowerShellBuildStatus.Tests.ps1 diff --git a/PSCoreUpdate.Tests/Find-PowerShellSupportStatus.Tests.ps1 b/PSCoreUpdate.Tests/Find-PowerShellSupportStatus.Tests.ps1 new file mode 100644 index 0000000..6e76504 --- /dev/null +++ b/PSCoreUpdate.Tests/Find-PowerShellSupportStatus.Tests.ps1 @@ -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 ()" -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 + } +} \ No newline at end of file diff --git a/PSCoreUpdate/Find-PowerShellSupportStatus.ps1 b/PSCoreUpdate/Find-PowerShellSupportStatus.ps1 new file mode 100644 index 0000000..1758513 --- /dev/null +++ b/PSCoreUpdate/Find-PowerShellSupportStatus.ps1 @@ -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 + } + } + } +} + diff --git a/PSCoreUpdate/Messages.psd1 b/PSCoreUpdate/Messages.psd1 index 77b4e29..0bdc59f 100644 --- a/PSCoreUpdate/Messages.psd1 +++ b/PSCoreUpdate/Messages.psd1 @@ -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. diff --git a/PSCoreUpdate/PSCoreUpdate.format.ps1xml b/PSCoreUpdate/PSCoreUpdate.format.ps1xml index b78a4c6..18cb8c8 100644 --- a/PSCoreUpdate/PSCoreUpdate.format.ps1xml +++ b/PSCoreUpdate/PSCoreUpdate.format.ps1xml @@ -37,6 +37,42 @@ + + + Default + + PowerShellSupportStatus + + + + + + + + + + + + + + + + + + "{0}.{1}" -f $_.Version.Major, $_.Version.Minor + + + $_.IsEOS() + + + $_.EOSDate.ToString("d") + + + + + + + Default diff --git a/PSCoreUpdate/PSCoreUpdate.psd1 b/PSCoreUpdate/PSCoreUpdate.psd1 index 02172c3..1a6d29a 100644 --- a/PSCoreUpdate/PSCoreUpdate.psd1 +++ b/PSCoreUpdate/PSCoreUpdate.psd1 @@ -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') diff --git a/PSCoreUpdate/PSCoreUpdate.psm1 b/PSCoreUpdate/PSCoreUpdate.psm1 index 65e27b6..2471656 100644 --- a/PSCoreUpdate/PSCoreUpdate.psm1 +++ b/PSCoreUpdate/PSCoreUpdate.psm1 @@ -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') diff --git a/PSCoreUpdate/Utils.ps1 b/PSCoreUpdate/Utils.ps1 index 803c200..e842d6e 100644 --- a/PSCoreUpdate/Utils.ps1 +++ b/PSCoreUpdate/Utils.ps1 @@ -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; diff --git a/PSCoreUpdate/ja-JP/Messages.psd1 b/PSCoreUpdate/ja-JP/Messages.psd1 index 8dbc638..5c3e70e 100644 --- a/PSCoreUpdate/ja-JP/Messages.psd1 +++ b/PSCoreUpdate/ja-JP/Messages.psd1 @@ -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 。 diff --git a/README.md b/README.md index 0b928c0..a14f03b 100644 --- a/README.md +++ b/README.md @@ -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.