[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'
|
$ErrorActionPreference = 'Stop'
|
||||||
$ProgressPreference = "SilentlyContinue" # https://www.amido.com/powershell-win32-error-handle-invalid-0x6/
|
$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
|
# This mostly uses Write-Output because it was an Azure WebJob before, and Write-Warning/etc
|
||||||
# So this mostly uses Write-Output for now
|
# didn't work properly in WebJobs
|
||||||
$BuildRoslynBranchIfModified = Resolve-Path "$PSScriptRoot\Build-RoslynBranchIfModified.ps1"
|
$BuildRoslynBranchIfModified = Resolve-Path "$PSScriptRoot\Build-RoslynBranchIfModified.ps1"
|
||||||
."$PSScriptRoot\Setup-Build.ps1"
|
."$PSScriptRoot\Setup-Build.ps1"
|
||||||
|
|
||||||
|
@ -37,6 +37,17 @@ function ConvertTo-Hashtable([PSCustomObject] $object) {
|
||||||
return $result
|
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 ------
|
# Code ------
|
||||||
try {
|
try {
|
||||||
$Host.UI.RawUI.WindowTitle = "SharpLab Build" # prevents title > 1024 char errors
|
$Host.UI.RawUI.WindowTitle = "SharpLab Build" # prevents title > 1024 char errors
|
||||||
|
@ -133,6 +144,7 @@ try {
|
||||||
$siteRoot = Ensure-ResolvedPath "$sitesRoot\$branchFsName"
|
$siteRoot = Ensure-ResolvedPath "$sitesRoot\$branchFsName"
|
||||||
$branchArtifactsRoot = Ensure-ResolvedPath "$roslynArtifactsRoot\$branchFsName"
|
$branchArtifactsRoot = Ensure-ResolvedPath "$roslynArtifactsRoot\$branchFsName"
|
||||||
|
|
||||||
|
$branchBuildFailed = $false
|
||||||
try {
|
try {
|
||||||
&$BuildRoslynBranchIfModified `
|
&$BuildRoslynBranchIfModified `
|
||||||
-SourceRoot $repositorySourceRoot `
|
-SourceRoot $repositorySourceRoot `
|
||||||
|
@ -152,24 +164,6 @@ try {
|
||||||
}
|
}
|
||||||
Set-Content "$branchArtifactsRoot\BranchInfo.json" (ConvertTo-Json $branchInfo -Depth 100)
|
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 {
|
catch {
|
||||||
$ex = $_.Exception
|
$ex = $_.Exception
|
||||||
|
@ -177,9 +171,43 @@ try {
|
||||||
throw
|
throw
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Output " [WARNING] $($ex.Message)"
|
$branchBuildFailed = $true
|
||||||
|
Write-Warning "$($ex.Message)"
|
||||||
Add-Content $failedListPath @("$branchFsName ($repositoryName)", $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) {
|
if (Test-Path $hashMarkerPath) {
|
||||||
$oldHash = [IO.File]::ReadAllText($hashMarkerPath)
|
$oldHash = [IO.File]::ReadAllText($hashMarkerPath)
|
||||||
if ($oldHash -eq $newHash) {
|
if ($oldHash -eq $newHash) {
|
||||||
Write-Output "Branch '$branchName' is up to date."
|
Write-Output "No changes since the last build."
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[IO.File]::WriteAllText($hashMarkerPathFull, $newHash)
|
||||||
|
|
||||||
Write-Output "Resetting '$branchName'..."
|
Write-Output "Resetting '$branchName'..."
|
||||||
|
|
||||||
Invoke-Git $sourceRoot checkout $branchName --force
|
Invoke-Git $sourceRoot checkout $branchName --force
|
||||||
Invoke-Git $sourceRoot reset --hard origin/$branchName
|
Invoke-Git $sourceRoot reset --hard origin/$branchName
|
||||||
|
#Invoke-Git $sourceRoot clean --force
|
||||||
if (Test-Path "$sourceRoot\Binaries") {
|
if (Test-Path "$sourceRoot\Binaries") {
|
||||||
Remove-Item "$sourceRoot\Binaries" -Recurse -Force
|
Remove-Item "$sourceRoot\Binaries" -Recurse -Force
|
||||||
}
|
}
|
||||||
|
@ -52,21 +55,16 @@ function Build-Project(
|
||||||
" $projectPath $msbuildArgs" | Out-Default
|
" $projectPath $msbuildArgs" | Out-Default
|
||||||
|
|
||||||
$projectPath = "$sourceRoot\$projectPath"
|
$projectPath = "$sourceRoot\$projectPath"
|
||||||
" nuget restore" | Out-Default
|
" dotnet restore" | Out-Default
|
||||||
nuget restore "$projectPath" >> "$buildLogPath"
|
dotnet restore "$projectPath" >> "$buildLogPath"
|
||||||
if ($LastExitCode -ne 0) {
|
" dotnet build" | Out-Default
|
||||||
throw New-Object BranchBuildException("Build failed, see $buildLogPath", $buildLogPath)
|
Invoke-Expression ("dotnet build `"$projectPath`" $msbuildArgs >> `"$buildLogPath`"")
|
||||||
}
|
|
||||||
|
|
||||||
$msbuild = $env:MSBUILD_PATH
|
|
||||||
" msbuild ($msbuild)" | Out-Default
|
|
||||||
Invoke-Expression ("&`"$msbuild`" `"$projectPath`" $msbuildArgs >> `"$buildLogPath`"")
|
|
||||||
if ($LastExitCode -ne 0) {
|
if ($LastExitCode -ne 0) {
|
||||||
throw New-Object BranchBuildException("Build failed, see $buildLogPath", $buildLogPath)
|
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\Core\Portable\CodeAnalysis.csproj" $standardArgs
|
||||||
Build-Project "Src\Compilers\CSharp\Portable\CSharpCodeAnalysis.csproj" $standardArgs
|
Build-Project "Src\Compilers\CSharp\Portable\CSharpCodeAnalysis.csproj" $standardArgs
|
||||||
Build-Project "src\Features\CSharp\Portable\CSharpFeatures.csproj" $standardArgs
|
Build-Project "src\Features\CSharp\Portable\CSharpFeatures.csproj" $standardArgs
|
||||||
|
@ -84,8 +82,6 @@ robocopy "$sourceRoot\Binaries\Debug" "$artifactsRoot\Binaries\Debug" `
|
||||||
/xd "runtimes" `
|
/xd "runtimes" `
|
||||||
/mir /np
|
/mir /np
|
||||||
|
|
||||||
[IO.File]::WriteAllText($hashMarkerPathFull, $newHash)
|
|
||||||
|
|
||||||
Write-Output " Build completed"
|
Write-Output " Build completed"
|
||||||
|
|
||||||
if ($ifBuilt) {
|
if ($ifBuilt) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче