From 3b94f59edfb6762a8201b1511ad9b80263e84934 Mon Sep 17 00:00:00 2001 From: Thom Neale Date: Thu, 19 Dec 2024 14:29:11 -0500 Subject: [PATCH 1/7] Deleted reference to removed VersionCheckFile --- PowerShell/ScubaGear/CheckVersion.ps1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/PowerShell/ScubaGear/CheckVersion.ps1 b/PowerShell/ScubaGear/CheckVersion.ps1 index bf215d8e2e..602d5179f3 100644 --- a/PowerShell/ScubaGear/CheckVersion.ps1 +++ b/PowerShell/ScubaGear/CheckVersion.ps1 @@ -19,9 +19,6 @@ function Invoke-CheckScubaGearVersionPSGallery { Write-Warning "A new version of ScubaGear ($LatestVersion) is available on PowerShell Gallery. This notification can be disabled by setting `$env:SCUBAGEAR_SKIP_VERSION_CHECK = `$true before running ScubaGear." } - - # Store the current time in the file to mark the last check time - (Get-Date -ErrorAction 'Stop').ToString() | Set-Content $VersionCheckFile -ErrorAction 'Stop' } From 2917a1cba3e94ef3be61db1115887617d74b0b34 Mon Sep 17 00:00:00 2001 From: Thom Neale Date: Mon, 23 Dec 2024 12:32:09 -0500 Subject: [PATCH 2/7] Update PowerShell/ScubaGear/CheckVersion.ps1 Improved verbiage Co-authored-by: Addam Schroll <108814318+schrolla@users.noreply.github.com> --- PowerShell/ScubaGear/CheckVersion.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/ScubaGear/CheckVersion.ps1 b/PowerShell/ScubaGear/CheckVersion.ps1 index 602d5179f3..3b32220c4f 100644 --- a/PowerShell/ScubaGear/CheckVersion.ps1 +++ b/PowerShell/ScubaGear/CheckVersion.ps1 @@ -16,7 +16,7 @@ function Invoke-CheckScubaGearVersionPSGallery { $LatestVersion = [System.Version]$ModuleInfo.Version if ($CurrentVersion -lt $LatestVersion) { - Write-Warning "A new version of ScubaGear ($LatestVersion) is available on PowerShell Gallery. This notification can be disabled by setting `$env:SCUBAGEAR_SKIP_VERSION_CHECK = `$true before running ScubaGear." + Write-Warning "A newer version of ScubaGear ($LatestVersion) is available on PowerShell Gallery. This notification can be disabled by setting `$env:SCUBAGEAR_SKIP_VERSION_CHECK = `$true before running ScubaGear." } } From cb8db6b1f77b4c5ec8679472d0d051f0cd7a9993 Mon Sep 17 00:00:00 2001 From: Thom Neale Date: Fri, 27 Dec 2024 12:50:49 -0500 Subject: [PATCH 3/7] Use system.version to compare versions from github --- PowerShell/ScubaGear/CheckVersion.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PowerShell/ScubaGear/CheckVersion.ps1 b/PowerShell/ScubaGear/CheckVersion.ps1 index 3b32220c4f..fae75c08de 100644 --- a/PowerShell/ScubaGear/CheckVersion.ps1 +++ b/PowerShell/ScubaGear/CheckVersion.ps1 @@ -24,9 +24,9 @@ function Invoke-CheckScubaGearVersionPSGallery { function Invoke-CheckScubaGearVersionGithub { $ScubaManifest = Import-PowerShellDataFile (Join-Path -Path $PSScriptRoot -ChildPath 'ScubaGear.psd1' -Resolve -ErrorAction 'Stop' ) -ErrorAction 'Stop' - $CurrentVersion = $ScubaManifest.ModuleVersion - $LatestVersion = $(Invoke-RestMethod -Uri "https://api.github.com/repos/cisagov/ScubaGear/releases/latest" -ErrorAction 'Stop').tag_name.TrimStart("v") - if ($CurrentVersion -ne $LatestVersion) { + $CurrentVersion = [System.Version]$ScubaManifest.ModuleVersion + $LatestVersion = [System.Version]$(Invoke-RestMethod -Uri "https://api.github.com/repos/cisagov/ScubaGear/releases/latest" -ErrorAction 'Stop').tag_name.TrimStart("v") + if ($CurrentVersion -lt $LatestVersion) { Write-Warning "A new version of ScubaGear ($latestVersion) is available. Please consider updating at: https://github.com/cisagov/ScubaGear/releases. This notification can be disabled by setting `$env:SCUBAGEAR_SKIP_VERSION_CHECK = `$true before running ScubaGear." } } From d4432302782bede0ccecdfe5d704418a634a5231 Mon Sep 17 00:00:00 2001 From: Thom Neale Date: Fri, 27 Dec 2024 13:29:39 -0500 Subject: [PATCH 4/7] Handle case of multiple scubas installed --- PowerShell/ScubaGear/CheckVersion.ps1 | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/PowerShell/ScubaGear/CheckVersion.ps1 b/PowerShell/ScubaGear/CheckVersion.ps1 index fae75c08de..23f45634f8 100644 --- a/PowerShell/ScubaGear/CheckVersion.ps1 +++ b/PowerShell/ScubaGear/CheckVersion.ps1 @@ -1,23 +1,29 @@ -function Invoke-CheckScubaGearVersionPSGallery { +function Invoke-CheckScubaGearVersion { # Retrieve the installed version of ScubaGear from the system $InstalledModule = Get-Module -Name ScubaGear -ListAvailable -ErrorAction 'Stop' - if ($InstalledModule) { - $CurrentVersion = [System.Version]$InstalledModule.Version - } else { + + # If multiple different versions are installed, get the most recent. + if ($InstalledModule -is [array]) { + $InstalledModule = $InstalledModule | Sort-Object | Select-Object -First 1 + } + + # Check if no results found. + if (!$InstalledModule) { # If we are here, ScubaGear is not installed from PSGallery. # Or it may have been installed a different way in a nonstandard folder, # or is running in an extracted release folder. Check github instead. return Invoke-CheckScubaGearVersionGithub -ErrorAction 'Stop' } + $LatestInstalledVersion = [System.Version]$InstalledModule.Version + # Retrieve the latest version from PowerShell Gallery $ModuleInfo = Find-Module -Name ScubaGear -ErrorAction 'Stop' - $LatestVersion = [System.Version]$ModuleInfo.Version - - if ($CurrentVersion -lt $LatestVersion) { - Write-Warning "A newer version of ScubaGear ($LatestVersion) is available on PowerShell Gallery. This notification can be disabled by setting `$env:SCUBAGEAR_SKIP_VERSION_CHECK = `$true before running ScubaGear." + $LatestPSGalleryVersion = [System.Version]$ModuleInfo.Version + if ($LatestInstalledVersion -lt $LatestPSGalleryVersion) { + Write-Warning "A newer version of ScubaGear ($LatestPSGalleryVersion) is available on PowerShell Gallery. This notification can be disabled by setting `$env:SCUBAGEAR_SKIP_VERSION_CHECK = `$true before running ScubaGear." } } @@ -34,7 +40,7 @@ function Invoke-CheckScubaGearVersionGithub { # Do the version check if the skip envvar is not defined. if ([string]::IsNullOrWhiteSpace($env:SCUBAGEAR_SKIP_VERSION_CHECK)) { try { - Invoke-CheckScubaGearVersionPSGallery -ErrorAction 'Stop' + Invoke-CheckScubaGearVersion -ErrorAction 'Stop' } catch { Write-Warning "The ScubaGear version check failed to execute. This notification can be disabled by setting `$env:SCUBAGEAR_SKIP_VERSION_CHECK = `$true.`n$($_.Exception.Message)`n$($_.ScriptStackTrace)" From 8e4e2969fdc0d4520dbc403e90a9aac57b003dee Mon Sep 17 00:00:00 2001 From: Thom Neale Date: Thu, 2 Jan 2025 12:26:10 -0500 Subject: [PATCH 5/7] Sort by the version property --- PowerShell/ScubaGear/CheckVersion.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/ScubaGear/CheckVersion.ps1 b/PowerShell/ScubaGear/CheckVersion.ps1 index 23f45634f8..0d31c3bbaa 100644 --- a/PowerShell/ScubaGear/CheckVersion.ps1 +++ b/PowerShell/ScubaGear/CheckVersion.ps1 @@ -5,7 +5,7 @@ function Invoke-CheckScubaGearVersion { # If multiple different versions are installed, get the most recent. if ($InstalledModule -is [array]) { - $InstalledModule = $InstalledModule | Sort-Object | Select-Object -First 1 + $InstalledModule = $InstalledModule | Sort-Object -Property Version | Select-Object -Last 1 } # Check if no results found. From 8230ca2632fe2f41ee3aba0582e1f6532c71f234 Mon Sep 17 00:00:00 2001 From: Thom Neale Date: Thu, 2 Jan 2025 14:30:23 -0500 Subject: [PATCH 6/7] Added docstrings --- PowerShell/ScubaGear/CheckVersion.ps1 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/PowerShell/ScubaGear/CheckVersion.ps1 b/PowerShell/ScubaGear/CheckVersion.ps1 index 0d31c3bbaa..2c34a56255 100644 --- a/PowerShell/ScubaGear/CheckVersion.ps1 +++ b/PowerShell/ScubaGear/CheckVersion.ps1 @@ -1,4 +1,12 @@ function Invoke-CheckScubaGearVersion { + <# + .SYNOPSIS + Complain if a newer version of ScubaGear is available on PSGallery. + + .DESCRIPTION + Checks PSGallery latest version and compares it to the latest version installed + from PSGallery. + #> # Retrieve the installed version of ScubaGear from the system $InstalledModule = Get-Module -Name ScubaGear -ListAvailable -ErrorAction 'Stop' @@ -29,6 +37,13 @@ function Invoke-CheckScubaGearVersion { function Invoke-CheckScubaGearVersionGithub { + <# + .SYNOPSIS + Complain if a newer version of ScubaGear is available from the Github release page. + + .DESCRIPTION + Checks latest version available on the github release page and compares it to the current running verison. + #> $ScubaManifest = Import-PowerShellDataFile (Join-Path -Path $PSScriptRoot -ChildPath 'ScubaGear.psd1' -Resolve -ErrorAction 'Stop' ) -ErrorAction 'Stop' $CurrentVersion = [System.Version]$ScubaManifest.ModuleVersion $LatestVersion = [System.Version]$(Invoke-RestMethod -Uri "https://api.github.com/repos/cisagov/ScubaGear/releases/latest" -ErrorAction 'Stop').tag_name.TrimStart("v") From 30ec25d709372afbd57c1e9a75e09968c9883969 Mon Sep 17 00:00:00 2001 From: Thom Neale Date: Fri, 3 Jan 2025 10:08:17 -0500 Subject: [PATCH 7/7] Nuke the PSGallery checks --- PowerShell/ScubaGear/CheckVersion.ps1 | 39 +-------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/PowerShell/ScubaGear/CheckVersion.ps1 b/PowerShell/ScubaGear/CheckVersion.ps1 index 2c34a56255..35a095d2f9 100644 --- a/PowerShell/ScubaGear/CheckVersion.ps1 +++ b/PowerShell/ScubaGear/CheckVersion.ps1 @@ -1,42 +1,5 @@ -function Invoke-CheckScubaGearVersion { - <# - .SYNOPSIS - Complain if a newer version of ScubaGear is available on PSGallery. - - .DESCRIPTION - Checks PSGallery latest version and compares it to the latest version installed - from PSGallery. - #> - - # Retrieve the installed version of ScubaGear from the system - $InstalledModule = Get-Module -Name ScubaGear -ListAvailable -ErrorAction 'Stop' - - # If multiple different versions are installed, get the most recent. - if ($InstalledModule -is [array]) { - $InstalledModule = $InstalledModule | Sort-Object -Property Version | Select-Object -Last 1 - } - # Check if no results found. - if (!$InstalledModule) { - # If we are here, ScubaGear is not installed from PSGallery. - # Or it may have been installed a different way in a nonstandard folder, - # or is running in an extracted release folder. Check github instead. - return Invoke-CheckScubaGearVersionGithub -ErrorAction 'Stop' - } - - $LatestInstalledVersion = [System.Version]$InstalledModule.Version - - # Retrieve the latest version from PowerShell Gallery - $ModuleInfo = Find-Module -Name ScubaGear -ErrorAction 'Stop' - $LatestPSGalleryVersion = [System.Version]$ModuleInfo.Version - - if ($LatestInstalledVersion -lt $LatestPSGalleryVersion) { - Write-Warning "A newer version of ScubaGear ($LatestPSGalleryVersion) is available on PowerShell Gallery. This notification can be disabled by setting `$env:SCUBAGEAR_SKIP_VERSION_CHECK = `$true before running ScubaGear." - } -} - - -function Invoke-CheckScubaGearVersionGithub { +function Invoke-CheckScubaGearVersion { <# .SYNOPSIS Complain if a newer version of ScubaGear is available from the Github release page.