Skip to content

Commit

Permalink
Merge pull request #21 from Lombiq/issue/OSOE-110
Browse files Browse the repository at this point in the history
 OSOE-110: Fix `verify` action that fails if the PR title has apostrophe in it
  • Loading branch information
0liver authored Aug 4, 2022
2 parents 17e00fd + c6c0bcd commit 76e4c89
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 12 deletions.
18 changes: 15 additions & 3 deletions .github/actions/build-dotnet/Build-DotNetSolution.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]"
Expand All @@ -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))
{
Expand Down
34 changes: 34 additions & 0 deletions .github/actions/publish-nuget/New-NuGetPackage.ps1
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 18 additions & 4 deletions .github/actions/publish-nuget/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions .github/actions/verify-submodule-pull-request/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.521000.bestmunity/t/resuable-called-workflow-environment-variables-secrets-and-trigger-event-access/207723/2
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/test-analysis-failure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify-submodule-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

0 comments on commit 76e4c89

Please sign in to comment.