-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add build script * Cleanup * Update build script backup artifacts * Consolidate dependency * Consolidate dependency
- Loading branch information
Showing
4 changed files
with
234 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $false, Position = 0)] | ||
[string] $PublishRoot, | ||
[string[]] $NugetSources, | ||
[string] $Artifacts, | ||
[string] $Coverage | ||
) | ||
|
||
$root = Split-Path $MyInvocation.MyCommand.Path -Parent -Resolve | ||
. $root/buildHelper.ps1 | ||
|
||
if (!$Artifacts) { | ||
$Artifacts = 'artifacts' | ||
} | ||
if (!$Coverage) { | ||
$Coverage = "$Artifacts/coverage" # %cus.P_COVERAGE% | ||
} | ||
|
||
StartBuildSaveLocation | ||
|
||
# blockOpened 'git-clean' 'git clean' | ||
# git clean -xdf -e .vs -e NuGet.Config | ||
# if (!$?) { FailBuild 'git clean' } | ||
# blockClosed 'git-clean' | ||
|
||
blockOpened 'dotnet-tool-restore' 'dotnet tool restore' | ||
if ($NugetSources) { | ||
$params = @() | ||
foreach ($NugetSource in $NugetSources) { | ||
$params += @('--add-source', $NugetSource) | ||
} | ||
dotnet tool restore @params || FailBuild 'dotnet tool restore' | ||
} | ||
else { | ||
dotnet tool restore | ||
if (!$?) { FailBuild 'dotnet tool restore' } | ||
} | ||
blockClosed 'dotnet-tool-restore' | ||
|
||
blockOpened 'dotnet-restore' 'dotnet restore' | ||
if ($NugetSources) { | ||
$params = @() | ||
foreach ($NugetSource in $NugetSources) { | ||
$params += @('--source', $NugetSource) | ||
} | ||
dotnet restore @params || FailBuild 'dotnet restore' | ||
} | ||
else { | ||
dotnet restore || FailBuild 'dotnet restore' | ||
} | ||
blockClosed 'dotnet-restore' | ||
|
||
blockOpened 'dotnet-build' 'dotnet build' | ||
dotnet build -c Release --no-restore -nodereuse:false || FailBuild 'dotnet build' | ||
blockClosed 'dotnet-build' | ||
|
||
if (!$PublishRoot) { | ||
$PublishRoot = $Artifacts | ||
Write-Host "Set publishRoot: $PublishRoot" | ||
} | ||
|
||
foreach ($targetVersionNum in @("6.0", "7.0", "8.0", "9.0")) { | ||
$path = "$publishRoot/$targetVersionNum" | ||
$targetVersion = if ($targetVersionNum -eq '3.1') { 'netcoreapp3.1' } else { "net$targetVersionNum" } | ||
|
||
$tempArtifactsPath = "$publishRoot/$targetVersionNum-temp-Artifacts" | ||
$linuxWebAppPath = "$path/spa-host/WebApp" | ||
if (Test-Path $linuxWebAppPath -PathType Leaf -ErrorAction SilentlyContinue) { | ||
DropFolderRetry $tempArtifactsPath -Retry 3 | ||
$tempArtifactFolder = New-Item -Path $tempArtifactsPath -ItemType 'Directory' -ErrorAction Stop | ||
Move-Item -Path $linuxWebAppPath -Destination $tempArtifactFolder | ||
} | ||
|
||
DropFolderRetry $path -Retry 3 | ||
|
||
blockOpened ".NET-$targetVersionNum" ".NET $targetVersionNum" | ||
|
||
blockOpened 'dotnet-publish-src\WebApp' 'dotnet publish src\WebApp' | ||
dotnet publish src\WebApp -f $targetVersion -c Release --no-build -o $path/spa-host | ||
if (!$?) { FailBuild 'dotnet publish src\WebApp' } | ||
blockClosed 'dotnet-publish-src\WebApp' | ||
|
||
if (Test-Path $tempArtifactsPath -PathType Container -ErrorAction SilentlyContinue) { | ||
Move-Item -Path $tempArtifactsPath/* -Destination $path/spa-host -Force | ||
DropFolderRetry $tempArtifactsPath -Retry 3 | ||
} | ||
|
||
Write-Host "##teamcity[setParameter name='cus.tfmNet$($targetVersionNum)' value='true']" | ||
blockClosed ".NET-$targetVersionNum" | ||
} | ||
|
||
FinishBuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
function CopyCoverage([string]$source, [string]$coveragePath) { | ||
$coverlet = (Get-ChildItem -Path $source) | ||
if ($coverlet -isnot [System.IO.DirectoryInfo]) { | ||
Write-Error "Cannot file testResult inside $source" -ErrorAction Stop | ||
} | ||
|
||
if (!(Test-Path -Path $coveragePath -Type Container)) { | ||
$coverage = New-Item -Path $coveragePath -Type Directory | ||
Write-Verbose $coverage | ||
} | ||
|
||
Copy-Item -Path "$($coverlet.FullName)/*" -Destination $coveragePath -Force -Confirm:$false -ErrorAction Stop | ||
} | ||
|
||
function DropFolderRetry([string] $folder, [int] $Retry) { | ||
for ($i = $Retry; $i -ge 1; $i--) { | ||
if ($folder -and (Test-Path $folder -ErrorAction SilentlyContinue)) { | ||
Write-Verbose "Drop Folder/Remove-Item $folder / $i" | ||
if ($i -gt 1) { | ||
Remove-Item -Path $folder -Recurse -Force -Confirm:$false -ErrorAction Ignore | ||
} | ||
else { | ||
Remove-Item -Path $folder -Recurse -Force -Confirm:$false -ErrorAction Stop | ||
} | ||
} | ||
if (!$folder -or !(Test-Path $folder -ErrorAction SilentlyContinue)) { | ||
break | ||
} | ||
Write-Verbose 'Remove-Item failed, sleep for 1 second' | ||
Start-Sleep -Seconds 1 | ||
} | ||
} | ||
|
||
function TouchFile { | ||
Param( | ||
[Parameter(Mandatory = $true)] | ||
[string]$Path | ||
) | ||
|
||
if (Test-Path -LiteralPath $Path) { | ||
(Get-Item -Path $Path).LastWriteTime = Get-Date | ||
} | ||
else { | ||
New-Item -Type File -Path $Path | Out-Null | ||
} | ||
} | ||
|
||
function blockOpened($block, $description) { | ||
Write-Host "##teamcity[blockOpened name='$($block)' description='$($description)']" | ||
progressMessage $description | ||
} | ||
|
||
function blockClosed($block) { | ||
Write-Host "##teamcity[blockClosed name='$($block)']" | ||
} | ||
|
||
function progressStart($message) { | ||
Write-Host "##teamcity[progressStart '$($message)']" | ||
} | ||
|
||
function progressMessage($message) { | ||
Write-Host "##teamcity[progressMessage '$($message)']" | ||
} | ||
|
||
function progressFinish($message) { | ||
Write-Host "##teamcity[progressFinish '$($message)']" | ||
} | ||
|
||
function FailBuild($subStep) { | ||
Write-Host "##teamcity[buildProblem description='$($subStep) failed.']" | ||
RestoreLocation | ||
EndBuild | ||
Write-Host "Build failed, elapsed $($_buildElapsedTime.TotalSeconds) seconds" | ||
exit 1 | ||
} | ||
|
||
function StartBuildSaveLocation { | ||
StartBuild | ||
SaveLocation | ||
} | ||
|
||
function FinishBuildRestoreLocation { | ||
RestoreLocation | ||
FinishBuild | ||
} | ||
|
||
function StartBuild { | ||
$Script:_buildStartTime = Get-Date | ||
Write-Output "Build start $_buildStartTime" | ||
} | ||
|
||
function EndBuild { | ||
$Script:_buildEndTime = Get-Date | ||
$Script:_buildElapsedTime = New-TimeSpan $_buildStartTime $_buildEndTime | ||
} | ||
|
||
function FinishBuild { | ||
EndBuild | ||
progressMessage 'Build is done!' | ||
Write-Host "Build elapsed $($_buildElapsedTime.TotalSeconds) seconds" | ||
} | ||
|
||
function SaveLocation { | ||
$Script:_buildSaveOriginDirectory = Get-Location | ||
} | ||
|
||
function RestoreLocation { | ||
if ($Script:_buildSaveOriginDirectory) { | ||
Set-Location $Script:_buildSaveOriginDirectory | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters