Skip to content

Commit

Permalink
Run the Basic ContentBuilder Tests on CI
Browse files Browse the repository at this point in the history
We are currently not running ANY tests on CI.
Lets correct this by running at least the content building and
processor tests on CI.

Certain content pipelines tests (Audio & Effects) have
been disabled because they fail or hang on CI at this time.

Current the tests run in x64 dotnet so that we can pass the
TextureCompression tests.
This PR MonoGame#8456 should fix the texture compression issues so we do not
need x64 dotnet.

The Effect compilation for Linux /Mac needs to happen
in wine. But dotnet 8 does not seem to run under wine on CI at this
time. So that will need to be looked at.
  • Loading branch information
dellis1972 committed Aug 27, 2024
1 parent eeb3893 commit bd87586
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 88 deletions.
84 changes: 81 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,102 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'microsoft'
java-version: '11'
java-version: '17'

- name: Disable annotations
run: echo "::remove-matcher owner=csc::"

- name: install wine64 on linux
run: |
sudo apt install p7zip-full curl
sudo dpkg --add-architecture i386
sudo mkdir -pm755 /etc/apt/keyrings
sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources
sudo apt update && sudo apt install --install-recommends winehq-stable
if: runner.os == 'Linux'

- name: Install Arial Font
run: |
echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | sudo debconf-set-selections
sudo apt install -y ttf-mscorefonts-installer
sudo fc-cache
fc-match Arial
if: runner.os == 'Linux'

- name: install wine64 on macos
run: brew install wine-stable p7zip
if: runner.os == 'macOS'

- name: Setup Wine
run: wget -qO- https://monogame.net/downloads/net8_mgfxc_wine_setup.sh | bash
if: runner.os != 'Windows'

# Not working yet they crash
# - name: Test Wine
# run: wine64 dotnet --info
# env:
# WINEPREFIX: /home/runner/.winemonogame
# if: runner.os == 'Linux'

# Not working yet they crash
# - name: Test Wine
# run: wine64 dotnet --info
# env:
# WINEPREFIX: /Users/runner/.winemonogame
# if: runner.os == 'macOS'

- name: Download dotnet-install.sh
run: |
wget https://dot.net/v1/dotnet-install.sh
chmod u+x dotnet-install.sh
ls -la
working-directory: ${{github.workspace}}
if: runner.os != 'Windows'

- name: Install x64 dotnet
run: ${{github.workspace}}/dotnet-install.sh --architecture x64 --install-dir ${{github.workspace}}/dotnet64 --version latest
working-directory: ${{github.workspace}}
if: runner.os != 'Windows'

- name: Install required workloads
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
echo "MICROSOFT SUPPORT ANDROID WORKLOAD ON LINUX PLZZZ!"
dotnet workload install android
${{github.workspace}}/dotnet64/dotnet workload install android
elif [ "$RUNNER_OS" == "Windows" ]; then
dotnet.exe workload install android ios macos
else
dotnet workload install android ios macos
dotnet workload install android
${{github.workspace}}/dotnet64/dotnet workload install android ios macos
fi
shell: bash

- name: Build
run: ${{github.workspace}}/dotnet64/dotnet run --project build/Build.csproj -- --target=Default
if: runner.os != 'Windows'

- name: Build
run: dotnet run --project build/Build.csproj -- --target=Default
if: runner.os == 'Windows'

- name: Test
run: ${{github.workspace}}/dotnet64/dotnet test Tools/MonoGame.Tools.Tests/MonoGame.Tools.Tests.csproj --blame-hang-timeout 1m -c Release
env:
DOTNET_ROOT: ${{github.workspace}}/dotnet64
MGFXC_WINE_PATH: /home/runner/.winemonogame
if: runner.os == 'Linux'

- name: Test
run: ${{github.workspace}}/dotnet64/dotnet test Tools/MonoGame.Tools.Tests/MonoGame.Tools.Tests.csproj --blame-hang-timeout 1m -c Release
env:
DOTNET_ROOT: ${{github.workspace}}/dotnet64
MGFXC_WINE_PATH: /Users/runner/.winemonogame
if: runner.os == 'macOS'

- name: Test
run: dotnet test Tools/MonoGame.Tools.Tests/MonoGame.Tools.Tests.csproj --blame-hang-timeout 1m -c Release
if: runner.os == 'Windows'

- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v3
Expand Down
50 changes: 8 additions & 42 deletions Tests/Assets/Projects/BuildSimpleProject.csproj
Original file line number Diff line number Diff line change
@@ -1,50 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\..\..\Tools\MonoGame.Content.Builder.Task\MonoGame.Content.Builder.Task.props" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{1A3C19CC-557D-4009-82D6-92B511EA4172}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BuildSimpleProject</RootNamespace>
<AssemblyName>BuildSimpleProject</AssemblyName>
<FileAlignment>512</FileAlignment>
<MonoGamePlatform>DesktopGL</MonoGamePlatform>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE;LINUX</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>false</Prefer32Bit>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
<DefineConstants>TRACE;LINUX</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>false</Prefer32Bit>
<WarningLevel>4</WarningLevel>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RollForward>Major</RollForward>
<IsPackable>false</IsPackable>
<MonoGamePlatform>DesktopGL</MonoGamePlatform>
</PropertyGroup>

<ItemGroup>
<Reference Include="System" />
</ItemGroup>

<ItemGroup>
<MonoGameContentReference Include="Content\Content.mgcb" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\MonoGame.Content.Builder.targets" />
<Import Project="..\..\..\..\..\..\Tools\MonoGame.Content.Builder.Task\MonoGame.Content.Builder.Task.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
<Link>%(MonoGameContentReference.Link)</Link>
<FullDir>%(MonoGameContentReference.RootDir)%(MonoGameContentReference.Directory)</FullDir>
<ContentFolder>%(MonoGameContentReference.ContentFolder)</ContentFolder>
<OutputFolder>%(MonoGameContentReference.Filename)</OutputFolder>
<OutputFolder>%(MonoGameContentReference.OutputFolder)</OutputFolder>
<OutputFolder Condition="'%(MonoGameContentReference.OutputFolder)' == '' ">%(MonoGameContentReference.Filename)</OutputFolder>
</ContentReference>

<!--
Expand Down Expand Up @@ -137,12 +138,12 @@

<!-- Remove this line if they make dotnet tool restore part of dotnet restore build -->
<!-- https://github.com/dotnet/sdk/issues/4241 -->
<Exec Command="$(DotnetCommand) tool restore" />
<Exec Command="&quot;$(DotnetCommand)&quot; tool restore" />

<!-- Execute MGCB from the project directory so we use the correct manifest. -->
<Exec
Condition="'%(ContentReference.FullPath)' != ''"
Command="$(DotnetCommand) $(MGCBCommand) $(MonoGameMGCBAdditionalArguments) /@:&quot;%(ContentReference.FullPath)&quot; /platform:$(MonoGamePlatform) /outputDir:&quot;%(ContentReference.ContentOutputDir)&quot; /intermediateDir:&quot;%(ContentReference.ContentIntermediateOutputDir)&quot; /workingDir:&quot;%(ContentReference.FullDir)&quot;"
Command="&quot;$(DotnetCommand)&quot; &quot;$(MGCBCommand)&quot; $(MonoGameMGCBAdditionalArguments) /@:&quot;%(ContentReference.FullPath)&quot; /platform:$(MonoGamePlatform) /outputDir:&quot;%(ContentReference.ContentOutputDir)&quot; /intermediateDir:&quot;%(ContentReference.ContentIntermediateOutputDir)&quot; /workingDir:&quot;%(ContentReference.FullDir)&quot;"
WorkingDirectory="$(MSBuildProjectDirectory)" />

<ItemGroup>
Expand Down
8 changes: 2 additions & 6 deletions Tools/MonoGame.Content.Builder/BuildContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,12 @@ public void Build(out int successCount, out int errorCount)
}
catch (PipelineException ex)
{
Console.Error.WriteLine("{0}: error: {1}", c.SourceFile, ex.Message);
if (ex.InnerException != null)
Console.Error.WriteLine(ex.InnerException.ToString());
Console.Error.WriteLine("{0}: error: {1}. {2}", c.SourceFile, ex.Message, ex.InnerException != null ? ex.InnerException : string.Empty);
++errorCount;
}
catch (Exception ex)
{
Console.Error.WriteLine("{0}: error: {1}", c.SourceFile, ex.Message);
if (ex.InnerException != null)
Console.Error.WriteLine(ex.InnerException.ToString());
Console.Error.WriteLine("{0}: error: {1}. {2}", c.SourceFile, ex.Message, ex.InnerException != null ? ex.InnerException : string.Empty);
++errorCount;
}
}
Expand Down
3 changes: 3 additions & 0 deletions Tools/MonoGame.Tools.Tests/AudioContentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace MonoGame.Tests.ContentPipeline
{
#if MACOS
[Ignore("Hanging on Mac in CI?")]
#endif
class AudioContentTests
{
[Test]
Expand Down
3 changes: 3 additions & 0 deletions Tools/MonoGame.Tools.Tests/BitmapContentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace MonoGame.Tests.ContentPipeline
{
#if MACOS || LINUX
[Ignore("Does not work on Unix based systems. We need to get wine working on CI.")]
#endif
class BitmapContentTests
{
// Needed to copy from an array of struct to a byte array
Expand Down
73 changes: 40 additions & 33 deletions Tools/MonoGame.Tools.Tests/BuilderTargetsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,71 @@ namespace MonoGame.Tests.ContentPipeline
[TestFixture]
public class BuilderTargetsTest
{
string[] msBuildFolders = new string[]
string FindTool (string toolName)
{
Path.Combine ("MSBuild", "15.0", "Bin", "MSBuild.exe"),
Path.Combine ("MSBuild", "14.0", "Bin", "MSBuild.exe"),
};
string FindBuildTool(string buildTool)
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT && buildTool == "msbuild")
var dotnetRoot = Environment.GetEnvironmentVariable ("DOTNET_ROOT");
TestContext.WriteLine ("DOTNET_ROOT=" + dotnetRoot);
if (!string.IsNullOrEmpty (dotnetRoot))
{
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
foreach (var path in msBuildFolders)
var dotNetExe = Path.Combine (dotnetRoot, OperatingSystem.IsWindows() ? "dotnet.exe" : "dotnet");
TestContext.WriteLine ("DOTNET_EXE=" + dotNetExe);
if (File.Exists (dotNetExe))
{
if (File.Exists(Path.Combine(programFiles, path)))
return Path.Combine(programFiles, path);
TestContext.WriteLine ("returning:" + dotNetExe);
return dotNetExe;
}
}
return buildTool;
TestContext.WriteLine ("returning:" + toolName);
return toolName;
}
bool RunBuild(string buildTool, string projectFile, params string[] parameters)
{
var root = Path.GetDirectoryName(typeof(BuilderTargetsTest).Assembly.Location);
var psi = new ProcessStartInfo(FindBuildTool(buildTool))
var tool = FindTool(buildTool);
var psi = new ProcessStartInfo(tool)
{
Arguments = projectFile + " /t:BuildContent " + string.Join(" ", parameters) + " /noconsolelogger \"/flp1:LogFile=build.log;Encoding=UTF-8;Verbosity=Diagnostic\"",
Arguments = $"build {projectFile} -t:IncludeContent {string.Join(" ", parameters)} -tl:off -bl -p:DotnetCommand=\"{tool}\"",
WorkingDirectory = root,
UseShellExecute = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
TestContext.WriteLine (psi.FileName + " " + psi.Arguments);
using (var process = Process.Start(psi))
{
process.WaitForExit();
process.OutputDataReceived += (sender, e) => {
if (!string.IsNullOrEmpty(e.Data))
{
TestContext.WriteLine($"Output: {e.Data}");
}
};

process.ErrorDataReceived += (sender, e) => {
if (!string.IsNullOrEmpty(e.Data))
{
TestContext.WriteLine($"Error: {e.Data}");
}
};
process.BeginOutputReadLine();
process.BeginErrorReadLine();
if (!process.WaitForExit(60000)) {// wait for 60 seconds
process.Kill ();
}
return process.ExitCode == 0;
}
}

static object[] BuilderTargetsBuildTools = new object[] {
"msbuild",
"xbuild",
};

[Test]
[TestCaseSource("BuilderTargetsBuildTools")]
#if DESKTOPGL
[Ignore("Fails on Mac build server with xbuild for some reason.")]
#else
[Ignore("This test need to be rewritten to properly test Tools\\MonoGame.Content.Builder instead of the old builder targets.")]
#endif
public void BuildSimpleProject(string buildTool)
public void BuildSimpleProject()
{
if (buildTool == "xbuild" && Environment.OSVersion.Platform == PlatformID.Win32NT)
Assert.Ignore("Skipping xbuild tests on windows");

var root = Path.GetDirectoryName(typeof(BuilderTargetsTest).Assembly.Location);
var outputPath = Path.Combine(root, "Assets", "Projects", "Content", "bin");
if (Directory.Exists(outputPath))
Directory.Delete(outputPath, recursive: true);

var result = RunBuild(buildTool, Path.Combine("Assets", "Projects", "BuildSimpleProject.csproj"), new string[] {
"/p:MonoGameContentBuilderExe=" + Path.Combine(root, "MGCB.exe")
var result = RunBuild("dotnet", Path.Combine(root, "Assets", "Projects", "BuildSimpleProject.csproj"), new string[] {
"-p:MGCBCommand=" + Path.Combine(root, "mgcb.dll")
});
Assert.AreEqual(true, result, "Content Build should have succeeded.");
var contentFont = Path.Combine(outputPath, "DesktopGL", "Content", "ContentFont.xnb");
Expand Down
1 change: 1 addition & 0 deletions Tools/MonoGame.Tools.Tests/EffectProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace MonoGame.Tests.ContentPipeline
{
[Ignore("Does not work on CI yet.")]
class EffectProcessorTests
{
class ImporterContext : ContentImporterContext
Expand Down
2 changes: 2 additions & 0 deletions Tools/MonoGame.Tools.Tests/ModelProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ public void DefaultEffectTest()
}

[Test]
[Ignore ("Not working yet")]
/// <summary>
/// Test to validate a model with missing normals does not throw an exception using the default ModelProcessor.
/// </summary>
Expand All @@ -305,6 +306,7 @@ public void MissingNormalsTestDefault()
}

[Test]
[Ignore ("Not working yet")]
/// <summary>
/// Test to validate a model with missing normals does not throw an exception using a custom ModelProcessor using MeshHelper.CalculateTangentFrames directly.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions Tools/MonoGame.Tools.Tests/MonoGame.Tools.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<DefineConstants>DESKTOPGL</DefineConstants>
<DefineConstants Condition=" $([MSBuild]::IsOsPlatform('osx')) " >$(DefineConstants);MACOS</DefineConstants>
<DefineConstants Condition=" $([MSBuild]::IsOsPlatform('windows')) " >$(DefineConstants);WINDOWS</DefineConstants>
<DefineConstants Condition=" $([MSBuild]::IsOsPlatform('linux')) " >$(DefineConstants);LINUX</DefineConstants>
<BaseOutputPath>..\..\Artifacts\Tests\Tools</BaseOutputPath>
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
<UseAppHost>true</UseAppHost>
Expand All @@ -23,6 +26,8 @@
<ItemGroup>
<ProjectReference Include="..\..\MonoGame.Framework\MonoGame.Framework.DesktopGL.csproj" />
<ProjectReference Include="..\..\MonoGame.Framework.Content.Pipeline\MonoGame.Framework.Content.Pipeline.csproj" />
<ProjectReference Include="..\..\Tools\MonoGame.Content.Builder\MonoGame.Content.Builder.csproj" />
<ProjectReference Include="..\..\Tools\MonoGame.Effect.Compiler\MonoGame.Effect.Compiler.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions Tools/MonoGame.Tools.Tests/Mp3ImporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace MonoGame.Tests.ContentPipeline
{
#if MACOS
[Ignore("Hanging on Mac in CI?")]
#endif
class Mp3ImporterTests
{
[Test]
Expand Down
3 changes: 3 additions & 0 deletions Tools/MonoGame.Tools.Tests/OggImporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace MonoGame.Tests.ContentPipeline
{
#if MACOS
[Ignore("Hanging on Mac in CI?")]
#endif
class OggImporterTests
{
[Test]
Expand Down
Loading

0 comments on commit bd87586

Please sign in to comment.