From d25cdffcfc2b8d447b24f15b37e4d9cad44ec3a0 Mon Sep 17 00:00:00 2001 From: Sergei Vorobev Date: Tue, 19 Apr 2016 15:51:54 -0700 Subject: [PATCH 1/5] Add $ErrorActionPreference = 'Stop' to fail the build --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 1d4b21f7d1..ed2313d31d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,6 +22,7 @@ install: build_script: - ps: | + $ErrorActionPreference = 'Stop' Import-Module .\PowerShellGitHubDev.psm1 Start-PSBuild -Publish Start-PSBuild -FullCLR @@ -62,6 +63,7 @@ test_script: on_finish: - ps: | + $ErrorActionPreference = 'Stop' # Creating project artifact $name = git describe $zipFilePath = Join-Path $pwd "$name.zip" From db674c797786de057023c3af595f96a83f74a720 Mon Sep 17 00:00:00 2001 From: Sergei Vorobev Date: Tue, 19 Apr 2016 16:00:09 -0700 Subject: [PATCH 2/5] Add try-catch to on_finish section to prevent hang --- appveyor.yml | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index ed2313d31d..ab0366493b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -64,19 +64,23 @@ test_script: on_finish: - ps: | $ErrorActionPreference = 'Stop' - # Creating project artifact - $name = git describe - $zipFilePath = Join-Path $pwd "$name.zip" - $zipFileFullPath = Join-Path $pwd "$name.FullCLR.zip" - Add-Type -assemblyname System.IO.Compression.FileSystem - [System.IO.Compression.ZipFile]::CreateFromDirectory($env:CoreOutput, $zipFilePath) - [System.IO.Compression.ZipFile]::CreateFromDirectory($env:FullOutput, $zipFileFullPath) - - @( - # You can add other artifacts here - $zipFilePath, - $zipFileFullPath - ) | % { - Write-Host "Pushing package $_ as Appveyor artifact" - Push-AppveyorArtifact $_ - } + try { + # Creating project artifact + $name = git describe + $zipFilePath = Join-Path $pwd "$name.zip" + $zipFileFullPath = Join-Path $pwd "$name.FullCLR.zip" + Add-Type -assemblyname System.IO.Compression.FileSystem + [System.IO.Compression.ZipFile]::CreateFromDirectory($env:CoreOutput, $zipFilePath) + [System.IO.Compression.ZipFile]::CreateFromDirectory($env:FullOutput, $zipFileFullPath) + + @( + # You can add other artifacts here + $zipFilePath, + $zipFileFullPath + ) | % { + Write-Host "Pushing package $_ as Appveyor artifact" + Push-AppveyorArtifact $_ + } + } catch { + Write-Host -Foreground Red $_ + } From 8635c84cd97ec9fdce1f4a527986e2c4a8cebbb9 Mon Sep 17 00:00:00 2001 From: Sergei Vorobev Date: Tue, 19 Apr 2016 16:10:09 -0700 Subject: [PATCH 3/5] Fix typo in PowerShellGitHubDev.psm1 --- PowerShellGitHubDev.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShellGitHubDev.psm1 b/PowerShellGitHubDev.psm1 index 203ca1f9a8..c77a72e14f 100644 --- a/PowerShellGitHubDev.psm1 +++ b/PowerShellGitHubDev.psm1 @@ -74,7 +74,7 @@ function Start-PSBuild { # msbuild is needed to build powershell.exe # msbuild is part of .NET Framework, we can try to get it from well-known location. - if (-nopt $NoPath -and -not (Get-Command -Name msbuild -ErrorAction Ignore)) { + if (-not $NoPath -and -not (Get-Command -Name msbuild -ErrorAction Ignore)) { Write-Verbose "Appending probable Visual C++ tools path" $env:path += ";${env:SystemRoot}\Microsoft.Net\Framework\v4.0.30319" } From f28bd0814bbd9dc84545c460d52c831a7a7fc6b6 Mon Sep 17 00:00:00 2001 From: Sergei Vorobev Date: Tue, 19 Apr 2016 16:39:06 -0700 Subject: [PATCH 4/5] Fix log message in Start-PSBuild --- PowerShellGitHubDev.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShellGitHubDev.psm1 b/PowerShellGitHubDev.psm1 index c77a72e14f..7853ac77fc 100644 --- a/PowerShellGitHubDev.psm1 +++ b/PowerShellGitHubDev.psm1 @@ -173,8 +173,8 @@ function Start-PSBuild { try { # Relative paths do not work well if cwd is not changed to project - log "Run `dotnet build $Arguments` from $pwd" Push-Location $Options.Top + log "Run dotnet $Arguments from $pwd" dotnet $Arguments log "PowerShell output: $($Options.Output)" } finally { From 33c458459cfbb5beb89587130b10cea52056ac93 Mon Sep 17 00:00:00 2001 From: Sergei Vorobev Date: Tue, 19 Apr 2016 16:59:03 -0700 Subject: [PATCH 5/5] Wrap all native commands in helper function in PowerShellGitHubDev.psm1 --- PowerShellGitHubDev.psm1 | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/PowerShellGitHubDev.psm1 b/PowerShellGitHubDev.psm1 index 7853ac77fc..efaefad038 100644 --- a/PowerShellGitHubDev.psm1 +++ b/PowerShellGitHubDev.psm1 @@ -125,7 +125,7 @@ function Start-PSBuild { $RestoreArguments += "$PSScriptRoot" - dotnet restore $RestoreArguments + Start-NativeExecution { dotnet restore $RestoreArguments } } # Build native components @@ -164,7 +164,7 @@ function Start-PSBuild { cmake . } - msbuild powershell.vcxproj /p:Configuration=$msbuildConfiguration + Start-NativeExecution { msbuild powershell.vcxproj /p:Configuration=$msbuildConfiguration } } finally { Pop-Location @@ -175,7 +175,7 @@ function Start-PSBuild { # Relative paths do not work well if cwd is not changed to project Push-Location $Options.Top log "Run dotnet $Arguments from $pwd" - dotnet $Arguments + Start-NativeExecution { dotnet $Arguments } log "PowerShell output: $($Options.Output)" } finally { Pop-Location @@ -321,9 +321,9 @@ function Start-PSxUnit { $Arguments = "--configuration", "Linux" try { Push-Location $PSScriptRoot/test/csharp - dotnet build $Arguments + Start-NativeExecution { dotnet build $Arguments } Copy-Item -ErrorAction SilentlyContinue -Recurse -Path $Content/* -Include Modules,libpsl-native* -Destination "./bin/Linux/netstandardapp1.5/ubuntu.14.04-x64" - dotnet test $Arguments + Start-NativeExecution { dotnet test $Arguments } if ($LASTEXITCODE -ne 0) { throw "$LASTEXITCODE xUnit tests failed" } @@ -758,6 +758,27 @@ function script:Convert-PSObjectToHashtable { } } +# this function wraps native command Execution +# for more information, read https://mnaoumov.wordpress.com/2015/01/11/execution-of-external-commands-in-powershell-done-right/ +function script:Start-NativeExecution([scriptblock]$sb) +{ + $backupEAP = $script:ErrorActionPreference + $script:ErrorActionPreference = "Continue" + try + { + & $sb + # note, if $sb doens't have a native invokation, $LASTEXITCODE will + # point to the obsolete value + if ($LASTEXITCODE -ne 0) + { + throw "Execution failed with exit code $LASTEXITCODE" + } + } + finally + { + $script:ErrorActionPreference = $backupEAP + } +} function script:Get-StronglyTypeCsFileForResx {