[closes gh-69] Updated build to reuse last successful result if available.
This commit is contained in:
Родитель
71fbf393fa
Коммит
baaeaf8747
|
@ -2,8 +2,8 @@ Set-StrictMode -Version 2.0
|
|||
$ErrorActionPreference = 'Stop'
|
||||
$ProgressPreference = "SilentlyContinue" # https://www.amido.com/powershell-win32-error-handle-invalid-0x6/
|
||||
|
||||
# Write-Host, Write-Error and Write-Warning do not function properly in Azure
|
||||
# So this mostly uses Write-Output for now
|
||||
# This mostly uses Write-Output because it was an Azure WebJob before, and Write-Warning/etc
|
||||
# didn't work properly in WebJobs
|
||||
$BuildRoslynBranchIfModified = Resolve-Path "$PSScriptRoot\Build-RoslynBranchIfModified.ps1"
|
||||
."$PSScriptRoot\Setup-Build.ps1"
|
||||
|
||||
|
@ -37,6 +37,17 @@ function ConvertTo-Hashtable([PSCustomObject] $object) {
|
|||
return $result
|
||||
}
|
||||
|
||||
function Write-Success($object) {
|
||||
$saved = $Host.UI.RawUI.ForegroundColor
|
||||
try {
|
||||
$Host.UI.RawUI.ForegroundColor = 'Green'
|
||||
Write-Output "SUCCESS: $object"
|
||||
}
|
||||
finally {
|
||||
$Host.UI.RawUI.ForegroundColor = $saved
|
||||
}
|
||||
}
|
||||
|
||||
# Code ------
|
||||
try {
|
||||
$Host.UI.RawUI.WindowTitle = "SharpLab Build" # prevents title > 1024 char errors
|
||||
|
@ -133,6 +144,7 @@ try {
|
|||
$siteRoot = Ensure-ResolvedPath "$sitesRoot\$branchFsName"
|
||||
$branchArtifactsRoot = Ensure-ResolvedPath "$roslynArtifactsRoot\$branchFsName"
|
||||
|
||||
$branchBuildFailed = $false
|
||||
try {
|
||||
&$BuildRoslynBranchIfModified `
|
||||
-SourceRoot $repositorySourceRoot `
|
||||
|
@ -152,24 +164,6 @@ try {
|
|||
}
|
||||
Set-Content "$branchArtifactsRoot\BranchInfo.json" (ConvertTo-Json $branchInfo -Depth 100)
|
||||
}
|
||||
|
||||
Write-Output "Copying Server\Web.config to $siteRoot\Web.config..."
|
||||
Copy-Item "$sourceRoot\Server\Web.config" "$siteRoot\Web.config" -Force
|
||||
|
||||
Write-Output "Resolving and copying assemblies..."
|
||||
$resolverLogPath = "$branchArtifactsRoot\AssemblyResolver.log"
|
||||
$resolverCommand = "&""$assemblyResolver""" +
|
||||
" --source-bin ""$sourceRoot\Server\bin\Release"" " +
|
||||
" --roslyn-bin ""$branchArtifactsRoot\Binaries""" +
|
||||
" --target ""$(Ensure-ResolvedPath $siteRoot\bin)""" +
|
||||
" --target-app-config ""$siteRoot\Web.config""" +
|
||||
" >> ""$resolverLogPath"""
|
||||
$resolverCommand | Out-File $resolverLogPath -Encoding 'Unicode'
|
||||
Invoke-Expression $resolverCommand
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw New-Object BranchBuildException("AssemblyResolver failed with code $LastExitCode, see $resolverLogPath.")
|
||||
}
|
||||
Write-Output "All done, looks OK."
|
||||
}
|
||||
catch {
|
||||
$ex = $_.Exception
|
||||
|
@ -177,9 +171,43 @@ try {
|
|||
throw
|
||||
}
|
||||
|
||||
Write-Output " [WARNING] $($ex.Message)"
|
||||
$branchBuildFailed = $true
|
||||
Write-Warning "$($ex.Message)"
|
||||
Add-Content $failedListPath @("$branchFsName ($repositoryName)", $ex.Message, '')
|
||||
}
|
||||
|
||||
$branchBinariesPath = "$branchArtifactsRoot\Binaries"
|
||||
if (!(Test-Path $branchBinariesPath)) {
|
||||
Write-Warning "No binaries available, skipping further steps."
|
||||
if (!$branchBuildFailed) {
|
||||
Add-Content $failedListPath @("$branchFsName ($repositoryName)", "No binaries found under $branchBinariesPath.", '')
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Write-Output "Copying Server\Web.config to $siteRoot\Web.config..."
|
||||
Copy-Item "$sourceRoot\Server\Web.config" "$siteRoot\Web.config" -Force
|
||||
|
||||
Write-Output "Resolving and copying assemblies..."
|
||||
$resolverLogPath = "$branchArtifactsRoot\AssemblyResolver.log"
|
||||
$resolverCommand = "&""$assemblyResolver""" +
|
||||
" --source-bin ""$sourceRoot\Server\bin\Release"" " +
|
||||
" --roslyn-bin ""$branchBinariesPath""" +
|
||||
" --target ""$(Ensure-ResolvedPath $siteRoot\bin)""" +
|
||||
" --target-app-config ""$siteRoot\Web.config""" +
|
||||
" >> ""$resolverLogPath"""
|
||||
$resolverCommand | Out-File $resolverLogPath -Encoding 'Unicode'
|
||||
Invoke-Expression $resolverCommand
|
||||
if ($LastExitCode -ne 0) {
|
||||
Write-Warning "AssemblyResolver failed with code $LastExitCode, see $resolverLogPath."
|
||||
return
|
||||
}
|
||||
if (!$branchBuildFailed) {
|
||||
Write-Success "All done, looks OK."
|
||||
}
|
||||
else {
|
||||
Write-Warning "Branch build failed: using previous version."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,15 +21,18 @@ $newHash = (Invoke-Git $sourceRoot log "origin/$branchName" -n 1 --pretty=format
|
|||
if (Test-Path $hashMarkerPath) {
|
||||
$oldHash = [IO.File]::ReadAllText($hashMarkerPath)
|
||||
if ($oldHash -eq $newHash) {
|
||||
Write-Output "Branch '$branchName' is up to date."
|
||||
Write-Output "No changes since the last build."
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
[IO.File]::WriteAllText($hashMarkerPathFull, $newHash)
|
||||
|
||||
Write-Output "Resetting '$branchName'..."
|
||||
|
||||
Invoke-Git $sourceRoot checkout $branchName --force
|
||||
Invoke-Git $sourceRoot reset --hard origin/$branchName
|
||||
#Invoke-Git $sourceRoot clean --force
|
||||
if (Test-Path "$sourceRoot\Binaries") {
|
||||
Remove-Item "$sourceRoot\Binaries" -Recurse -Force
|
||||
}
|
||||
|
@ -52,21 +55,16 @@ function Build-Project(
|
|||
" $projectPath $msbuildArgs" | Out-Default
|
||||
|
||||
$projectPath = "$sourceRoot\$projectPath"
|
||||
" nuget restore" | Out-Default
|
||||
nuget restore "$projectPath" >> "$buildLogPath"
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw New-Object BranchBuildException("Build failed, see $buildLogPath", $buildLogPath)
|
||||
}
|
||||
|
||||
$msbuild = $env:MSBUILD_PATH
|
||||
" msbuild ($msbuild)" | Out-Default
|
||||
Invoke-Expression ("&`"$msbuild`" `"$projectPath`" $msbuildArgs >> `"$buildLogPath`"")
|
||||
" dotnet restore" | Out-Default
|
||||
dotnet restore "$projectPath" >> "$buildLogPath"
|
||||
" dotnet build" | Out-Default
|
||||
Invoke-Expression ("dotnet build `"$projectPath`" $msbuildArgs >> `"$buildLogPath`"")
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw New-Object BranchBuildException("Build failed, see $buildLogPath", $buildLogPath)
|
||||
}
|
||||
}
|
||||
|
||||
$standardArgs = "/nodeReuse:false /m /p:RestorePackages=false /p:Configuration=Debug /p:DelaySign=false /p:SignAssembly=false /p:NeedsFakeSign=false /p:SolutionDir=`"$sourceRoot\Src`""
|
||||
$standardArgs = "/p:RestorePackages=false /p:Configuration=Debug /p:DelaySign=false /p:SignAssembly=false /p:NeedsFakeSign=false /p:SolutionDir=`"$sourceRoot\Src`""
|
||||
Build-Project "Src\Compilers\Core\Portable\CodeAnalysis.csproj" $standardArgs
|
||||
Build-Project "Src\Compilers\CSharp\Portable\CSharpCodeAnalysis.csproj" $standardArgs
|
||||
Build-Project "src\Features\CSharp\Portable\CSharpFeatures.csproj" $standardArgs
|
||||
|
@ -84,8 +82,6 @@ robocopy "$sourceRoot\Binaries\Debug" "$artifactsRoot\Binaries\Debug" `
|
|||
/xd "runtimes" `
|
||||
/mir /np
|
||||
|
||||
[IO.File]::WriteAllText($hashMarkerPathFull, $newHash)
|
||||
|
||||
Write-Output " Build completed"
|
||||
|
||||
if ($ifBuilt) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче