Skip to content

Commit d9d6b11

Browse files
authored
!deploy v2.33.2 ready for release (#243)
## 2.33.2 - 2019-10-06 * [Issue #242](#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 parents 6d7a989 + d984abd commit d9d6b11

9 files changed

+102
-40
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* [PSGSuite - ChangeLog](#psgsuite---changelog)
2+
* [2.33.2 - 2019-10-06](#2332---2019-10-06)
23
* [2.33.1 - 2019-10-06](#2331---2019-10-06)
34
* [2.33.0 - 2019-09-26](#2330---2019-09-26)
45
* [2.32.3 - 2019-09-18](#2323---2019-09-18)
@@ -102,6 +103,14 @@
102103

103104
# PSGSuite - ChangeLog
104105

106+
## 2.33.2 - 2019-10-06
107+
108+
* [Issue #242](https://github.com/scrthq/PSGSuite/issues/242)
109+
* Fixed: Error handling around `[System.Console]::CursorVisible` on `Start-GSDriveFileUpload`, `Wait-GSDriveFileUpload` and `Write-InlineProgress`
110+
* Cleaned up verbose handling on `Stop-GSDriveFileUpload` due to file uploads showing as Failed even though they were successful.
111+
* Miscellaneous
112+
* Updated build.ps1 script for better verbose output
113+
105114
## 2.33.1 - 2019-10-06
106115

107116
* [Issue #235](https://github.com/scrthq/PSGSuite/issues/235)

PSGSuite/PSGSuite.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'PSGSuite.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '2.33.1'
15+
ModuleVersion = '2.33.2'
1616

1717
# ID used to uniquely identify this module
1818
GUID = '9d751152-e83e-40bb-a6db-4c329092aaec'

PSGSuite/Private/Write-InlineProgress.ps1

+25-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,14 @@ function Write-InlineProgress {
116116
Remove-Variable -Name 'lastProgressString' -Scope 'Script' -ErrorAction SilentlyContinue
117117
[console]::WriteLine()
118118
}
119-
[console]::CursorVisible = $true
119+
try {
120+
[System.Console]::CursorVisible = $true
121+
}
122+
catch {
123+
if ($Error[0].Exception.Message -eq 'Exception setting "CursorVisible": "The handle is invalid."') {
124+
$Global:Error.Remove($Global:Error[0])
125+
}
126+
}
120127
}
121128
else {
122129
if ($Completed) {
@@ -135,7 +142,14 @@ function Write-InlineProgress {
135142

136143
$cursorPosition = $host.UI.RawUI.CursorPosition
137144
#$cursorPositionY = $host.UI.RawUI.CursorPosition.Y
138-
[console]::CursorVisible=$false
145+
try {
146+
[System.Console]::CursorVisible = $false
147+
}
148+
catch {
149+
if ($Error[0].Exception.Message -eq 'Exception setting "CursorVisible": "The handle is invalid."') {
150+
$Global:Error.Remove($Global:Error[0])
151+
}
152+
}
139153
$windowWidth = [console]::WindowWidth
140154

141155
# if screen is very small, don't display the percent
@@ -231,12 +245,19 @@ function Write-InlineProgress {
231245
if ($Completed) {
232246
# do some clean-up and jump to the next line
233247
Remove-Variable -Name 'lastProgressString' -Scope 'Script' -ErrorAction SilentlyContinue
234-
[console]::CursorVisible = $true
248+
try {
249+
[System.Console]::CursorVisible = $true
250+
}
251+
catch {
252+
if ($Error[0].Exception.Message -eq 'Exception setting "CursorVisible": "The handle is invalid."') {
253+
$Global:Error.Remove($Global:Error[0])
254+
}
255+
}
235256
[console]::WriteLine()
236257
}
237258
}
238259
}
239260
else {
240261
Write-Warning 'This function is not compatible with PowerShell ISE.'
241262
}
242-
}
263+
}

PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1

+20-3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ function Start-GSDriveFileUpload {
7979
$throttleCount = 0
8080
$totalThrottleCount = 0
8181
$totalFiles = 0
82+
$successParam = @{
83+
Successful = $false
84+
}
8285
}
8386
Process {
8487
if ($User -ceq 'me') {
@@ -217,9 +220,14 @@ function Start-GSDriveFileUpload {
217220
}
218221
}
219222
finally {
220-
if ($Host.Name -and $Host.Name -notlike "Windows*PowerShell*ISE*") {
223+
try {
221224
[System.Console]::CursorVisible = $true
222225
}
226+
catch {
227+
if ($Error[0].Exception.Message -eq 'Exception setting "CursorVisible": "The handle is invalid."') {
228+
$Global:Error.Remove($Global:Error[0])
229+
}
230+
}
223231
}
224232
}
225233
End {
@@ -233,6 +241,7 @@ function Start-GSDriveFileUpload {
233241
$failedFiles = $fullStatusList | Where-Object {$_.Status -eq "Failed"}
234242
if (!$failedFiles) {
235243
Write-Verbose "All files uploaded to Google Drive successfully! Total time: $("{0:c}" -f ((Get-Date) - $start) -replace "\..*")"
244+
$successParam['Successful'] = $true
236245
}
237246
elseif ($RetryCount) {
238247
$totalRetries = 0
@@ -312,6 +321,7 @@ function Start-GSDriveFileUpload {
312321
}
313322
elseif (!$failedFiles) {
314323
Write-Verbose "All files uploaded to Google Drive successfully! Total time: $("{0:c}" -f ((Get-Date) - $start) -replace "\..*")"
324+
$successParam['Successful'] = $true
315325
}
316326
}
317327
}
@@ -325,9 +335,16 @@ function Start-GSDriveFileUpload {
325335
}
326336
finally {
327337
if ($Host.Name -and $Host.Name -notlike "Windows*PowerShell*ISE*") {
328-
[System.Console]::CursorVisible = $true
338+
try {
339+
[System.Console]::CursorVisible = $true
340+
}
341+
catch {
342+
if ($Error[0].Exception.Message -eq 'Exception setting "CursorVisible": "The handle is invalid."') {
343+
$Global:Error.Remove($Global:Error[0])
344+
}
345+
}
329346
}
330-
Stop-GSDriveFileUpload
347+
Stop-GSDriveFileUpload @successParam
331348
}
332349
}
333350
}

PSGSuite/Public/Drive/Stop-GSDriveFileUpload.ps1

+12-3
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,30 @@ function Stop-GSDriveFileUpload {
66
.DESCRIPTION
77
Stops all Drive file uploads in progress and disposes of all streams.
88
9+
.PARAMETER Successful
10+
If $true, hides any failed task verbose output
11+
912
.EXAMPLE
1013
Stop-GSDriveFileUpload
1114
1215
Stops all Drive file uploads in progress and disposes of all streams.
1316
#>
1417
[cmdletbinding()]
15-
Param ()
18+
Param (
19+
[Parameter(DontShow)]
20+
[Switch]
21+
$Successful
22+
)
1623
Begin {
1724
Write-Verbose "Stopping all remaining Drive file uploads!"
1825
}
1926
Process {
2027
foreach ($task in $script:DriveUploadTasks | Where-Object {$_.Stream -and -not $_.StreamDisposed}) {
2128
try {
22-
$progress = {$task.Request.GetProgress()}.InvokeReturnAsIs()
23-
Write-Verbose "[$($progress.Status)] Stopping stream of Task Id [$($task.Id)] | File [$($task.File.FullName)]"
29+
if (-not $Successful) {
30+
$progress = {$task.Request.GetProgress()}.InvokeReturnAsIs()
31+
Write-Verbose "[$($progress.Status)] Stopping stream of Task Id [$($task.Id)] | File [$($task.File.FullName)]"
32+
}
2433
$task.Stream.Dispose()
2534
$task.StreamDisposed = $true
2635
}

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ All other functions are either intact or have an alias included to support backw
158158

159159
[Full CHANGELOG here](https://github.com/scrthq/PSGSuite/blob/master/CHANGELOG.md)
160160

161+
#### 2.33.2 - 2019-10-06
162+
163+
* [Issue #242](https://github.com/scrthq/PSGSuite/issues/242)
164+
* Fixed: Error handling around `[System.Console]::CursorVisible` on `Start-GSDriveFileUpload`, `Wait-GSDriveFileUpload` and `Write-InlineProgress`
165+
* Cleaned up verbose handling on `Stop-GSDriveFileUpload` due to file uploads showing as Failed even though they were successful.
166+
* Miscellaneous
167+
* Updated build.ps1 script for better verbose output
168+
161169
#### 2.33.1 - 2019-10-06
162170

163171
* [Issue #235](https://github.com/scrthq/PSGSuite/issues/235)

build.ps1

+1-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $Dependencies = @{
1818
Configuration = '1.3.1'
1919
psake = '4.9.0'
2020
}
21-
if ($env:SYSTEM_STAGENAME -eq 'Build') {
21+
if ($env:SYSTEM_STAGENAME -eq 'Build' -or -not (Test-Path Env:\TF_BUILD)) {
2222
$Dependencies['PowerShellGet'] = '2.2.1'
2323
}
2424
$update = @{}
@@ -137,14 +137,6 @@ else {
137137
" + NuGet API key is not null : $($null -ne $env:NugetApiKey)`n" +
138138
" + Commit message matches '!deploy' : $($env:BUILD_SOURCEVERSIONMESSAGE -match '!deploy') [$env:BUILD_SOURCEVERSIONMESSAGE]"| Write-Host -ForegroundColor Green
139139
}
140-
<#
141-
if (-not (Get-Module BuildHelpers -ListAvailable | Where-Object {$_.Version -eq '2.0.1'})) {
142-
Write-Verbose "Installing BuildHelpers v2.0.1" -Verbose
143-
Install-Module 'BuildHelpers' -RequiredVersion 2.0.1 -Scope CurrentUser -Repository PSGallery -AllowClobber -SkipPublisherCheck -Force
144-
}
145-
Write-Verbose "Importing BuildHelpers v2.0.1" -Verbose
146-
Import-Module 'BuildHelpers' -RequiredVersion 2.0.1
147-
#>
148140
Write-BuildLog "Resolving necessary modules"
149141
$moduleDependencies.Name | Resolve-Module -UpdateModules -Verbose
150142
Write-BuildLog "Modules resolved"

ci/AzurePipelinesHelpers.ps1

+7-7
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,12 @@ Set-Alias -Name Summary -Value Add-EnvironmentSummary -Force
232232
function Write-BuildWarning {
233233
param(
234234
[parameter(Mandatory,Position = 0,ValueFromRemainingArguments,ValueFromPipeline)]
235-
[System.Object]
235+
[System.String]
236236
$Message
237237
)
238238
Process {
239239
Write-Warning $Message
240-
if ($IsCI) {
240+
if ((Test-Path Env:\TF_BUILD)) {
241241
Write-Host "##vso[task.logissue type=warning;]$Message"
242242
}
243243
else {
@@ -248,14 +248,14 @@ function Write-BuildWarning {
248248
function Write-BuildError {
249249
param(
250250
[parameter(Mandatory,Position = 0,ValueFromRemainingArguments,ValueFromPipeline)]
251-
[System.Object]
251+
[System.String]
252252
$Message
253253
)
254254
Process {
255-
Write-Error $Message
256-
if ($IsCI) {
255+
if ((Test-Path Env:\TF_BUILD)) {
257256
Write-Host "##vso[task.logissue type=error;]$Message"
258257
}
258+
throw $Message
259259
}
260260
}
261261

@@ -388,14 +388,14 @@ function Set-EnvironmentVariable {
388388
)
389389
$fullVal = $Value -join " "
390390
Set-Item -Path Env:\$Name -Value $fullVal -Force
391-
if ($IsCI) {
391+
if ((Test-Path Env:\TF_BUILD)) {
392392
"##vso[task.setvariable variable=$Name]$fullVal" | Write-Host
393393
}
394394
}
395395
Set-Alias -Name SetEnv -Value Set-EnvironmentVariable -Force
396396

397397
function Set-BuildVariables {
398-
$gitVars = if ($IsCI) {
398+
$gitVars = if ((Test-Path Env:\TF_BUILD)) {
399399
@{
400400
BHBranchName = $env:BUILD_SOURCEBRANCHNAME
401401
BHPSModuleManifest = "$env:BuildScriptPath\$env:BuildProjectName\$env:BuildProjectName.psd1"

psake.ps1

+19-13
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ task Compile -depends Clean {
9191
$functionsToExport = @()
9292
$sutLib = [System.IO.Path]::Combine($sut,'lib')
9393
$aliasesToExport = (. $sut\Aliases\PSGSuite.Aliases.ps1).Keys
94-
if ("$env:NoNugetRestore" -ne 'True') {
94+
if (-not (Test-Path $outputModVerDir)) {
9595
$modDir = New-Item -Path $outputModDir -ItemType Directory -ErrorAction SilentlyContinue
9696
New-Item -Path $outputModVerDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
9797
}
@@ -100,13 +100,22 @@ task Compile -depends Clean {
100100
Write-BuildLog 'Creating psm1...'
101101
$psm1 = Copy-Item -Path (Join-Path -Path $sut -ChildPath 'PSGSuite.psm1') -Destination (Join-Path -Path $outputModVerDir -ChildPath "$($ENV:BHProjectName).psm1") -PassThru
102102

103-
Get-ChildItem -Path (Join-Path -Path $sut -ChildPath 'Private') -Recurse -File | ForEach-Object {
104-
"$(Get-Content $_.FullName -Raw)`n" | Add-Content -Path $psm1 -Encoding UTF8
105-
}
106-
Get-ChildItem -Path (Join-Path -Path $sut -ChildPath 'Public') -Recurse -File | ForEach-Object {
107-
"$(Get-Content $_.FullName -Raw)`nExport-ModuleMember -Function '$($_.BaseName)'`n" | Add-Content -Path $psm1 -Encoding UTF8
108-
$functionsToExport += $_.BaseName
103+
foreach ($scope in @('Private','Public')) {
104+
Write-BuildLog "Copying contents from files in source folder to PSM1: $($scope)"
105+
$gciPath = Join-Path $sut $scope
106+
if (Test-Path $gciPath) {
107+
Get-ChildItem -Path $gciPath -Filter "*.ps1" -Recurse -File | ForEach-Object {
108+
Write-BuildLog "Working on: $scope$([System.IO.Path]::DirectorySeparatorChar)$($_.FullName.Replace("$gciPath$([System.IO.Path]::DirectorySeparatorChar)",'') -replace '\.ps1$')"
109+
[System.IO.File]::AppendAllText($psm1,("$([System.IO.File]::ReadAllText($_.FullName))`n"))
110+
if ($scope -eq 'Public') {
111+
$functionsToExport += $_.BaseName
112+
[System.IO.File]::AppendAllText($psm1,("Export-ModuleMember -Function '$($_.BaseName)'`n"))
113+
}
114+
}
115+
}
109116
}
117+
118+
110119
Invoke-CommandWithLog {Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue -Force -Verbose:$false}
111120

112121
if ("$env:NoNugetRestore" -ne 'True') {
@@ -331,10 +340,7 @@ Task Import -Depends Compile {
331340
} -description 'Imports the newly compiled module'
332341

333342
$pesterScriptBlock = {
334-
'Pester' | Foreach-Object {
335-
Install-Module -Name $_ -Repository PSGallery -Scope CurrentUser -AllowClobber -SkipPublisherCheck -Confirm:$false -ErrorAction Stop -Force
336-
Import-Module -Name $_ -Verbose:$false -ErrorAction Stop -Force
337-
}
343+
'Pester' | Resolve-Module -UpdateModules -Verbose
338344
Push-Location
339345
Set-Location -PassThru $outputModDir
340346
if (-not $ENV:BHProjectPath) {
@@ -368,8 +374,8 @@ $pesterScriptBlock = {
368374
$testResults = Invoke-Pester @pesterParams
369375
' Pester invocation complete!'
370376
if ($testResults.FailedCount -gt 0) {
371-
$testResults | Format-List
372-
Write-Error -Message 'One or more Pester tests failed. Build cannot continue!'
377+
$testResults.TestResult | Where-Object {-not $_.Passed} | Format-List
378+
Write-BuildError -Message 'One or more Pester tests failed. Build cannot continue!'
373379
}
374380
Pop-Location
375381
$env:PSModulePath = $origModulePath

0 commit comments

Comments
 (0)