|
| 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 | +} |
0 commit comments