forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitbuild.ps1
130 lines (98 loc) · 3.98 KB
/
itbuild.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
## Script that iteratively builds the samples in the repository
## This script it used by the VSTS build agents.
## Author: Den Delimarsky (dendeli)
## Last Modified: 8/12/2016
## This is needed for JSON parsing
[System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
dotnet --version
$homePath = (Get-Item -Path ".\" -Verbose).FullName
$logIdentifier = [Guid]::NewGuid().ToString()
$logFile = "$homePath\$logIdentifier.buildlog"
$buildResults = @{}
Function LogWrite
{
Param ([string]$logString)
Write-Host $logString
Add-content $logFile -value $logString
}
LogWrite $homePath
## =============================================
## Global Projects
## =============================================
LogWrite "===== Bootstraping build for global projects... ====="
$Content = Get-Content "$homePath\global.projects" | Foreach-Object {
if ($_) {
$restorePath = (Get-Item $_.ToString().Trim()).Directory.ToString()
$restoreFileName = $_.ToString().Trim()
LogWrite "Bootstraping restore on $restorePath..."
$rawJson = Get-Content $restoreFileName
LogWrite "Getting information for $restoreFileName..."
$ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer
$globalObject = $ser.DeserializeObject($rawJson)
$projects = $globalObject.projects
LogWrite "Ready to work on restore for $restoreFileName. Executing command..."
Write-Host $restorePath
cd $restorePath
dotnet restore | Write-Host
$buildResults.Add(([GUID]::NewGuid()).GUID, $LastExitCode)
LogWrite "Restore complete."
foreach($project in $projects)
{
$comboPath = Join-Path $restorePath $project
$singleProjectContainer = Get-ChildItem $comboPath -Recurse | where {$_.Name -eq "project.json" }
if ($singleProjectContainer -is [System.IO.FileInfo])
{
$projectPath = Split-Path -parent $singleProjectContainer.FullName
cd $projectPath
dotnet build | Write-Host
$buildResults.Add(([GUID]::NewGuid()).GUID, $LastExitCode)
}
else
{
foreach($sProject in $singleProjects)
{
cd $projectPath
dotnet build | Write-Host
$buildResults.Add(([GUID]::NewGuid()).GUID, $LastExitCode)
}
}
}
}
}
$resultsCount = $buildResults.Count
LogWrite "Total samples built by now: $resultsCount"
LogWrite "===== Building of global projects is complete. ====="
## =============================================
## Single Projects
## =============================================
LogWrite "===== Bootstraping build for single projects... ====="
$Content = Get-Content "$homePath\single.projects" | Foreach-Object {
if ($_) {
$projectPath = (Get-Item $_.ToString().Trim()).Directory.ToString()
LogWrite "Working on $projectPath..."
cd $projectPath
dotnet restore | Write-Host
$buildResults.Add(([GUID]::NewGuid()).GUID, $LastExitCode)
dotnet build | Write-Host
$buildResults.Add(([GUID]::NewGuid()).GUID, $LastExitCode)
}
}
$resultsCount = $buildResults.Count
LogWrite "Commands triggered that can result in errors: $resultsCount"
LogWrite "===== Building of single projects is complete. ====="
## Obviously the color does nothing when this shows up in the VSTS console.
LogWrite ($buildResults | Out-String) -ForegroundColor Yellow
$brutalFailures = @($buildResults.GetEnumerator())| where {$_.Value -eq 1}
$numberOfBrutalFailures = $brutalFailures.Count
LogWrite "Number of brutal failures in this build: $numberOfBrutalFailures"
## Check if we have any breaking errors - currently warnings are ignored as those do
## not impede the overall sample performance. Those are still logged.
if ($numberOfBrutalFailures -gt 0)
{
LogWrite "Build failed. See log for details."
exit 1
}
else
{
exit 0
}