Skip to content

Commit 89c43d8

Browse files
IEvangelistThraka
andauthored
Workflow test (#18889)
* Create blank.yml * Rename blank.yml to build-validation.yml * Create nothing.txt * add dotnetdocstools.locateprojects.nupkg * Delete nothing.txt * Update build-validation.yml * Update build-validation.yml * Update build-validation.yml * add global tool install * Change paths; add actions * Update build-validation.yml * Add files via upload * Add files via upload * Add files via upload * Update build-validation.yml * Add files via upload * Update build-validation.yml * Update build-validation.yml * Update build-validation.yml * Add files via upload * Update build-validation.yml * Add files via upload * Update build-validation.yml * Add files via upload * Add files via upload * Update build-validation.yml * Update build-validation.yml * Add files via upload * Add files via upload * Add files via upload * Update MainWindow.xaml * Update MainWindow.xaml * Add files via upload * Add files via upload * Add files via upload * Add files via upload * Add files via upload * Delete DotnetDocsTools.LocateProjects.1.0.0.nupkg * Delete DotnetDocsTools.LocateProjects.1.0.1.nupkg * Update build-validation.yml Co-authored-by: Andy De George <[email protected]>
1 parent d103889 commit 89c43d8

File tree

4 files changed

+323
-0
lines changed

4 files changed

+323
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# This is a basic workflow to help you get started with Actions
2+
name: Snippets 5000
3+
4+
# Controls when the action will run. Triggers the workflow on push or pull request
5+
# events but only for the master branch
6+
on:
7+
pull_request:
8+
paths:
9+
- "**.cs"
10+
- "**.vb"
11+
- "**.fs"
12+
- "**.cpp"
13+
- "**.h"
14+
- "**.xaml"
15+
- "**.razor"
16+
- "**.cshtml"
17+
- "**.vbhtml"
18+
- "**.*proj"
19+
- "**global.json"
20+
branches: [ master ]
21+
22+
env:
23+
DOTNET_VERSION: '3.1.300' # set this to the dot net version to use
24+
25+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
26+
jobs:
27+
# This workflow contains a single job called "build"
28+
build:
29+
# The type of runner that the job will run on
30+
runs-on: windows-latest
31+
32+
# Steps represent a sequence of tasks that will be executed as part of the job
33+
steps:
34+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
35+
- uses: actions/checkout@v2
36+
- name: Setup .NET Core SDK
37+
uses: actions/setup-dotnet@v1
38+
with:
39+
dotnet-version: ${{ env.DOTNET_VERSION }}
40+
41+
# Install locate projs global tool
42+
- name: Install LocateProjects tool
43+
run: |
44+
dotnet tool install --global --add-source ./.github/workflows/dependencies/ DotnetDocsTools.LocateProjects
45+
46+
# Run locate projs tool
47+
- name: Locate projects for PR
48+
env:
49+
GitHubKey: ${{ secrets.GITHUB_TOKEN }}
50+
LocateExts: ".cs;.vb;.fs;.cpp;.h;.xaml;.razor;.cshtml;.vbhtml;.csproj;.fsproj;.vbproj;.sln"
51+
run: |
52+
./.github/workflows/dependencies/Get-MSBuildResults.ps1 "${{ github.workspace }}" -PullRequest ${{ github.event.number }} -RepoOwner ${{ github.repository_owner }} -RepoName ${{ github.event.repository.name }}
53+
54+
# Update build output json file
55+
- name: Upload build results
56+
uses: actions/upload-artifact@v1
57+
with:
58+
name: build
59+
path: ./output.json
60+
61+
# Return status based on json file
62+
- name: Report status
63+
run: |
64+
./.github/workflows/dependencies/Out-GithubActionStatus.ps1
65+
66+
67+
191 KB
Binary file not shown.
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
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
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<#
2+
3+
.SYNOPSIS
4+
Reads the output.json file and outputs status to GitHub Actions
5+
6+
.DESCRIPTION
7+
Reads the output.json file and outputs status to GitHub Actions
8+
9+
.INPUTS
10+
None
11+
12+
.OUTPUTS
13+
None
14+
15+
.NOTES
16+
Version: 1.0
17+
18+
Creation Date: 06/17/2020
19+
Purpose/Change: Initial release
20+
#>
21+
22+
[CmdletBinding()]
23+
Param(
24+
)
25+
26+
$json = Get-Content output.json | ConvertFrom-Json
27+
28+
$errors = $json | Where-Object ErrorCount -ne 0 | Select-Object InputFile -ExpandProperty Errors | Select-Object InputFile, Error, Line
29+
30+
if ($errors.Count -eq 0) {
31+
Write-Host "All builds passed"
32+
exit 0
33+
}
34+
35+
Write-Host "Total errors: $($errors.Count)"
36+
37+
foreach ($er in $errors) {
38+
Write-Host "::error file=$($er.InputFile)::----FILE: $($er.InputFile)"
39+
Write-Host "::error file=$($er.InputFile):: ERROR: $($er.Error)"
40+
Write-Host "::error file=$($er.InputFile):: LINE: $($er.Line)"
41+
}
42+
43+
exit 1

0 commit comments

Comments
 (0)