Skip to content

Commit

Permalink
Add fail fast on build failures of TestPlatform.sln (microsoft#1243)
Browse files Browse the repository at this point in the history
* Add fail fast on build failures of TestPlatform.sln

* Move exit code check to Set-ScriptFailed-OnError

* Rename function name to PS naming standard
  • Loading branch information
smadala authored and codito committed Nov 2, 2017
1 parent e170a89 commit 4df8775
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ function Restore-Package
& $dotnetExe restore $env:TP_ROOT_DIR\src\package\external\external.csproj --packages $env:TP_PACKAGES_DIR -v:minimal -warnaserror -p:Version=$TPB_Version
Write-Log ".. .. Restore-Package: Complete."

if ($lastExitCode -ne 0) {
Set-ScriptFailed
}
Set-ScriptFailedOnError

Write-Log "Restore-Package: Complete. {$(Get-ElapsedTime($timer))}"
}
Expand All @@ -190,14 +188,14 @@ function Invoke-Build
& $dotnetExe build $TPB_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild
Write-Log ".. .. Build: Complete."

Set-ScriptFailedOnError

Write-Log ".. .. Build: Source: $TPB_TestAssets_Solution"
Write-Verbose "$dotnetExe build $TPB_TestAssets_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild"
& $dotnetExe build $TPB_TestAssets_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild
Write-Log ".. .. Build: Complete."

if ($lastExitCode -ne 0) {
Set-ScriptFailed
}
Set-ScriptFailedOnError

Write-Log "Invoke-Build: Complete. {$(Get-ElapsedTime($timer))}"
}
Expand Down Expand Up @@ -252,15 +250,15 @@ function Publish-Package
New-Item -ItemType directory -Path $fullDestDir -Force | Out-Null
Copy-Item $testhostFullPackageDir\* $fullDestDir -Force -recurse

Set-ScriptFailedOnError

# Copy over the Full CLR built datacollector package assemblies to the Core CLR package folder along with testhost
Publish-PackageInternal $dataCollectorProject $TPB_TargetFramework $fullDestDir

New-Item -ItemType directory -Path $fullCLRPackageDir -Force | Out-Null
Copy-Item $testhostFullPackageDir\* $fullCLRPackageDir -Force -recurse

if ($lastExitCode -ne 0) {
Set-ScriptFailed
}
Set-ScriptFailedOnError

# Publish platform abstractions
$platformAbstraction = Join-Path $env:TP_ROOT_DIR "src\Microsoft.TestPlatform.PlatformAbstractions\bin\$TPB_Configuration"
Expand Down Expand Up @@ -378,6 +376,8 @@ function Publish-PackageInternal($packagename, $framework, $output)
{
Write-Verbose "$dotnetExe publish $packagename --configuration $TPB_Configuration --framework $framework --output $output -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild"
& $dotnetExe publish $packagename --configuration $TPB_Configuration --framework $framework --output $output -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild

Set-ScriptFailedOnError
}

function Copy-Loc-Files($sourceDir, $destinationDir, $dllName)
Expand Down Expand Up @@ -553,9 +553,7 @@ function Update-LocalizedResources
Write-Verbose "& $dotnetExe msbuild $localizationProject -m -nologo -v:minimal -t:Localize -p:LocalizeResources=true"
& $dotnetExe msbuild $localizationProject -m -nologo -v:minimal -t:Localize -p:LocalizeResources=true

if ($lastExitCode -ne 0) {
Set-ScriptFailed
}
Set-ScriptFailedOnError

Write-Log ".. Update-LocalizedResources: Complete. {$(Get-ElapsedTime($timer))}"
}
Expand Down Expand Up @@ -604,8 +602,12 @@ function Get-ElapsedTime([System.Diagnostics.Stopwatch] $timer)
return $timer.Elapsed
}

function Set-ScriptFailed
function Set-ScriptFailedOnError
{
if ($lastExitCode -eq 0) {
return
}

if ($FailFast -eq $true) {
Write-Error "Build failed. Stopping as fail fast is set."
}
Expand Down

0 comments on commit 4df8775

Please sign in to comment.