diff --git a/.github/actions/build-dotnet/Build-DotNetSolution.ps1 b/.github/actions/build-dotnet/Build-DotNetSolution.ps1 index 5767f88f6..cf6091db1 100644 --- a/.github/actions/build-dotnet/Build-DotNetSolution.ps1 +++ b/.github/actions/build-dotnet/Build-DotNetSolution.ps1 @@ -8,9 +8,7 @@ function ConvertTo-Array([string] $rawInput) { - $rawInput.Replace("`r", "").Split("`n") | - % { $_.Trim() } | - ? { -not [string]::IsNullOrEmpty($_) } + $rawInput.Replace("`r", "").Split("`n") | % { $_.Trim() } | ? { $_ } } Write-Output ".NET version number: $Version" @@ -50,6 +48,11 @@ if (Test-Path src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj Write-Output "::endgroup::" } +# This prepares the solution with the Lombiq.Analyzers files. The output and exit code are discarded because they will +# be in error if there is a project without the LombiqNetAnalyzers target. Then there is nothing to do, and the target +# will still run on the projects that have it. +dotnet msbuild '-target:Restore;LombiqNetAnalyzers' $Solution | Out-Null || bash -c 'true' + Write-Output "Building solution with ``dotnet build $Solution $($buildSwitches -join " ")``." $errorLines = New-Object "System.Collections.Generic.List[string]" @@ -72,6 +75,15 @@ if ($expectedErrorCodes) $fail = 0 $report = New-Object "System.Text.StringBuilder" "`n" + if ($null -eq $errorCodes -or -not $errorCodes.Count) + { + $expectedCount = $expectedErrorCodes.Count + $expectedCodesJoined = $expectedErrorCodes -join ', ' + + Write-Output "::error::Expected $expectedCount error codes ($expectedCodesJoined), but none were displayed." + exit 1 + } + $length = [System.Math]::Max($errorCodes.Count, $expectedErrorCodes.Count) foreach ($index in 0..($length - 1)) { diff --git a/.github/actions/publish-nuget/New-NuGetPackage.ps1 b/.github/actions/publish-nuget/New-NuGetPackage.ps1 new file mode 100644 index 000000000..5b32c35b9 --- /dev/null +++ b/.github/actions/publish-nuget/New-NuGetPackage.ps1 @@ -0,0 +1,34 @@ +<# +.SYNOPSIS + Creates a NuGet package from each project in the sln file in the current directory. +.DESCRIPTION + Uses "dotnet sln list" to get all projects in the current directory. This means the current directory must have + exactly one sln file in it. Then calls "dotnet pack" for each csproj file with the provided arguments. If there is + a nuspec file in the project's directory too, then it is used to generate the package description instead of the + regular auto-generation. +.NOTES + We go through the projects individually in a foreach loop, because the "-p:NuspecFile=" parameter can't be passed + to a solution. +.EXAMPLE + New-NugetPackage @("--configuration:Release", "--warnaserror") + Calls "dotnet pack project.csproj --configuration:Release --warnaserror" on each project. +#> + +param([array] $Arguments) + +foreach ($project in (dotnet sln list | Select-Object -Skip 2 | Get-Item)) +{ + Push-Location $project.Directory + + $nuspecFile = (Get-ChildItem *.nuspec).Name + if ($nuspecFile.Count -eq 1) + { + dotnet pack $project -p:NuspecFile="$nuspecFile" @Arguments + } + else + { + dotnet pack $project @Arguments + } + + Pop-Location +} diff --git a/.github/actions/publish-nuget/action.yml b/.github/actions/publish-nuget/action.yml index b9d6193f3..cd5a5e266 100644 --- a/.github/actions/publish-nuget/action.yml +++ b/.github/actions/publish-nuget/action.yml @@ -16,6 +16,10 @@ inputs: description: > Additional warning codes for the `-p:NoWarn=` argument of `dotnet pack`. The items can be separated by any whitespace, including newlines. + dotnet-pack-include-symbols: + required: false + default: "true" + description: If set to "true", a symbol package will be created together with the NuGet package. secrets: API_KEY: required: true @@ -55,6 +59,11 @@ runs: shell: pwsh run: dotnet restore -p:NuGetBuild=true --verbosity ${{ inputs.verbosity }} + - name: Generate nuspec file if needed + if: hashFiles('ConvertTo-Nuspec.ps1') + shell: pwsh + run: ./ConvertTo-Nuspec.ps1 '${{ steps.setup.outputs.publish-version }}' + - name: Build uses: Lombiq/GitHub-Actions/.github/actions/build-dotnet@dev # Notes on the configuration: @@ -82,6 +91,11 @@ runs: -p:DebugSymbols=true -p:DebugType=portable + - name: Actions prior to dotnet pack + if: hashFiles('Invoke-BeforePack.ps1') + shell: pwsh + run: ./Invoke-BeforePack.ps1 + - name: Pack shell: pwsh # Notes on the configuration apart from what's also for dotnet build: @@ -96,24 +110,24 @@ runs: ${{ inputs.dotnet-pack-ignore-warning }} '@.Split() | ? { $_ } - $arguments = @( + New-NuGetPackage @( "--configuration:Release", "--warnaserror", "--no-restore", "--no-build", - "--output:artifacts", + "--output:" + (Join-Path $PWD artifacts), "--verbosity:${{ inputs.verbosity }}", "-p:NuGetBuild=true", "-p:Version=${{ steps.setup.outputs.publish-version }}", + "-p:NuspecProperties=version=${{ steps.setup.outputs.publish-version }}", "-p:GenerateDocumentationFile=True", "-p:NoWarn=$($noWarn -join '%3B')", "-p:TreatWarningsAsErrors=true", "-p:WarnOnPackingNonPackableProject=True", - "-p:IncludeSymbols=true", + "-p:IncludeSymbols=${{ inputs.dotnet-pack-include-symbols }}", "-p:SymbolPackageFormat=snupkg", "-p:NoDefaultExcludes=true" ) - dotnet pack @arguments - name: Push with dotnet shell: pwsh diff --git a/.github/actions/verify-submodule-pull-request/action.yml b/.github/actions/verify-submodule-pull-request/action.yml index 807e82ac3..9bcd51500 100644 --- a/.github/actions/verify-submodule-pull-request/action.yml +++ b/.github/actions/verify-submodule-pull-request/action.yml @@ -25,10 +25,16 @@ runs: New-Item -ItemType File -Force $Profile | Out-Null Get-Content -Raw ${{ github.action_path }}/functions.ps1 >> $Profile + # We are using env for the title input in these steps because it realistically could contain quotes, apostrophes or + # even both. This way those don't need to be escaped. - name: Ensure Current PR Title Includes Issue Code shell: pwsh - run: Check-Current '${{ inputs.title }}' + env: + PR_TITLE: ${{ inputs.title }} + run: Check-Current $Env:PR_TITLE - name: Ensure Parent Repository Contains Matching PR shell: pwsh - run: Check-Parent '${{ inputs.repository }}' '${{ inputs.title }}' + env: + PR_TITLE: ${{ inputs.title }} + run: Check-Parent '${{ inputs.repository }}' $Env:PR_TITLE diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml index 653a6756c..7e0ef4f7e 100644 --- a/.github/workflows/publish-nuget.yml +++ b/.github/workflows/publish-nuget.yml @@ -30,6 +30,11 @@ on: description: > Additional warning codes for the `-p:NoWarn=` argument of `dotnet pack`. The items can be separated by any whitespace, including newlines. + dotnet-pack-include-symbols: + required: false + type: string + default: "true" + description: If set to "true", a symbol package will be created together with the NuGet package. secrets: # We can't access org secrets here so they need to be passed in, see: # https://github.community/t/resuable-called-workflow-environment-variables-secrets-and-trigger-event-access/207723/2 @@ -56,10 +61,11 @@ jobs: dotnet-version: ${{ inputs.dotnet-version }} - name: Publish to NuGet - uses: Lombiq/GitHub-Actions/.github/actions/publish-nuget@dev + uses: Lombiq/GitHub-Actions/.github/actions/publish-nuget@issue/OSOE-110 with: source: ${{ inputs.source }} verbosity: ${{ inputs.verbosity }} dotnet-pack-ignore-warning: ${{ inputs.dotnet-pack-ignore-warning }} + dotnet-pack-include-symbols: ${{ inputs.dotnet-pack-include-symbols }} env: API_KEY: ${{ secrets.API_KEY }} diff --git a/.github/workflows/test-analysis-failure.yml b/.github/workflows/test-analysis-failure.yml index 3aa8a92ae..80013cc25 100644 --- a/.github/workflows/test-analysis-failure.yml +++ b/.github/workflows/test-analysis-failure.yml @@ -87,7 +87,7 @@ jobs: uses: Lombiq/GitHub-Actions/.github/actions/enable-corepack@dev - name: Build and Static Code Analysis - uses: Lombiq/GitHub-Actions/.github/actions/build-dotnet@dev + uses: Lombiq/GitHub-Actions/.github/actions/build-dotnet@issue/OSOE-110 with: directory: ${{ inputs.build-directory }} verbosity: quiet diff --git a/.github/workflows/verify-submodule-pull-request.yml b/.github/workflows/verify-submodule-pull-request.yml index 15a5852d9..a34b915d3 100644 --- a/.github/workflows/verify-submodule-pull-request.yml +++ b/.github/workflows/verify-submodule-pull-request.yml @@ -13,6 +13,6 @@ jobs: runs-on: ubuntu-latest steps: - name: Ensure Parent PR Exists - uses: Lombiq/GitHub-Actions/.github/actions/verify-submodule-pull-request@dev + uses: Lombiq/GitHub-Actions/.github/actions/verify-submodule-pull-request@issue/OSOE-110 with: title: ${{ github.event.pull_request.title }}