Skip to content

Commit

Permalink
Fix net8.0-windows tests trying to run on Linux
Browse files Browse the repository at this point in the history
This also enforces which target frameworks are permitted for test projects to avoid mistakes that would cause tests to be silently skipped on CI.
  • Loading branch information
PathogenDavid committed Aug 7, 2024
1 parent 76b9d9d commit cf0f86a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/Bonsai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
release_version: ${{github.event.release.tag_name}}
workflow_dispatch_version: ${{github.event.inputs.version}}
workflow_dispatch_will_publish_packages: ${{github.event.inputs.will_publish_packages}}

# ----------------------------------------------------------------------- Build
- name: Restore
run: dotnet restore Bonsai.sln
Expand All @@ -122,9 +122,15 @@ jobs:
run: dotnet pack Bonsai.sln --no-restore --no-build --configuration ${{matrix.configuration}}

# ----------------------------------------------------------------------- Test
- name: Test
- name: Test .NET Framework 4.7.2
if: '!matrix.dummy-build'
run: dotnet test Bonsai.sln --no-restore --no-build --configuration ${{matrix.configuration}} --verbosity normal --framework net472
- name: Test .NET 8
if: '!matrix.dummy-build'
run: dotnet test Bonsai.sln --no-restore --no-build --configuration ${{matrix.configuration}} --verbosity normal
run: dotnet test Bonsai.sln --no-restore --no-build --configuration ${{matrix.configuration}} --verbosity normal --framework net8.0
- name: Test .NET 8 Windows
if: ${{!matrix.dummy-build && matrix.platform.rid == 'win-x64'}}
run: dotnet test Bonsai.sln --no-restore --no-build --configuration ${{matrix.configuration}} --verbosity normal --framework net8.0-windows

# ----------------------------------------------------------------------- Create portable zip
- name: Create portable zip
Expand Down Expand Up @@ -153,7 +159,7 @@ jobs:
id: create-installer
if: matrix.create-installer
run: msbuild /nologo /maxCpuCount Bonsai.Setup.sln /p:Configuration=${{matrix.configuration}}

# ----------------------------------------------------------------------- Collect artifacts
- name: Collect NuGet packages
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -412,7 +418,7 @@ jobs:
env:
version_file_path: tooling/CurrentVersion.props
just_released_version: ${{github.event.release.tag_name}}

# ----------------------------------------------------------------------- Commit and push changes
- name: Commit changes
if: steps.main-revision.outputs.sha == github.sha
Expand Down
2 changes: 0 additions & 2 deletions Bonsai.Core.Tests/Bonsai.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions Bonsai.Editor.Tests/Bonsai.Editor.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFrameworks>net472;net8.0-windows</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions Bonsai.System.Tests/Bonsai.System.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
Expand Down
24 changes: 24 additions & 0 deletions tooling/Common.Tests.csproj.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project>
<PropertyGroup>
<!-- Common test properties -->
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>
<Target Name="VerifyTestTargetFramework" BeforeTargets="Build" Condition="'$(TargetFramework)' != ''">
<ItemGroup>
<!--
Due to limitations in `dotnet test`, tests must only target specific target frameworks which are explicitly ran by CI.
Do not add any target frameworks to this list without also updating the CI workflow.
-->
<_PermittedTestFramework Remove="*" />
<_PermittedTestFramework Include="net472" />
<_PermittedTestFramework Include="net8.0" />
<_PermittedTestFramework Include="net8.0-windows" />
</ItemGroup>
<PropertyGroup>
<_IsPermittedTestFramework>false</_IsPermittedTestFramework>
<_IsPermittedTestFramework Condition="'%(_PermittedTestFramework.Identity)' == '$(TargetFramework)'">true</_IsPermittedTestFramework>
</PropertyGroup>
<Error Condition="'$(_IsPermittedTestFramework)' != 'true'" Text="Test project targets '$(TargetFramework)', which is not permitted for test projects." />
</Target>
</Project>
1 change: 1 addition & 0 deletions tooling/Common.csproj.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@
<DebugType Condition="'$(IsReferenceDummyBuild)' == 'true'">none</DebugType>
</PropertyGroup>
<Import Project="Versioning.props" />
<Import Project="Common.Tests.csproj.props" Condition="$(MSBuildProjectName.EndsWith('.Tests'))" />
</Project>

0 comments on commit cf0f86a

Please sign in to comment.