Skip to content

Commit 831fa32

Browse files
committed
Add GitHub Actions error parsing.
1 parent ea1ecc9 commit 831fa32

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ jobs:
1919
with:
2020
dotnet-version: 8.0.x
2121
- name: Build and test
22-
run: dotnet msbuild ./default.proj
23-
22+
shell: pwsh
23+
run: |
24+
dotnet msbuild ./default.proj
25+
./build/ConvertTo-GitHubActionsOutput.ps1 -Path ./artifacts/logs/dotnet-build-issues.log
2426
# TODO: Can we parse the build output logs to provide better warning/error feedback?
2527
# TODO: Upload to CodeCov should be part of the GitHub actions.
2628
# TODO: Upload to GitHub packages instead of MyGet in GitHub actions for master and develop.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<#
2+
.SYNOPSIS
3+
Converts an MSBuild issues log into build output for GitHub Actions.
4+
.DESCRIPTION
5+
Rather than simply failing the build and having to figure out what the error
6+
was, this script takes the output from an MSBuild execution and converts
7+
warnings/errors into GitHub Actions format for easier readability.
8+
.PARAMETER Path
9+
Path to the MSBuild issues log.
10+
.EXAMPLE
11+
ConvertTo-GitHubActionsOutput -Path ./artifacts/dotnet-build-issues.log
12+
13+
Converts the default log output into GitHub Actions format.
14+
#>
15+
[CmdletBinding(SupportsShouldProcess = $False)]
16+
Param(
17+
[Parameter(Mandatory = $True)]
18+
[string]
19+
$Path
20+
)
21+
22+
Begin {
23+
If (-not (Test-Path $Path)) {
24+
Exit 0
25+
}
26+
}
27+
28+
Process {
29+
Get-Content $Path | ForEach-Object {
30+
If ($_ -match '^(?:\s+\d+>)?([^\s].*)\((\d+|\d+,\d+|\d+,\d+,\d+,\d+)\)\s*:\s+(error|warning)\s+(\w{1,2}\d+)\s*:\s*(.*)$') {
31+
$File = $Matches[1]
32+
$Severity = $Matches[3]
33+
If ($Severity -ne 'warning') {
34+
$Severity = 'error'
35+
}
36+
$Code = $Matches[4]
37+
$Message = $Matches[5].Trim()
38+
$LineNumberData = $Matches[2]
39+
$Col = 0
40+
$LineNumber = $LineNumberData
41+
If ($LineNumberData.IndexOf(',') -ge 0) {
42+
$Col = $LineNumberData -replace '[^,]+,',''
43+
$LineNumber = $LineNumberData -replace ',[^,]+',''
44+
}
45+
46+
Write-Host "::$Severity file=$File,line=$LineNumber,col=$Col,title=$Code::$Message"
47+
}
48+
}
49+
}

default.proj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<CleanDirectory Include="$(ArtifactDirectory)" />
3737
<SourceProject Include="$(MSBuildProjectDirectory)/src/**/*.csproj" />
3838
<TestProject Include="$(MSBuildProjectDirectory)/test/**/*.csproj" />
39-
<SolutionFile Include="*.sln" />
39+
<SolutionFile Include="Autofac.sln" />
4040
</ItemGroup>
4141
<Target Name="All">
4242
<Message Text="****************************************" Importance="high" />
@@ -59,7 +59,7 @@
5959
</Target>
6060
<Target Name="Compile">
6161
<Exec Command="dotnet --info" />
62-
<Exec Command="dotnet build &quot;%(SolutionFile.FullPath)&quot; -c $(Configuration) /p:Version=$(Version) -flp:v=q -flp:logfile=$(LogDirectory)/dotnet-buildissues.log" />
62+
<Exec Command="dotnet build &quot;%(SolutionFile.FullPath)&quot; -c $(Configuration) /p:Version=$(Version) -flp:v=q -flp:logfile=$(LogDirectory)/dotnet-build-issues.log" />
6363
</Target>
6464
<Target Name="Package">
6565
<MakeDir Directories="$([System.IO.Path]::Combine($(PackageDirectory),%(PublishProject.Filename)))" />

0 commit comments

Comments
 (0)