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

Remove reference to removed VersionCheckFile #1481

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
41 changes: 11 additions & 30 deletions PowerShell/ScubaGear/CheckVersion.ps1
twneale marked this conversation as resolved.
Show resolved Hide resolved
twneale marked this conversation as resolved.
Show resolved Hide resolved
twneale marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,43 +1,24 @@
function Invoke-CheckScubaGearVersionPSGallery {

# 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 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'
}

# 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 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'
}
function Invoke-CheckScubaGearVersion {
<#
.SYNOPSIS
Complain if a newer version of ScubaGear is available from the Github release page.


function Invoke-CheckScubaGearVersionGithub {
.DESCRIPTION
Checks latest version available on the github release page and compares it to the current running verison.
#>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo and capitalization fix

Suggested change
Checks latest version available on the github release page and compares it to the current running verison.
Checks latest version available on the Github release page and compares it to the current running version.

$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."
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest version may be comparatively newer without being new. Suggest updating language.

Suggested change
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."
Write-Warning "A newer 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."

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about where we point them when a new version is available. Do we point directly to the GitHub release, or to our documentation? PSGallery users won't get much from the GitHub link.
We have install instructions, but not specifically upgrade instructions. Might be a good section to add and maintain in case we run into any difficult/breaking change upgrade paths. Already an issue in #1223. So maybe add to that issue that once instructions are available, update version update function to point to them instead.

}

# 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)"
Expand Down
Loading