diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 000000000..396c8215b --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,32 @@ +name: build + +on: + pull_request: + push: + +jobs: + build-windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - name: Run + run: ./build.ps1 + build-linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Clang + uses: egor-tensin/setup-clang@v1 + with: + version: latest + platform: x64 + - name: Set up zlib-static + run: sudo apt-get install -y libkrb5-dev + - name: Run + run: ./build.sh + build-macos: + runs-on: macOS-latest + steps: + - uses: actions/checkout@v2 + - name: Run + run: ./build.sh \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7560c1805..dcfea7f2d 100644 --- a/.gitignore +++ b/.gitignore @@ -58,4 +58,7 @@ tools/** .dotnet # Xamarin -Resource.designer.cs \ No newline at end of file +Resource.designer.cs + +# Tests +TestResults \ No newline at end of file diff --git a/build/Program.cs b/build/Program.cs index 5a9369d8a..637015a0c 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -1,6 +1,8 @@ using System.IO; using System.Linq; using System.Text; +using System.Xml; +using System.Xml.Xsl; using Cake.Common; using Cake.Common.Build; using Cake.Common.Build.AppVeyor; @@ -41,6 +43,7 @@ public class BuildContext : FrostingContext public DirectoryPath DocfxDirectory { get; } public FilePath DocfxExeFile { get; } public FilePath DocfxJsonFile { get; } + public DirectoryPath TestOutputDirectory { get; } public DirectoryPath ChangeLogDirectory { get; } public DirectoryPath ChangeLogGenDirectory { get; } @@ -72,6 +75,7 @@ public class BuildContext : FrostingContext DocfxDirectory = ToolsDirectory.Combine("docfx"); DocfxExeFile = DocfxDirectory.CombineWithFilePath("docfx.exe"); DocfxJsonFile = DocsDirectory.CombineWithFilePath("docfx.json"); + TestOutputDirectory = RootDirectory.Combine("TestResults"); ChangeLogDirectory = RootDirectory.Combine("docs").Combine("changelog"); ChangeLogGenDirectory = RootDirectory.Combine("docs").Combine("_changelog"); @@ -93,7 +97,7 @@ public class BuildContext : FrostingContext MsBuildSettings.WithProperty("UseSharedCompilation", "false"); } - public DotNetCoreTestSettings GetTestSettingsParameters(string tfm) + private DotNetCoreTestSettings GetTestSettingsParameters(FilePath logFile, string tfm) { return new DotNetCoreTestSettings { @@ -101,13 +105,21 @@ public class BuildContext : FrostingContext Framework = tfm, NoBuild = true, NoRestore = true, - Loggers = new[] { "trx" } + Loggers = new[] { "trx", $"trx;LogFileName={logFile.FullPath}" } }; } + public void RunTests(FilePath projectFile, string alias, string tfm) + { + var xUnitXmlFile = TestOutputDirectory.CombineWithFilePath(alias + "-" + tfm + ".trx"); + this.Information($"Run tests for {projectFile} ({tfm}), result file: '{xUnitXmlFile}'"); + var settings = GetTestSettingsParameters(xUnitXmlFile, tfm); + this.DotNetTest(projectFile.FullPath, settings); + } + public void DocfxChangelogDownload(string version, string versionPrevious, string lastCommit = "") { - this.Verbose("DocfxChangelogDownload: " + version); + this.Information("DocfxChangelogDownload: " + version); // Required environment variables: GITHIB_PRODUCT, GITHUB_TOKEN var changeLogBuilderDirectory = ChangeLogGenDirectory.Combine("ChangeLogBuilder"); var changeLogBuilderProjectFile = changeLogBuilderDirectory.CombineWithFilePath("ChangeLogBuilder.csproj"); @@ -121,12 +133,12 @@ public class BuildContext : FrostingContext var src = changeLogBuilderDirectory.CombineWithFilePath(version + ".md"); var dest = ChangeLogGenDirectory.Combine("details").CombineWithFilePath(version + ".md"); this.CopyFile(src, dest); - this.Verbose($"Changelog for {version}: {dest}"); + this.Information($"Changelog for {version}: {dest}"); } public void DocfxChangelogGenerate(string version) { - this.Verbose("DocfxChangelogGenerate: " + version); + this.Information("DocfxChangelogGenerate: " + version); var header = ChangeLogGenDirectory.Combine("header").CombineWithFilePath(version + ".md"); var footer = ChangeLogGenDirectory.Combine("footer").CombineWithFilePath(version + ".md"); var details = ChangeLogGenDirectory.Combine("details").CombineWithFilePath(version + ".md"); @@ -281,15 +293,12 @@ public class FastTestsTask : FrostingTask public override void Run(BuildContext context) { - var targetVersions = context.IsRunningOnWindows() + var targetFrameworks = context.IsRunningOnWindows() ? new[] { "net461", "net5.0" } : new[] { "net5.0" }; - foreach (var version in targetVersions) - { - var dotNetTestSettings = context.GetTestSettingsParameters(version); - context.DotNetTest(context.UnitTestsProjectFile.FullPath, dotNetTestSettings); - } + foreach (var targetFramework in targetFrameworks) + context.RunTests(context.UnitTestsProjectFile, "UnitTests", targetFramework); } } @@ -304,7 +313,7 @@ public class SlowTestsNet461Task : FrostingTask public override void Run(BuildContext context) { - context.DotNetTest(context.IntegrationTestsProjectFile.FullPath, context.GetTestSettingsParameters("net461")); + context.RunTests(context.IntegrationTestsProjectFile, "IntegrationTests", "net461"); } } @@ -319,7 +328,7 @@ public class SlowTestsNet5Task : FrostingTask public override void Run(BuildContext context) { - context.DotNetTest(context.IntegrationTestsProjectFile.FullPath, context.GetTestSettingsParameters("net5.0")); + context.RunTests(context.IntegrationTestsProjectFile, "IntegrationTests", "net5.0"); } } @@ -355,41 +364,9 @@ public class PackTask : FrostingTask } } -[TaskName("CiPack")] -[IsDependentOn(typeof(PackTask))] -public class CiPackTask : FrostingTask -{ - public override bool ShouldRun(BuildContext context) - { - return context.IsCiBuild && context.IsOnAppVeyorAndNotPr && context.IsRunningOnWindows(); - } -} - -[TaskName("Ci")] -[IsDependentOn(typeof(AllTestsTask))] -[IsDependentOn(typeof(CiPackTask))] -public class CiTask : FrostingTask -{ - public override bool ShouldRun(BuildContext context) - { - return context.IsCiBuild; - } -} - -[TaskName("Local")] -[IsDependentOn(typeof(AllTestsTask))] -[IsDependentOn(typeof(PackTask))] -public class LocalTask : FrostingTask -{ - public override bool ShouldRun(BuildContext context) - { - return context.IsLocalBuild; - } -} - [TaskName("Default")] -[IsDependentOn(typeof(LocalTask))] -[IsDependentOn(typeof(CiTask))] +[IsDependentOn(typeof(AllTestsTask))] +[IsDependentOn(typeof(PackTask))] public class DefaultTask : FrostingTask { } diff --git a/tests/BenchmarkDotNet.IntegrationTests/AllSetupAndCleanupTest.cs b/tests/BenchmarkDotNet.IntegrationTests/AllSetupAndCleanupTest.cs index 1b8697689..dc4cf9bfe 100644 --- a/tests/BenchmarkDotNet.IntegrationTests/AllSetupAndCleanupTest.cs +++ b/tests/BenchmarkDotNet.IntegrationTests/AllSetupAndCleanupTest.cs @@ -5,6 +5,7 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Engines; using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Tests.Loggers; +using BenchmarkDotNet.Tests.XUnit; using Xunit; using Xunit.Abstractions; @@ -234,7 +235,7 @@ namespace BenchmarkDotNet.IntegrationTests public void Benchmark() => Console.WriteLine(BenchmarkCalled); } - [Fact] + [FactNotGitHubActionsWindows] public void AllSetupAndCleanupMethodRunsAsyncGenericValueTaskSetupTest() { var logger = new OutputLogger(Output); diff --git a/tests/BenchmarkDotNet.Tests/XUnit/NotTravisFactAttribute.cs b/tests/BenchmarkDotNet.Tests/XUnit/FactNotGitHubActionsAttribute.cs similarity index 52% rename from tests/BenchmarkDotNet.Tests/XUnit/NotTravisFactAttribute.cs rename to tests/BenchmarkDotNet.Tests/XUnit/FactNotGitHubActionsAttribute.cs index 416ed30a1..a0e2f356e 100644 --- a/tests/BenchmarkDotNet.Tests/XUnit/NotTravisFactAttribute.cs +++ b/tests/BenchmarkDotNet.Tests/XUnit/FactNotGitHubActionsAttribute.cs @@ -3,14 +3,14 @@ using Xunit; namespace BenchmarkDotNet.Tests.XUnit { - public class NotTravisFactAttributeAttribute : FactAttribute + public class FactNotGitHubActionsAttribute : FactAttribute { - private const string Message = "Test is not available on Travis"; + private const string Message = "Test is not available on GitHub Actions"; private static readonly string skip; - static NotTravisFactAttributeAttribute() + static FactNotGitHubActionsAttribute() { - string value = Environment.GetEnvironmentVariable("TRAVIS"); // https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables + string value = Environment.GetEnvironmentVariable("GITHUB_WORKFLOW"); // https://docs.github.com/en/actions/learn-github-actions/environment-variables skip = !string.IsNullOrEmpty(value) ? Message : null; } diff --git a/tests/BenchmarkDotNet.Tests/XUnit/FactNotGitHubActionsWindowsAttribute.cs b/tests/BenchmarkDotNet.Tests/XUnit/FactNotGitHubActionsWindowsAttribute.cs new file mode 100644 index 000000000..ff97b4d6c --- /dev/null +++ b/tests/BenchmarkDotNet.Tests/XUnit/FactNotGitHubActionsWindowsAttribute.cs @@ -0,0 +1,20 @@ +using System; +using BenchmarkDotNet.Portability; +using Xunit; + +namespace BenchmarkDotNet.Tests.XUnit +{ + public class FactNotGitHubActionsWindowsAttribute : FactAttribute + { + private const string Message = "Test is not available on GitHub Actions Windows"; + private static readonly string skip; + + static FactNotGitHubActionsWindowsAttribute() + { + string value = Environment.GetEnvironmentVariable("GITHUB_WORKFLOW"); // https://docs.github.com/en/actions/learn-github-actions/environment-variables + skip = !string.IsNullOrEmpty(value) && RuntimeInformation.IsWindows() ? Message : null; + } + + public override string Skip => skip; + } +} \ No newline at end of file