Skip to content

Commit

Permalink
Added breaking change warning and new version notification on module …
Browse files Browse the repository at this point in the history
…load (#440)

* added notification messages on module load
* moved custom message to function
* deactivate updated message calls in test tasks
* added initial unit test
* added module message function to psm1
  • Loading branch information
SebastianSchuetze authored Feb 21, 2022
1 parent 02de3c4 commit 682186d
Show file tree
Hide file tree
Showing 9 changed files with 359 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// Uncomment the next line to run commands after the container is created. This gets run in bash which is why we call `pwsh`.
// "postCreateCommand": "pwsh -c '$PSVersionTable'",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
//"remoteUser": "vscode",
"build": {
"args": {
"UPGRADE_PACKAGES": "true"
Expand Down
9 changes: 9 additions & 0 deletions .github/moduleMessages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"msg": "Module Version 8.0.0 will stop supporting all TFS (2017,2018) versions. In the future it will also only keep the newest server versions in the support.",
"toDate": "14/02/2022 23:41:51",
"displayFromVersion": "7.4.0",
"displayToVersion": "8.0.0",
"type": "warning"
}
]
6 changes: 6 additions & 0 deletions .github/workflows/actions-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ jobs:
$pesterArgs.TestResult.OutputFormat = 'JUnitXml'
$pesterArgs.TestResult.OutputPath = 'test-results.xml'
$env:VSTEAM_NO_UPDATE_MESSAGE = $true
$env:VSTEAM_NO_MODULE_MESSAGES = $true
Invoke-Pester -Configuration $pesterArgs
# - name: Publish PowerShell test results
Expand Down Expand Up @@ -235,6 +238,9 @@ jobs:
$pesterArgs.TestResult.OutputFormat = 'JUnitXml'
$pesterArgs.TestResult.OutputPath = 'test-results.xml'
$env:VSTEAM_NO_UPDATE_MESSAGE = $true
$env:VSTEAM_NO_MODULE_MESSAGES = $true
Invoke-Pester -Configuration $pesterArgs
shell: pwsh
env:
Expand Down
13 changes: 11 additions & 2 deletions Build-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,21 @@ if ($ipmo.IsPresent -or $analyzeScript.IsPresent -or $runIntegrationTests.IsPres
# run PSScriptAnalyzer
if ($analyzeScript.IsPresent) {
Write-Output "Starting static code analysis..."
if ($null -eq $(Get-Module -Name PSScriptAnalyzer)) {
if ($null -eq $(Get-Module -Name PSScriptAnalyzer -ListAvailable)) {
Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Force -Scope CurrentUser
}


$r = Invoke-ScriptAnalyzer -Path $output -Recurse
$r | ForEach-Object { Write-Host "##vso[task.logissue type=$($_.Severity);sourcepath=$($_.ScriptPath);linenumber=$($_.Line);columnnumber=$($_.Column);]$($_.Message)" }
$r | ForEach-Object {

$severity = ([string]$_.Severity).ToLower()
if ($severity -eq 'information') {
$severity = "notice"
}

Write-Host "::$severity file=$($_.ScriptPath),line=$($_.Line),col=$($_.Column)::$($_.Message)"
}
Write-Output "Static code analysis complete."
}

Expand Down
114 changes: 111 additions & 3 deletions Source/Private/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function _getApiVersion {
'DistributedTaskReleased', 'VariableGroups', 'Tfvc',
'Packaging', 'MemberEntitlementManagement',
'ExtensionsManagement', 'ServiceEndpoints', 'Graph',
'TaskGroups', 'Policy', 'Processes', 'HierarchyQuery', 'Pipelines', 'Billing', 'Wiki','WorkItemTracking')]
'TaskGroups', 'Policy', 'Processes', 'HierarchyQuery', 'Pipelines', 'Billing', 'Wiki', 'WorkItemTracking')]
[string] $Service,

[parameter(ParameterSetName = 'Target')]
Expand Down Expand Up @@ -1050,9 +1050,9 @@ function _getBillingToken {
param (
#billing token can have different scopes. They are defined by named token ids.
#They should be validated to be specific by it's name
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string]
[ValidateSet('AzCommDeploymentProfile','CommerceDeploymentProfile')]
[ValidateSet('AzCommDeploymentProfile', 'CommerceDeploymentProfile')]
$NamedTokenId
)

Expand All @@ -1074,3 +1074,111 @@ function _getBillingToken {

return $billingToken
}

# pin if github is availabe and client has access to github
function _pinpGithub {
Write-Verbose "Checking if client is online"
$pingGh = [System.Net.NetworkInformation.Ping]::new()
[System.Net.NetworkInformation.PingReply]$reply = $pingGh.Send('github.com', 150)
return $reply.Status
}

function _showModuleLoadingMessages {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
Justification = 'False positive. Parameter is being used, but not catched when used in script blocks. see: https://github.com/PowerShell/PSScriptAnalyzer/issues/1472')]
[CmdletBinding()]
param (
# version of the module
[Parameter(Mandatory = $true)]
[version]
$ModuleVersion
)

process {
if ((_pinpGithub) -eq [System.Net.NetworkInformation.IPStatus]::Success) {
# catch if web request fails. Invoke-WebRequest does not have a ErrorAction parameter
try {

$moduleMessagesRes = (Invoke-RestMethod "https://raw.githubusercontent.com/MethodsAndPractices/vsteam/topic/addModuleLoadingNotifications/.github/moduleMessages.json")

# don't show messages if module has not the specified version
$filteredMessages = $moduleMessagesRes | Where-Object {

$returnMessage = $true

if (-not [String]::IsNullOrEmpty($_.displayFromVersion)) {
$returnMessage = ([version]$_.displayFromVersion) -le $ModuleVersion
}

if (-not [String]::IsNullOrEmpty($_.displayToVersion) -and $returnMessage -eq $true) {
$returnMessage = ([version]$_.displayToVersion) -ge $ModuleVersion
}

return $returnMessage
}

# dont show messages if display until date is in the past
$currentDate = Get-Date
$filteredMessages = $filteredMessages | Where-Object {$currentDate -le ([DateTime]::Parse($_.toDate))
}

# stop processing if no messages left
if ($null -eq $filteredMessages -or $filteredMessages.Count -eq 0) {
return
}

$filteredMessages | ForEach-Object {
$messageFormat = "{0}: {1}"
Write-Information ($messageFormat -f $_.type.ToUpper(), $_.msg) -InformationAction Continue
}



}
catch {
Write-Debug "Error: $_"
}
}else{
Write-Debug "Client is offline. Skipping module messages"
}
}
}

function _checkForModuleUpdates {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
Justification = 'False positive. Parameter is being used, but not catched when used in script blocks. see: https://github.com/PowerShell/PSScriptAnalyzer/issues/1472')]
[CmdletBinding()]
param (
# version of the module
[Parameter(Mandatory = $true)]
[version]
$ModuleVersion
)

process {

# check if client has online access
if ((_pinpGithub) -eq [System.Net.NetworkInformation.IPStatus]::Success) {

# catch if web request fails. Invoke-WebRequest does not have a ErrorAction parameter
try {
Write-Verbose "Checking if module is up to date"
$ghLatestRelease = Invoke-RestMethod "https://api.github.com/repos/MethodsAndPractices/vsteam/releases/latest"

[version]$latestVersion = $ghLatestRelease.tag_name -replace "v", ""
[version]$currentVersion = $ModuleVersion

if ($currentVersion -lt $latestVersion) {
Write-Information "New version available: $latestVersion" -InformationAction Continue
Write-Information "Run to update: Update-Module -Name VSTeam -RequiredVersion $latestVersion `n" -InformationAction Continue
}
}
catch {
Write-Debug "Error: $_"
}
}else{
Write-Debug "Client is offline. Skipping module updates check"
}
}

}
11 changes: 11 additions & 0 deletions Source/VSTeam.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
# Load the correct version of the environment variable
Set-VSTeamAPIVersion -Target $([vsteam_lib.Versions]::Version)

#compare versions and notify user
# new versions for the module are only checked if $env:VSTEAM_NO_UPDATE_MESSAGE is not set
if(($env:VSTEAM_NO_UPDATE_MESSAGE -eq $false) -or ($null -eq $env:VSTEAM_NO_UPDATE_MESSAGE)) {
_checkForModuleUpdates -ModuleVersion ([version][vsteam_lib.Versions]::ModuleVersion) -ErrorAction Continue
}

# display custom message if set and not $true
if(($env:VSTEAM_NO_MODULE_MESSAGES -eq $false) -or ($null -eq $env:VSTEAM_NO_MODULE_MESSAGES)) {
_showModuleLoadingMessages -ModuleVersion ([version][vsteam_lib.Versions]::ModuleVersion) -ErrorAction Continue
}

# Check to see if the user stored the default project in an environment variable
if ($null -ne $env:TEAM_PROJECT) {
# Make sure the value in the environment variable still exisits.
Expand Down
74 changes: 74 additions & 0 deletions Tests/SampleFiles/githubLatestRelease.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"url": "https://api.github.com/repos/MethodsAndPractices/vsteam/releases/56861123",
"assets_url": "https://api.github.com/repos/MethodsAndPractices/vsteam/releases/56861123/assets",
"upload_url": "https://uploads.github.com/repos/MethodsAndPractices/vsteam/releases/56861123/assets{?name,label}",
"html_url": "https://github.com/MethodsAndPractices/vsteam/releases/tag/v7.5.0",
"id": 56861123,
"author": {
"login": "github-actions[bot]",
"id": 41898282,
"node_id": "MDM6Qm90NDE4OTgyODI=",
"avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github-actions%5Bbot%5D",
"html_url": "https://github.com/apps/github-actions",
"followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers",
"following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}",
"gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions",
"organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs",
"repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos",
"events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
"received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events",
"type": "Bot",
"site_admin": false
},
"node_id": "RE_kwDOBLCmEc4DY6HD",
"tag_name": "v7.5.0",
"target_commitish": "trunk",
"name": "v7.5.0",
"draft": false,
"prerelease": false,
"created_at": "2022-01-11T19:15:48Z",
"published_at": "2022-01-11T19:52:31Z",
"assets": [{
"url": "https://api.github.com/repos/MethodsAndPractices/vsteam/releases/assets/53730365",
"id": 53730365,
"node_id": "RA_kwDOBLCmEc4DM9w9",
"name": "VSTeam.7.5.0.181.nupkg",
"label": "",
"uploader": {
"login": "github-actions[bot]",
"id": 41898282,
"node_id": "MDM6Qm90NDE4OTgyODI=",
"avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github-actions%5Bbot%5D",
"html_url": "https://github.com/apps/github-actions",
"followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers",
"following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}",
"gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions",
"organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs",
"repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos",
"events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
"received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events",
"type": "Bot",
"site_admin": false
},
"content_type": "raw",
"state": "uploaded",
"size": 199557,
"download_count": 1,
"created_at": "2022-01-11T19:52:32Z",
"updated_at": "2022-01-11T19:52:32Z",
"browser_download_url": "https://github.com/MethodsAndPractices/vsteam/releases/download/v7.5.0/VSTeam.7.5.0.181.nupkg"
}],
"tarball_url": "https://api.github.com/repos/MethodsAndPractices/vsteam/tarball/v7.5.0",
"zipball_url": "https://api.github.com/repos/MethodsAndPractices/vsteam/zipball/v7.5.0",
"body": "## What's Changed\n* Exclude cmdlet Get-VSTeamAccounts from PSAnalyzer plural rule by @SebastianSchuetze in https://github.com/MethodsAndPractices/vsteam/pull/416\n* Added Wiki cmdlets by @gm0d in https://github.com/MethodsAndPractices/vsteam/pull/414\n* Update-VSTeamNuGetPackageVersion added missing project parameter by @SebastianSchuetze in https://github.com/MethodsAndPractices/vsteam/pull/422\n* Migrated Azure Pipelines to Github Actions by @SebastianSchuetze in https://github.com/MethodsAndPractices/vsteam/pull/432\n* Fix Update-VSTeamUserEntitlement to correctly use contentype application/json-patch+json by @thahif in https://github.com/MethodsAndPractices/vsteam/pull/430\n* Multiple bug fixes for github workflow by @SebastianSchuetze in https://github.com/MethodsAndPractices/vsteam/pull/434\n\n## New Contributors\n* @gm0d made their first contribution in https://github.com/MethodsAndPractices/vsteam/pull/414\n* @thahif made their first contribution in https://github.com/MethodsAndPractices/vsteam/pull/430\n\n**Full Changelog**: https://github.com/MethodsAndPractices/vsteam/compare/v7.4.0...v7.5.0",
"discussion_url": "https://github.com/MethodsAndPractices/vsteam/discussions/435",
"mentions_count": 3
}
27 changes: 27 additions & 0 deletions Tests/SampleFiles/moduleMessages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"msg": "Message for minimum version 5.6.0",
"toDate": "2099-02-14 13:36:17Z",
"displayFromVersion": "5.6.0",
"type": "info"
},
{
"msg": "Message for minimum version 7.0.0",
"toDate": "2099-02-13 13:36:17Z",
"displayFromVersion": "7.0.0",
"type": "warning"
},
{
"msg": "Message for minimum version 6.9.0",
"toDate": "2021-12-31 23:59:59Z",
"displayFromVersion": "6.9.0",
"type": "warning"
},
{
"msg": "Message for minimum version 7.8.0 to maximum version 8.0.0",
"toDate": "2099-12-31 23:59:59Z",
"displayFromVersion": "7.8.0",
"displayToVersion": "8.0.0",
"type": "warning"
}
]
Loading

0 comments on commit 682186d

Please sign in to comment.