From 884606c500c807ab7bd9fc944e095cbf65647b46 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Mon, 7 Oct 2019 00:03:19 -0500 Subject: [PATCH 1/4] v2.33.2 ready for release ## 2.33.2 - 2019-10-06 * [Issue #242](https://github.com/scrthq/PSGSuite/issues/242) * Fixed: Error handling around `[System.Console]::CursorVisible` on `Start-GSDriveFileUpload`, `Wait-GSDriveFileUpload` and `Write-InlineProgress` * Cleaned up verbose handling on `Stop-GSDriveFileUpload` due to file uploads showing as Failed even though they were successful. * Miscellaneous * Updated build.ps1 script for better verbose output --- CHANGELOG.md | 9 ++++++ PSGSuite/PSGSuite.psd1 | 2 +- PSGSuite/Private/Write-InlineProgress.ps1 | 29 ++++++++++++++++--- .../Public/Drive/Start-GSDriveFileUpload.ps1 | 14 +++++++-- .../Public/Drive/Stop-GSDriveFileUpload.ps1 | 12 ++++++-- README.md | 8 +++++ build.ps1 | 2 +- psake.ps1 | 21 ++++++++++---- 8 files changed, 80 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7ca9c9f..1c3eeb3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ * [PSGSuite - ChangeLog](#psgsuite---changelog) + * [2.33.2 - 2019-10-06](#2332---2019-10-06) * [2.33.1 - 2019-10-06](#2331---2019-10-06) * [2.33.0 - 2019-09-26](#2330---2019-09-26) * [2.32.3 - 2019-09-18](#2323---2019-09-18) @@ -102,6 +103,14 @@ # PSGSuite - ChangeLog +## 2.33.2 - 2019-10-06 + +* [Issue #242](https://github.com/scrthq/PSGSuite/issues/242) + * Fixed: Error handling around `[System.Console]::CursorVisible` on `Start-GSDriveFileUpload`, `Wait-GSDriveFileUpload` and `Write-InlineProgress` + * Cleaned up verbose handling on `Stop-GSDriveFileUpload` due to file uploads showing as Failed even though they were successful. +* Miscellaneous + * Updated build.ps1 script for better verbose output + ## 2.33.1 - 2019-10-06 * [Issue #235](https://github.com/scrthq/PSGSuite/issues/235) diff --git a/PSGSuite/PSGSuite.psd1 b/PSGSuite/PSGSuite.psd1 index d41bc804..2042e823 100644 --- a/PSGSuite/PSGSuite.psd1 +++ b/PSGSuite/PSGSuite.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSGSuite.psm1' # Version number of this module. - ModuleVersion = '2.33.1' + ModuleVersion = '2.33.2' # ID used to uniquely identify this module GUID = '9d751152-e83e-40bb-a6db-4c329092aaec' diff --git a/PSGSuite/Private/Write-InlineProgress.ps1 b/PSGSuite/Private/Write-InlineProgress.ps1 index 861a6e88..d6bd10a1 100644 --- a/PSGSuite/Private/Write-InlineProgress.ps1 +++ b/PSGSuite/Private/Write-InlineProgress.ps1 @@ -116,7 +116,14 @@ function Write-InlineProgress { Remove-Variable -Name 'lastProgressString' -Scope 'Script' -ErrorAction SilentlyContinue [console]::WriteLine() } - [console]::CursorVisible = $true + try { + [System.Console]::CursorVisible = $true + } + catch { + if ($Error[0].Exception.Message -eq 'Exception setting "CursorVisible": "The handle is invalid."') { + $Global:Error.Remove($Global:Error[0]) + } + } } else { if ($Completed) { @@ -135,7 +142,14 @@ function Write-InlineProgress { $cursorPosition = $host.UI.RawUI.CursorPosition #$cursorPositionY = $host.UI.RawUI.CursorPosition.Y - [console]::CursorVisible=$false + try { + [System.Console]::CursorVisible = $false + } + catch { + if ($Error[0].Exception.Message -eq 'Exception setting "CursorVisible": "The handle is invalid."') { + $Global:Error.Remove($Global:Error[0]) + } + } $windowWidth = [console]::WindowWidth # if screen is very small, don't display the percent @@ -231,7 +245,14 @@ function Write-InlineProgress { if ($Completed) { # do some clean-up and jump to the next line Remove-Variable -Name 'lastProgressString' -Scope 'Script' -ErrorAction SilentlyContinue - [console]::CursorVisible = $true + try { + [System.Console]::CursorVisible = $true + } + catch { + if ($Error[0].Exception.Message -eq 'Exception setting "CursorVisible": "The handle is invalid."') { + $Global:Error.Remove($Global:Error[0]) + } + } [console]::WriteLine() } } @@ -239,4 +260,4 @@ function Write-InlineProgress { else { Write-Warning 'This function is not compatible with PowerShell ISE.' } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 b/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 index 04bcb8a3..d4946acc 100644 --- a/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 +++ b/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 @@ -79,6 +79,9 @@ function Start-GSDriveFileUpload { $throttleCount = 0 $totalThrottleCount = 0 $totalFiles = 0 + $successParam = @{ + Successful = $false + } } Process { if ($User -ceq 'me') { @@ -217,9 +220,14 @@ function Start-GSDriveFileUpload { } } finally { - if ($Host.Name -and $Host.Name -notlike "Windows*PowerShell*ISE*") { + try { [System.Console]::CursorVisible = $true } + catch { + if ($Error[0].Exception.Message -eq 'Exception setting "CursorVisible": "The handle is invalid."') { + $Global:Error.Remove($Global:Error[0]) + } + } } } End { @@ -233,6 +241,7 @@ function Start-GSDriveFileUpload { $failedFiles = $fullStatusList | Where-Object {$_.Status -eq "Failed"} if (!$failedFiles) { Write-Verbose "All files uploaded to Google Drive successfully! Total time: $("{0:c}" -f ((Get-Date) - $start) -replace "\..*")" + $successParam['Successful'] = $true } elseif ($RetryCount) { $totalRetries = 0 @@ -312,6 +321,7 @@ function Start-GSDriveFileUpload { } elseif (!$failedFiles) { Write-Verbose "All files uploaded to Google Drive successfully! Total time: $("{0:c}" -f ((Get-Date) - $start) -replace "\..*")" + $successParam['Successful'] = $true } } } @@ -327,7 +337,7 @@ function Start-GSDriveFileUpload { if ($Host.Name -and $Host.Name -notlike "Windows*PowerShell*ISE*") { [System.Console]::CursorVisible = $true } - Stop-GSDriveFileUpload + Stop-GSDriveFileUpload @successParam } } } diff --git a/PSGSuite/Public/Drive/Stop-GSDriveFileUpload.ps1 b/PSGSuite/Public/Drive/Stop-GSDriveFileUpload.ps1 index 37ad40b2..6f32e7c2 100644 --- a/PSGSuite/Public/Drive/Stop-GSDriveFileUpload.ps1 +++ b/PSGSuite/Public/Drive/Stop-GSDriveFileUpload.ps1 @@ -12,15 +12,21 @@ function Stop-GSDriveFileUpload { Stops all Drive file uploads in progress and disposes of all streams. #> [cmdletbinding()] - Param () + Param ( + [Parameter(DontShow)] + [Switch] + $Successful + ) Begin { Write-Verbose "Stopping all remaining Drive file uploads!" } Process { foreach ($task in $script:DriveUploadTasks | Where-Object {$_.Stream -and -not $_.StreamDisposed}) { try { - $progress = {$task.Request.GetProgress()}.InvokeReturnAsIs() - Write-Verbose "[$($progress.Status)] Stopping stream of Task Id [$($task.Id)] | File [$($task.File.FullName)]" + if (-not $Successful) { + $progress = {$task.Request.GetProgress()}.InvokeReturnAsIs() + Write-Verbose "[$($progress.Status)] Stopping stream of Task Id [$($task.Id)] | File [$($task.File.FullName)]" + } $task.Stream.Dispose() $task.StreamDisposed = $true } diff --git a/README.md b/README.md index 1b9dd5ec..24feecd3 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,14 @@ All other functions are either intact or have an alias included to support backw [Full CHANGELOG here](https://github.com/scrthq/PSGSuite/blob/master/CHANGELOG.md) +#### 2.33.2 - 2019-10-06 + +* [Issue #242](https://github.com/scrthq/PSGSuite/issues/242) + * Fixed: Error handling around `[System.Console]::CursorVisible` on `Start-GSDriveFileUpload`, `Wait-GSDriveFileUpload` and `Write-InlineProgress` + * Cleaned up verbose handling on `Stop-GSDriveFileUpload` due to file uploads showing as Failed even though they were successful. +* Miscellaneous + * Updated build.ps1 script for better verbose output + #### 2.33.1 - 2019-10-06 * [Issue #235](https://github.com/scrthq/PSGSuite/issues/235) diff --git a/build.ps1 b/build.ps1 index 2376bca0..a5fd0de8 100644 --- a/build.ps1 +++ b/build.ps1 @@ -18,7 +18,7 @@ $Dependencies = @{ Configuration = '1.3.1' psake = '4.9.0' } -if ($env:SYSTEM_STAGENAME -eq 'Build') { +if ($env:SYSTEM_STAGENAME -eq 'Build' -or -not $IsCI) { $Dependencies['PowerShellGet'] = '2.2.1' } $update = @{} diff --git a/psake.ps1 b/psake.ps1 index 88295de6..ed1f08f5 100644 --- a/psake.ps1 +++ b/psake.ps1 @@ -100,13 +100,22 @@ task Compile -depends Clean { Write-BuildLog 'Creating psm1...' $psm1 = Copy-Item -Path (Join-Path -Path $sut -ChildPath 'PSGSuite.psm1') -Destination (Join-Path -Path $outputModVerDir -ChildPath "$($ENV:BHProjectName).psm1") -PassThru - Get-ChildItem -Path (Join-Path -Path $sut -ChildPath 'Private') -Recurse -File | ForEach-Object { - "$(Get-Content $_.FullName -Raw)`n" | Add-Content -Path $psm1 -Encoding UTF8 - } - Get-ChildItem -Path (Join-Path -Path $sut -ChildPath 'Public') -Recurse -File | ForEach-Object { - "$(Get-Content $_.FullName -Raw)`nExport-ModuleMember -Function '$($_.BaseName)'`n" | Add-Content -Path $psm1 -Encoding UTF8 - $functionsToExport += $_.BaseName + foreach ($scope in @('Private','Public')) { + Write-BuildLog "Copying contents from files in source folder to PSM1: $($scope)" + $gciPath = Join-Path $sut $scope + if (Test-Path $gciPath) { + Get-ChildItem -Path $gciPath -Filter "*.ps1" -Recurse -File | ForEach-Object { + Write-BuildLog "Working on: $scope$([System.IO.Path]::DirectorySeparatorChar)$($_.FullName.Replace("$gciPath$([System.IO.Path]::DirectorySeparatorChar)",'') -replace '\.ps1$')" + [System.IO.File]::AppendAllText($psm1,("$([System.IO.File]::ReadAllText($_.FullName))`n")) + if ($scope -eq 'Public') { + $functionsToExport += $_.BaseName + [System.IO.File]::AppendAllText($psm1,("Export-ModuleMember -Function '$($_.BaseName)'`n")) + } + } + } } + + Invoke-CommandWithLog {Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue -Force -Verbose:$false} if ("$env:NoNugetRestore" -ne 'True') { From cacae916427c02a0b5a9a3bf9396ab57a1167365 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Mon, 7 Oct 2019 00:08:29 -0500 Subject: [PATCH 2/4] updated build script --- build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index a5fd0de8..db7a627b 100644 --- a/build.ps1 +++ b/build.ps1 @@ -18,7 +18,7 @@ $Dependencies = @{ Configuration = '1.3.1' psake = '4.9.0' } -if ($env:SYSTEM_STAGENAME -eq 'Build' -or -not $IsCI) { +if ($env:SYSTEM_STAGENAME -eq 'Build' -or -not (Test-Path Env:\TF_BUILD)) { $Dependencies['PowerShellGet'] = '2.2.1' } $update = @{} From 342747e9d8ae960dd9daaaa8b505f7e81c787998 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Mon, 7 Oct 2019 00:28:18 -0500 Subject: [PATCH 3/4] updated parameter help on Stop-GSDriveFileUpload and updated build script --- PSGSuite/Public/Drive/Stop-GSDriveFileUpload.ps1 | 3 +++ ci/AzurePipelinesHelpers.ps1 | 14 +++++++------- psake.ps1 | 11 ++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/PSGSuite/Public/Drive/Stop-GSDriveFileUpload.ps1 b/PSGSuite/Public/Drive/Stop-GSDriveFileUpload.ps1 index 6f32e7c2..13422e3d 100644 --- a/PSGSuite/Public/Drive/Stop-GSDriveFileUpload.ps1 +++ b/PSGSuite/Public/Drive/Stop-GSDriveFileUpload.ps1 @@ -6,6 +6,9 @@ function Stop-GSDriveFileUpload { .DESCRIPTION Stops all Drive file uploads in progress and disposes of all streams. + .PARAMETER Successful + If $true, hides any failed task verbose output + .EXAMPLE Stop-GSDriveFileUpload diff --git a/ci/AzurePipelinesHelpers.ps1 b/ci/AzurePipelinesHelpers.ps1 index 742cf217..94d7b177 100644 --- a/ci/AzurePipelinesHelpers.ps1 +++ b/ci/AzurePipelinesHelpers.ps1 @@ -232,12 +232,12 @@ Set-Alias -Name Summary -Value Add-EnvironmentSummary -Force function Write-BuildWarning { param( [parameter(Mandatory,Position = 0,ValueFromRemainingArguments,ValueFromPipeline)] - [System.Object] + [System.String] $Message ) Process { Write-Warning $Message - if ($IsCI) { + if ((Test-Path Env:\TF_BUILD)) { Write-Host "##vso[task.logissue type=warning;]$Message" } else { @@ -248,14 +248,14 @@ function Write-BuildWarning { function Write-BuildError { param( [parameter(Mandatory,Position = 0,ValueFromRemainingArguments,ValueFromPipeline)] - [System.Object] + [System.String] $Message ) Process { - Write-Error $Message - if ($IsCI) { + if ((Test-Path Env:\TF_BUILD)) { Write-Host "##vso[task.logissue type=error;]$Message" } + throw $Message } } @@ -388,14 +388,14 @@ function Set-EnvironmentVariable { ) $fullVal = $Value -join " " Set-Item -Path Env:\$Name -Value $fullVal -Force - if ($IsCI) { + if ((Test-Path Env:\TF_BUILD)) { "##vso[task.setvariable variable=$Name]$fullVal" | Write-Host } } Set-Alias -Name SetEnv -Value Set-EnvironmentVariable -Force function Set-BuildVariables { - $gitVars = if ($IsCI) { + $gitVars = if ((Test-Path Env:\TF_BUILD)) { @{ BHBranchName = $env:BUILD_SOURCEBRANCHNAME BHPSModuleManifest = "$env:BuildScriptPath\$env:BuildProjectName\$env:BuildProjectName.psd1" diff --git a/psake.ps1 b/psake.ps1 index ed1f08f5..10767474 100644 --- a/psake.ps1 +++ b/psake.ps1 @@ -91,7 +91,7 @@ task Compile -depends Clean { $functionsToExport = @() $sutLib = [System.IO.Path]::Combine($sut,'lib') $aliasesToExport = (. $sut\Aliases\PSGSuite.Aliases.ps1).Keys - if ("$env:NoNugetRestore" -ne 'True') { + if (-not (Test-Path $outputModVerDir)) { $modDir = New-Item -Path $outputModDir -ItemType Directory -ErrorAction SilentlyContinue New-Item -Path $outputModVerDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null } @@ -340,10 +340,7 @@ Task Import -Depends Compile { } -description 'Imports the newly compiled module' $pesterScriptBlock = { - 'Pester' | Foreach-Object { - Install-Module -Name $_ -Repository PSGallery -Scope CurrentUser -AllowClobber -SkipPublisherCheck -Confirm:$false -ErrorAction Stop -Force - Import-Module -Name $_ -Verbose:$false -ErrorAction Stop -Force - } + 'Pester' | Resolve-Module Push-Location Set-Location -PassThru $outputModDir if (-not $ENV:BHProjectPath) { @@ -377,8 +374,8 @@ $pesterScriptBlock = { $testResults = Invoke-Pester @pesterParams ' Pester invocation complete!' if ($testResults.FailedCount -gt 0) { - $testResults | Format-List - Write-Error -Message 'One or more Pester tests failed. Build cannot continue!' + $testResults.TestResult | Where-Object {-not $_.Passed} | Format-List + Write-BuildError -Message 'One or more Pester tests failed. Build cannot continue!' } Pop-Location $env:PSModulePath = $origModulePath From d984abd9635919d57c35a0aedcc38c0fb37bb557 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Mon, 7 Oct 2019 00:41:22 -0500 Subject: [PATCH 4/4] updated build.ps1, psake.ps1 and Start-GSDriveFileUpload.ps1 --- PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 | 9 ++++++++- build.ps1 | 8 -------- psake.ps1 | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 b/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 index d4946acc..30e77848 100644 --- a/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 +++ b/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 @@ -335,7 +335,14 @@ function Start-GSDriveFileUpload { } finally { if ($Host.Name -and $Host.Name -notlike "Windows*PowerShell*ISE*") { - [System.Console]::CursorVisible = $true + try { + [System.Console]::CursorVisible = $true + } + catch { + if ($Error[0].Exception.Message -eq 'Exception setting "CursorVisible": "The handle is invalid."') { + $Global:Error.Remove($Global:Error[0]) + } + } } Stop-GSDriveFileUpload @successParam } diff --git a/build.ps1 b/build.ps1 index db7a627b..a8ce6aa5 100644 --- a/build.ps1 +++ b/build.ps1 @@ -137,14 +137,6 @@ else { " + NuGet API key is not null : $($null -ne $env:NugetApiKey)`n" + " + Commit message matches '!deploy' : $($env:BUILD_SOURCEVERSIONMESSAGE -match '!deploy') [$env:BUILD_SOURCEVERSIONMESSAGE]"| Write-Host -ForegroundColor Green } - <# - if (-not (Get-Module BuildHelpers -ListAvailable | Where-Object {$_.Version -eq '2.0.1'})) { - Write-Verbose "Installing BuildHelpers v2.0.1" -Verbose - Install-Module 'BuildHelpers' -RequiredVersion 2.0.1 -Scope CurrentUser -Repository PSGallery -AllowClobber -SkipPublisherCheck -Force - } - Write-Verbose "Importing BuildHelpers v2.0.1" -Verbose - Import-Module 'BuildHelpers' -RequiredVersion 2.0.1 - #> Write-BuildLog "Resolving necessary modules" $moduleDependencies.Name | Resolve-Module -UpdateModules -Verbose Write-BuildLog "Modules resolved" diff --git a/psake.ps1 b/psake.ps1 index 10767474..24a2eecf 100644 --- a/psake.ps1 +++ b/psake.ps1 @@ -340,7 +340,7 @@ Task Import -Depends Compile { } -description 'Imports the newly compiled module' $pesterScriptBlock = { - 'Pester' | Resolve-Module + 'Pester' | Resolve-Module -UpdateModules -Verbose Push-Location Set-Location -PassThru $outputModDir if (-not $ENV:BHProjectPath) {