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

CARE-265: Adding .NET Framework build features #106

Merged
merged 56 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
8be4693
Centralizing checkout
Piedone Nov 17, 2022
587941f
Pointing workflows to issue branch
Piedone Nov 17, 2022
05d3c33
Factoring out dotnet build-server shutdown call
Piedone Nov 18, 2022
1f932e9
Adding name to the checkout step so it's nicer
Piedone Nov 18, 2022
bba115f
Fixing switch name
Piedone Nov 18, 2022
68f9019
Adding msbuild action and workflow
Piedone Nov 18, 2022
bdd170b
Surfacing checkout token in action
Piedone Nov 18, 2022
de1a030
Adding checkout token support to msbuild-and-test
Piedone Nov 18, 2022
6064b73
Adding missing .NET setup
Piedone Nov 18, 2022
0d71b5f
Adding explicit build failure handling
Piedone Nov 18, 2022
a2f0edf
More helpful build failed message
Piedone Nov 18, 2022
fc05882
Unnecessary line break
Piedone Nov 18, 2022
cb05ff3
Merge remote-tracking branch 'origin/dev' into issue/CARE-265
Piedone Nov 18, 2022
472e026
Activating test execution
Piedone Nov 18, 2022
a7f63fa
Adding support for specifying the machine type
Piedone Nov 18, 2022
ae58123
Debug code
Piedone Nov 18, 2022
3f17898
Better debug code
Piedone Nov 18, 2022
11aef7a
Debug code for testing, and configuring the same properties as for th…
Piedone Nov 18, 2022
b2017aa
Missing branch references
Piedone Nov 18, 2022
d827f3b
Removing debug code
Piedone Nov 18, 2022
2eede38
Docs
Piedone Nov 20, 2022
ba97b86
Not going overboard with exit code
Piedone Nov 20, 2022
7405e25
Attempting to simplify test listing
Piedone Nov 20, 2022
f128aa8
Revert "Attempting to simplify test listing"
Piedone Nov 20, 2022
21718cb
Perhaps we do need build
Piedone Nov 20, 2022
4f3e74d
Surfacing dotnet test configuration parameter, since it needs to be D…
Piedone Nov 20, 2022
0651b33
Merge remote-tracking branch 'origin/dev' into issue/CARE-265
Piedone Nov 20, 2022
efc4194
Do we need no-build for tests indeed?
Piedone Nov 20, 2022
0001688
Better no-restore/no-build config for dotnet test
Piedone Nov 20, 2022
87922d1
Merge remote-tracking branch 'origin/dev' into issue/CARE-265
Piedone Nov 21, 2022
fe8d0da
Merge remote-tracking branch 'origin/dev' into issue/CARE-265
Piedone Nov 22, 2022
b52ca54
Removing unneeded comment
Piedone Nov 22, 2022
8abf5d1
Fixing description
Piedone Nov 22, 2022
c26b2fa
Merge remote-tracking branch 'origin/dev' into issue/CARE-265
Piedone Nov 23, 2022
58f4535
Grammar
Piedone Nov 23, 2022
e601dc0
Removing continue to nowhere
Piedone Nov 23, 2022
25c2d6f
Grammar
Piedone Nov 23, 2022
e46f593
Typo
Piedone Nov 23, 2022
0f8ac54
Renaming action parameter
Piedone Nov 23, 2022
7a51c37
Clearer variable names
Piedone Nov 23, 2022
3cbf3b1
Clearer variable names, now for real
Piedone Nov 23, 2022
bc261f7
Fixing leftover workflow name
Piedone Nov 23, 2022
b73343d
Simpler language
Piedone Nov 23, 2022
6701f15
Rename Close-DotNetBuildServers
Piedone Nov 24, 2022
29e0f32
Merge remote-tracking branch 'origin/dev' into issue/CARE-265
Piedone Nov 24, 2022
1af20ba
Merge remote-tracking branch 'origin/dev' into issue/CARE-265
Piedone Nov 24, 2022
e7c6789
Removing PowerShell aliases
Piedone Nov 24, 2022
dc201a2
Merge remote-tracking branch 'origin/dev' into issue/CARE-265
Piedone Nov 25, 2022
a48503e
Grammar
Piedone Nov 25, 2022
b41519f
More grammar
Piedone Nov 25, 2022
ec45b17
Formatting
Piedone Nov 25, 2022
511586b
Revert "Formatting"
Piedone Nov 25, 2022
381144e
Indentation without syntax error
Piedone Nov 25, 2022
98d234f
Merge remote-tracking branch 'origin/dev' into issue/CARE-265
Piedone Nov 25, 2022
dd8991c
Merge remote-tracking branch 'origin/dev' into issue/CARE-265
Piedone Nov 25, 2022
dddd35c
Reset branch specifiers to @dev
Nov 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ if ($noErrors -and !$?)
exit 1
}

# With node reuse, dotnet build spawns processes that while speed up build, they can cause dotnet test and other dotnet
# tools to randomly hang. So, here we shut down those processes for later actions.
# For details see: https://github.com/Lombiq/UI-Testing-Toolbox/issues/228.
Write-Output "Shutting down .NET build servers."
dotnet build-server shutdown
Stop-DotNetBuildServers

if ($expectedErrorCodes)
{
Expand Down
3 changes: 2 additions & 1 deletion .github/actions/build-dotnet/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ runs:
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH

- name: Setup & Detect Cache Configuration
id: detect-cache-configuration
Expand Down Expand Up @@ -125,7 +126,7 @@ runs:
'@

$switches = @{
Solution = (Get-ChildItem ${{ inputs.solution-or-project-path }}).FullName
SolutionOrProject = (Get-ChildItem ${{ inputs.solution-or-project-path }}).FullName
Verbosity = "${{ inputs.verbosity }}"
EnableCodeAnalysis = "${{ inputs.enable-code-analysis }}"
Version = "${{ inputs.publish-version }}"
Expand Down
20 changes: 20 additions & 0 deletions .github/actions/checkout/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Checkout
description: >
Runs actions/checkout. Exists only to centralize which version of the action we use. Intentionally not documented in
Actions.md since it's only meant to be for internal use.
Piedone marked this conversation as resolved.
Show resolved Hide resolved

inputs:
token:
required: false
default: ${{ github.token }}
description: >
The GitHub token to authenticate checkout. Pass in a GitHub personal access token if authenticated submodules are
used.

runs:
using: "composite"
steps:
- uses: actions/[email protected]
with:
submodules: 'recursive'
token: ${{ inputs.token }}
77 changes: 77 additions & 0 deletions .github/actions/msbuild/Build-DotNetFrameworkSolutionOrProject.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
param (
[string] $SolutionOrProject,
[string] $Verbosity,
[string] $EnableCodeAnalysis,
[string] $Version,
[string] $Switches)

function ConvertTo-Array([string] $rawInput)
{
$rawInput.Replace("`r", "").Split("`n") | ForEach-Object { $PSItem.Trim() } | Where-Object { $PSItem }
}

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

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 that of msbuild.
Piedone marked this conversation as resolved.
Show resolved Hide resolved
$gulpBuildSwitches = 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
"@
Piedone marked this conversation as resolved.
Show resolved Hide resolved
0liver marked this conversation as resolved.
Show resolved Hide resolved

$startTime = [DateTime]::Now
dotnet build src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj @gulpBuildSwitches
$endTime = [DateTime]::Now

Write-Output ("Gulp Extensions build took {0:0.###} seconds." -f ($endTime - $startTime).TotalSeconds)
Write-Output "::endgroup::"
}

# - -p:Retries and -p:RetryDelayMilliseconds are to retry builds if it fails the first time due to random locks.
Piedone marked this conversation as resolved.
Show resolved Hide resolved

$buildSwitches = 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 " ")``."

msbuild $SolutionOrProject @buildSwitches

# Without this, if the msbuild command fails with certain MSB error codes (not build errors), they still won't cause
# this script to fail.

# error MSB3644: The reference assemblies for .NETFramework,Version=v4.6.1 were not found. To resolve this, install the
# Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET
# Framework Developer Packs at https://aka.ms/msbuild/developerpacks

if ($?)
{
Write-Output "Build successful."
Stop-DotNetBuildServers
}
else
{
Write-Output "::error::Build failed. See the errors above in the build log."
exit 1
}
73 changes: 73 additions & 0 deletions .github/actions/msbuild/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: MSBuild .NET Framework Build with Static Code Analysis
description: Builds the .NET Framework solution in the given directory with static code analysis.

inputs:
directory:
required: false
default: .
description: Path to the directory where a solution file can be found.
verbosity:
required: false
default: quiet
description: Verbosity parameter for msbuild.
enable-code-analysis:
required: false
default: "true"
description: If set to "true", static code analysis is enabled during the build.
publish-version:
required: false
default: "1.${{ github.run_number }}.${{ github.run_attempt }}-${{ github.run_id }}"
description: The value given to `msbuild`'s `-Version` switch.
msbuild-switches:
required: false
default: ""
description: >
Additional command line switches given to `msbuild`. You must split these into multiple lines, even the
parameter value.
solution-or-project-path:
required: false
default: "*.sln"
description: >
The path of the solution or project file to be built. If you have exactly one .sln file in the current directory
then this can be omitted. Otherwise make sure to specify it to avoid an "MSB1008: Only one project can be
specified." error that is thrown when the `*.sln` wildcard results in multiple files. To build a project file you
must specify a path that ends with `.csproj`. An example: "./src/*Web/*.Web.csproj". The value is given to
PowerShell's `Get-ChildItem` cmdlet as-is, so grepping is still possible but a name with spaces must be escaped
separately.

runs:
using: "composite"
steps:
- name: Setup Scripts
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH

- name: Add MSBuild to PATH
# v1.1.3
uses: microsoft/setup-msbuild@34cfbaee7f672c76950673338facd8a73f637506
with:
vs-version: "[17.3,]"
0liver marked this conversation as resolved.
Show resolved Hide resolved

- name: Build and Static Code Analysis
shell: pwsh
0liver marked this conversation as resolved.
Show resolved Hide resolved
working-directory: ${{ inputs.directory }}
run: |
$givenSwitches = @'
${{ inputs.msbuild-switches }}
'@

$allSwitches = @{
SolutionOrProject = (Get-ChildItem ${{ inputs.solution-or-project-path }}).FullName
Verbosity = "${{ inputs.verbosity }}"
EnableCodeAnalysis = "${{ inputs.enable-code-analysis }}"
Version = "${{ inputs.publish-version }}"
Switches = $givenSwitches
}

$startTime = [DateTime]::Now
Build-DotNetFrameworkSolutionOrProject @allSwitches
$endTime = [DateTime]::Now

Write-Output ("Solution or project build took {0:0.###} seconds." -f ($endTime - $startTime).TotalSeconds)
9 changes: 7 additions & 2 deletions .github/actions/test-dotnet/Invoke-SolutionTests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
param ($Verbosity, $Filter)
param ($Verbosity, $Filter, $Configuration)

# Note that this script will only find tests if they were previously build in Release mode.

Expand Down Expand Up @@ -26,13 +26,18 @@ else

$Env:Lombiq_Tests_UI__BrowserConfiguration__Headless = "true"

# We assume that the solution was built in Release configuration. If the tests need to be built in Debug configuration,
# as they should, we need to first build them, but not restore. Otherwise, the Release tests are already built, so we
# don't need to build them here.
$optOut = $Configuration -eq "Debug" ? "--no-restore" : "--no-build"

$tests = dotnet sln list |
Select-Object -Skip 2 |
Select-String "\.Tests\." |
Select-String -NotMatch "Lombiq.Tests.UI.csproj" |
Select-String -NotMatch "Lombiq.Tests.csproj" |
Where-Object {
$result = dotnet test --no-restore --list-tests --verbosity $Verbosity $PSItem 2>&1 | Out-String -Width 9999
$result = dotnet test $optOut --configuration $Configuration --list-tests --verbosity $Verbosity $PSItem 2>&1 | Out-String -Width 9999
-not [string]::IsNullOrEmpty($result) -and $result.Contains("The following Tests are available")
}

Expand Down
13 changes: 12 additions & 1 deletion .github/actions/test-dotnet/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ inputs:
required: false
description: >
Filter expression for dotnet test. See: https://learn.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests.
test-configuration:
required: false
description: Value passed to the --configuration parameter of dotnet test.
default: "Debug"
ui-test-parallelism:
required: false
default: "-1"
Expand Down Expand Up @@ -54,7 +58,14 @@ runs:
- name: Run Tests
shell: pwsh
working-directory: ${{ inputs.build-directory }}
run: Invoke-SolutionTests -Verbosity ${{ inputs.test-verbosity }} -Filter "${{ inputs.test-filter }}"
run: |
$switches = @{
Verbosity = "${{ inputs.test-verbosity }}"
Filter = "${{ inputs.test-filter }}"
Configuration = "${{ inputs.test-configuration }}"
}

Invoke-SolutionTests @switches

# Note that uploading the failure dumps would fail under Windows if the path were too long, regardless of
# LongPathsEnabled, see: https://github.com/actions/upload-artifact/issues/309. To get around that we merge all
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/build-and-test-orchard-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ jobs:
- ${{ inputs.timeout-minutes }}
timeout-minutes: ${{ matrix.timeout-minutes }}
steps:
- uses: actions/[email protected]
with:
submodules: 'recursive'
- name: Checkout
uses: Lombiq/GitHub-Actions/.github/actions/checkout@issue/CARE-265

- name: Set up .NET
uses: Lombiq/GitHub-Actions/.github/actions/setup-dotnet@dev
Expand All @@ -133,7 +132,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/CARE-265
with:
directory: ${{ inputs.build-directory }}
verbosity: ${{ inputs.build-verbosity }}
Expand All @@ -153,7 +152,7 @@ jobs:
location: ${{ inputs.build-directory}}

- name: Tests
uses: Lombiq/GitHub-Actions/.github/actions/test-dotnet@dev
uses: Lombiq/GitHub-Actions/.github/actions/test-dotnet@issue/CARE-265
with:
build-directory: ${{ inputs.build-directory }}
test-verbosity: ${{ inputs.build-verbosity }}
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/build-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ jobs:
- ${{ inputs.timeout-minutes }}
timeout-minutes: ${{ matrix.timeout-minutes }}
steps:
- uses: actions/[email protected]
with:
submodules: 'recursive'
- name: Checkout
uses: Lombiq/GitHub-Actions/.github/actions/checkout@issue/CARE-265

- name: Set up .NET
uses: Lombiq/GitHub-Actions/.github/actions/setup-dotnet@dev
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/deploy-to-azure-app-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ jobs:
shell: pwsh
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- uses: actions/[email protected]
with:
submodules: 'recursive'
- name: Checkout
uses: Lombiq/GitHub-Actions/.github/actions/checkout@issue/CARE-265

- name: Set up .NET
uses: Lombiq/GitHub-Actions/.github/actions/setup-dotnet@dev
Expand Down
Loading