1
+ <#
2
+
3
+ . SYNOPSIS
4
+ Invokes dotnet build on the samples sln and project files.
5
+
6
+ . DESCRIPTION
7
+ Invokes dotnet build on the samples sln and project files.
8
+
9
+ . PARAMETER RepoRootDir
10
+ The directory of the repository files on the local machine.
11
+
12
+ . PARAMETER PullRequest
13
+ The pull requst to process. If 0 or not passed, processes the whole repo
14
+
15
+ . PARAMETER RepoOwner
16
+ The name of the repository owner.
17
+
18
+ . PARAMETER RepoName
19
+ The name of the repository.
20
+
21
+ . PARAMETER RangeStart
22
+ A range of results to process.
23
+
24
+ . PARAMETER RangeEnd
25
+ A range of results to process.
26
+
27
+ . INPUTS
28
+ None
29
+
30
+ . OUTPUTS
31
+ None
32
+
33
+ . NOTES
34
+ Version: 1.1
35
+
36
+ Creation Date: 06/17/2020
37
+ Purpose/Change: Update to GitHub actions and new framework.
38
+ #>
39
+
40
+ [CmdletBinding ()]
41
+ Param (
42
+ [Parameter (Mandatory = $true , ValueFromPipeline = $false )]
43
+ [System.String ] $RepoRootDir = $env: RepoRootDir ,
44
+
45
+ [Parameter (Mandatory = $false , ValueFromPipeline = $false )]
46
+ [System.Int64 ] $PullRequest = 0 ,
47
+
48
+ [Parameter (Mandatory = $false , ValueFromPipeline = $false )]
49
+ [System.String ] $RepoOwner = " " ,
50
+
51
+ [Parameter (Mandatory = $false , ValueFromPipeline = $false )]
52
+ [System.String ] $RepoName = " " ,
53
+
54
+ [Parameter (Mandatory = $false , ValueFromPipeline = $false )]
55
+ [System.Int32 ] $RangeStart = $env: rangestart ,
56
+
57
+ [Parameter (Mandatory = $false , ValueFromPipeline = $false )]
58
+ [System.Int32 ] $RangeEnd = $env: rangeend
59
+ )
60
+
61
+ $Global :statusOutput = @ ()
62
+
63
+ Write-Host " Gathering solutions and projects..."
64
+
65
+ if ($PullRequest -ne 0 ) {
66
+ Write-Host " Running `" LocateProjects `" $RepoRootDir `" --pullrequest $PullRequest --owner $RepoOwner --repo $RepoName `" "
67
+ $output = Invoke-Expression " LocateProjects `" $RepoRootDir `" --pullrequest $PullRequest --owner $RepoOwner --repo $RepoName "
68
+ }
69
+ else {
70
+ Write-Host " Running `" LocateProjects `" $RepoRootDir `" "
71
+ $output = Invoke-Expression " LocateProjects `" $RepoRootDir `" "
72
+ }
73
+
74
+ if ($LASTEXITCODE -ne 0 )
75
+ {
76
+ $output
77
+ throw " Error on running LocateProjects"
78
+ }
79
+
80
+ function New-Result ($inputFile , $projectFile , $exitcode , $outputText )
81
+ {
82
+ $info = @ {}
83
+
84
+ $info.InputFile = $inputFile
85
+ $info.ProjectFile = $projectFile
86
+ $info.ExitCode = $exitcode
87
+ $info.Output = $outputText
88
+
89
+ $object = New-Object - TypeName PSObject - Prop $info
90
+ $Global :statusOutput += $object
91
+ }
92
+
93
+ $workingSet = $output
94
+
95
+ if (($RangeStart -ne 0 ) -and ($RangeEnd -ne 0 )){
96
+ $workingSet = $output [$RangeStart .. $RangeEnd ]
97
+ }
98
+
99
+ $counter = 1
100
+ $length = $workingSet.Count
101
+ $thisExitCode = 0
102
+
103
+ $ErrorActionPreference = " Continue"
104
+
105
+ foreach ($item in $workingSet ) {
106
+ try {
107
+ Write-Host " $counter /$length :: $Item "
108
+
109
+ $data = $item.Split (' |' )
110
+
111
+ # Project found, build it
112
+ if ([int ]$data [0 ] -eq 0 ) {
113
+ $projectFile = Resolve-Path " $RepoRootDir \$ ( $data [2 ]) "
114
+ $result = Invoke-Expression " dotnet build `" $projectFile `" " | Out-String
115
+ $thisExitCode = 0
116
+
117
+ if ($LASTEXITCODE -ne 0 ) {
118
+ $thisExitCode = 4
119
+ }
120
+
121
+ New-Result $data [1 ] $projectFile $thisExitCode $result
122
+ }
123
+
124
+ # No project found
125
+ elseif ([int ]$data [0 ] -eq 1 ) {
126
+ New-Result $data [1 ] " " 1 " No project found"
127
+ $thisExitCode = 1 ;
128
+ }
129
+
130
+ # Too many projects found
131
+ elseif ([int ]$data [0 ] -eq 2 ) {
132
+ New-Result $data [1 ] $data [2 ] 2 " Too many projects found"
133
+ $thisExitCode = 2 ;
134
+ }
135
+
136
+ # Solution found, but no project
137
+ elseif ([int ]$data [0 ] -eq 3 ) {
138
+ New-Result $data [1 ] $data [2 ] 2 " Top-level solution found, but no project"
139
+ $thisExitCode = 3 ;
140
+ }
141
+ }
142
+ catch {
143
+ New-Result $data [1 ] $projectFile 1000 " ERROR: $ ( $_.Exception ) "
144
+ $thisExitCode = 4
145
+ Write-Host $_.Exception.Message - Foreground " Red"
146
+ Write-Host $_.ScriptStackTrace - Foreground " DarkGray"
147
+ }
148
+
149
+ $counter ++
150
+ }
151
+
152
+ $resultItems = $Global :statusOutput | Select-Object InputFile, ProjectFile, ExitCode, Output
153
+
154
+ # Add our output type
155
+ $typeResult = @"
156
+ public class ResultItem
157
+ {
158
+ public string ProjectFile;
159
+ public string InputFile;
160
+ public int ExitCode;
161
+ public string BuildOutput;
162
+ public MSBuildError[] Errors;
163
+ public int ErrorCount;
164
+
165
+ public class MSBuildError
166
+ {
167
+ public string Line;
168
+ public string Error;
169
+ }
170
+ }
171
+ "@
172
+ Add-Type $typeResult
173
+
174
+ $transformedItems = $resultItems | ForEach-Object { New-Object ResultItem - Property @ {
175
+ ProjectFile = $_.ProjectFile.Path ;
176
+ InputFile = $_.InputFile ;
177
+ ExitCode = $_.ExitCode ;
178
+ BuildOutput = $_.Output ;
179
+ Errors = @ ();
180
+ ErrorCount = 0 }
181
+ }
182
+
183
+ # Transform the build output to break it down into MSBuild result entries
184
+ foreach ($item in $transformedItems ) {
185
+ $list = @ ()
186
+
187
+ # No project found OR
188
+ if ($item.ExitCode -eq 0 ) {
189
+ $list += New-Object - TypeName " ResultItem+MSBuildError" - Property @ { Line = " " ; Error = $item.BuildOutput }
190
+ }
191
+ elseif ($item.ExitCode -ne 4 ) {
192
+ $list += New-Object - TypeName " ResultItem+MSBuildError" - Property @ { Line = " " ; Error = $item.BuildOutput }
193
+ $item.ErrorCount = 1
194
+ }
195
+ elseif ($item.ExitCode -ne 0 ) {
196
+ $errorInfo = $item.BuildOutput -Split [System.Environment ]::NewLine |
197
+ Select-String " : (?:Solution file error|error) ([^:]*)" | `
198
+ Select-Object Line - ExpandProperty Matches | `
199
+ Select-Object Line, Groups | `
200
+ Sort-Object Line | Get-Unique - AsString
201
+ $item.ErrorCount = $errorInfo.Count
202
+ foreach ($err in $errorInfo ) {
203
+ $list += New-Object - TypeName " ResultItem+MSBuildError" - Property @ { Line = $err.Line ; Error = $err.Groups [1 ].Value }
204
+ }
205
+ }
206
+
207
+ $item.Errors = $list
208
+
209
+ }
210
+
211
+ $transformedItems | ConvertTo-Json - Depth 3 | Out-File ' output.json'
212
+
213
+ exit 0
0 commit comments