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-498: Additional configuration options for MSBuild-based builds #147

Merged
merged 8 commits into from
Dec 15, 2022
41 changes: 23 additions & 18 deletions .github/actions/msbuild/Build-DotNetFrameworkSolutionOrProject.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
param (
[string] $SolutionOrProject,
[string] $Verbosity,
[string] $TreatWarningsAsErrors,
[string] $EnableCodeAnalysis,
[string] $Version,
[string] $Switches)
Expand All @@ -10,26 +11,37 @@ function ConvertTo-Array([string] $rawInput)
$rawInput.Replace("`r", "").Split("`n") | ForEach-Object { $PSItem.Trim() } | Where-Object { $PSItem }
}

nuget restore $SolutionOrProject

Write-Output ".NET version number: $Version"

$commonSwitches = ConvertTo-Array @"
--verbosity:$Verbosity
-p:RunAnalyzersDuringBuild=$EnableCodeAnalysis
-p:Retries=4
-p:RetryDelayMilliseconds=1000
-p:Version=$Version
"@

if ($TreatWarningsAsErrors -eq "true")
{
$commonSwitches += ConvertTo-Array @"
--warnaserror
-p:TreatWarningsAsErrors=true
"@
}

if (Test-Path src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj)
{
Write-Output "::group::Gulp Extensions found. It needs to be explicitly built before the solution."

# These need to be different than those for msbuild.
$gulpBuildSwitches = ConvertTo-Array @"
$gulpBuildSwitches = $commonSwitches + (ConvertTo-Array @"
--configuration:Release
--nologo
--verbosity:$Verbosity
--warnaserror
--warnAsMessage:MSB3026
--consoleLoggerParameters:NoSummary
-p:TreatWarningsAsErrors=true
-p:RunAnalyzersDuringBuild=$EnableCodeAnalysis
-p:Retries=4
-p:RetryDelayMilliseconds=1000
-p:Version=$Version
"@
"@)

$startTime = [DateTime]::Now
dotnet build src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj @gulpBuildSwitches
Expand All @@ -41,18 +53,11 @@ if (Test-Path src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj

# -p:Retries and -p:RetryDelayMilliseconds are used to retry builds when they fail due to random locks.

$buildSwitches = ConvertTo-Array @"
$buildSwitches = $commonSwitches + (ConvertTo-Array @"
-p:Configuration=Release
-restore
--verbosity:$Verbosity
--warnaserror
-p:TreatWarningsAsErrors=true
-p:RunAnalyzersDuringBuild=$EnableCodeAnalysis
-p:Retries=4
-p:RetryDelayMilliseconds=1000
-p:Version=$Version
$Switches
"@
"@)

Write-Output "Building solution or project with ``msbuild $SolutionOrProject $($buildSwitches -join " ")``."

Expand Down
5 changes: 5 additions & 0 deletions .github/actions/msbuild/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
required: false
default: quiet
description: Verbosity parameter for msbuild.
treat-warnings-as-errors:
required: false
default: "true"
description: If set to "true", warnings produced during the build will be treated as errors and fail the build.
enable-code-analysis:
required: false
default: "true"
Expand Down Expand Up @@ -61,6 +65,7 @@ runs:
$allSwitches = @{
SolutionOrProject = (Get-ChildItem ${{ inputs.solution-or-project-path }}).FullName
Verbosity = "${{ inputs.verbosity }}"
TreatWarningsAsErrors = "${{ inputs.treat-warnings-as-errors }}"
EnableCodeAnalysis = "${{ inputs.enable-code-analysis }}"
Version = "${{ inputs.publish-version }}"
Switches = $givenSwitches
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/msbuild-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ on:
type: string
default: quiet
description: Verbosity parameter for msbuild.
build-treat-warnings-as-errors:
required: false
type: string
default: "true"
description: Indicates whether warnings should be treated as errors during msbuild.
build-enable-code-analysis:
required: false
type: string
Expand Down Expand Up @@ -96,6 +101,7 @@ jobs:
directory: ${{ inputs.build-directory }}
solution-or-project-path: ${{ inputs.solution-or-project-path }}
verbosity: ${{ inputs.build-verbosity }}
treat-warnings-as-errors: ${{ inputs.build-treat-warnings-as-errors }}
enable-code-analysis: ${{ inputs.build-enable-code-analysis }}

- name: Tests
Expand Down