Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-874: Build and Static Code Analysis not showing the offending file and line for submodules #366

Merged
merged 15 commits into from
Jul 3, 2024
Merged
24 changes: 15 additions & 9 deletions .github/actions/build-dotnet/Build-DotNetSolutionOrProject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $buildSwitches = ConvertTo-Array @"
"@

[array] $expectedErrorCodes = ConvertTo-Array $ExpectedCodeAnalysisErrors | ForEach-Object { $PSItem.Split(':')[0] } | Sort-Object
$noErrors = $expectedErrorCodes.Count -eq 0
$noErrorsExpected = $expectedErrorCodes.Count -eq 0

if (Test-Path src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj)
{
Expand All @@ -62,18 +62,24 @@ Write-Output "Building solution or project with ``dotnet build $SolutionOrProjec
$errorLines = New-Object 'System.Collections.Generic.List[string]'
$errorCodes = New-Object 'System.Collections.Generic.List[string]'

$errorFormat = '^(.*)\((\d+),(\d+)\): error (.*)'
dotnet build $SolutionOrProject @buildSwitches 2>&1 | ForEach-Object {
if ($PSItem -notmatch $errorFormat) { return $PSItem }
if ($noErrorsExpected)
{
dotnet build $SolutionOrProject @buildSwitches
}
else
{
$errorFormat = '^(.*)\((\d+),(\d+)\): error (.*)'
dotnet build $SolutionOrProject @buildSwitches 2>&1 | ForEach-Object {
if ($PSItem -notmatch $errorFormat) { return $PSItem }

($null, $file, $line, $column, $message) = [regex]::Match($PSItem, $errorFormat, 'Compiled').Groups.Value
($null, $file, $line, $column, $message) = [regex]::Match($PSItem, $errorFormat, 'Compiled').Groups.Value

$errorLines.Add($PSItem)
if ($message.Contains(':')) { $errorCodes.Add($message.Split(':')[0].Trim()) }
if ($noErrors) { Write-Output "::error file=$file,line=$line,col=$column::$message" }
$errorLines.Add($PSItem)
if ($message.Contains(':')) { $errorCodes.Add($message.Split(':')[0].Trim()) }
}
}

if ($noErrors -and -not $?)
if ($noErrorsExpected -and -not $?)
{
exit 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@

# Filter actions based on files in action directory.
[array]$actionFiles = $FileIncludeList | Where-Object -FilterScript {
$itemDirectory = (Get-Item $PSItem).Directory.FullName
# The try-catch is necessary to not fail on files that are changed but not in the working directory. At least
# .gitignore files are like this.
try
{
$item = Get-Item $PSItem -ErrorAction Stop
$itemDirectory = $item.Directory.FullName
}
catch
{
return $false
}

$isInGitHubDir = $itemDirectory -like '*/.github/*' -or $itemDirectory -eq '*/.github'
if (-not $isInGitHubDir)
{
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node_modules/
*.user
.pnpm-debug.log
/.editorconfig
*.binlog
Loading