Skip to content

Commit 7e19f3a

Browse files
Enable GitHub actions
1 parent f188f76 commit 7e19f3a

File tree

6 files changed

+85
-52
lines changed

6 files changed

+85
-52
lines changed

.github/workflows/build.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: build
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
build-windows:
9+
runs-on: windows-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Run
13+
run: ./build.ps1
14+
build-linux:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Clang
19+
uses: egor-tensin/setup-clang@v1
20+
with:
21+
version: latest
22+
platform: x64
23+
- name: Set up zlib-static
24+
run: sudo apt-get install -y libkrb5-dev
25+
- name: Run
26+
run: ./build.sh
27+
build-macos:
28+
runs-on: macOS-latest
29+
steps:
30+
- uses: actions/checkout@v2
31+
- name: Run
32+
run: ./build.sh

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,7 @@ tools/**
5858
.dotnet
5959

6060
# Xamarin
61-
Resource.designer.cs
61+
Resource.designer.cs
62+
63+
# Tests
64+
TestResults

build/Program.cs

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.IO;
22
using System.Linq;
33
using System.Text;
4+
using System.Xml;
5+
using System.Xml.Xsl;
46
using Cake.Common;
57
using Cake.Common.Build;
68
using Cake.Common.Build.AppVeyor;
@@ -41,6 +43,7 @@ public class BuildContext : FrostingContext
4143
public DirectoryPath DocfxDirectory { get; }
4244
public FilePath DocfxExeFile { get; }
4345
public FilePath DocfxJsonFile { get; }
46+
public DirectoryPath TestOutputDirectory { get; }
4447

4548
public DirectoryPath ChangeLogDirectory { get; }
4649
public DirectoryPath ChangeLogGenDirectory { get; }
@@ -72,6 +75,7 @@ public BuildContext(ICakeContext context)
7275
DocfxDirectory = ToolsDirectory.Combine("docfx");
7376
DocfxExeFile = DocfxDirectory.CombineWithFilePath("docfx.exe");
7477
DocfxJsonFile = DocsDirectory.CombineWithFilePath("docfx.json");
78+
TestOutputDirectory = RootDirectory.Combine("TestResults");
7579

7680
ChangeLogDirectory = RootDirectory.Combine("docs").Combine("changelog");
7781
ChangeLogGenDirectory = RootDirectory.Combine("docs").Combine("_changelog");
@@ -93,21 +97,29 @@ public BuildContext(ICakeContext context)
9397
MsBuildSettings.WithProperty("UseSharedCompilation", "false");
9498
}
9599

96-
public DotNetCoreTestSettings GetTestSettingsParameters(string tfm)
100+
private DotNetCoreTestSettings GetTestSettingsParameters(FilePath logFile, string tfm)
97101
{
98102
return new DotNetCoreTestSettings
99103
{
100104
Configuration = BuildConfiguration,
101105
Framework = tfm,
102106
NoBuild = true,
103107
NoRestore = true,
104-
Loggers = new[] { "trx" }
108+
Loggers = new[] { "trx", $"trx;LogFileName={logFile.FullPath}" }
105109
};
106110
}
107111

112+
public void RunTests(FilePath projectFile, string alias, string tfm)
113+
{
114+
var xUnitXmlFile = TestOutputDirectory.CombineWithFilePath(alias + "-" + tfm + ".trx");
115+
this.Information($"Run tests for {projectFile} ({tfm}), result file: '{xUnitXmlFile}'");
116+
var settings = GetTestSettingsParameters(xUnitXmlFile, tfm);
117+
this.DotNetTest(projectFile.FullPath, settings);
118+
}
119+
108120
public void DocfxChangelogDownload(string version, string versionPrevious, string lastCommit = "")
109121
{
110-
this.Verbose("DocfxChangelogDownload: " + version);
122+
this.Information("DocfxChangelogDownload: " + version);
111123
// Required environment variables: GITHIB_PRODUCT, GITHUB_TOKEN
112124
var changeLogBuilderDirectory = ChangeLogGenDirectory.Combine("ChangeLogBuilder");
113125
var changeLogBuilderProjectFile = changeLogBuilderDirectory.CombineWithFilePath("ChangeLogBuilder.csproj");
@@ -121,12 +133,12 @@ public void DocfxChangelogDownload(string version, string versionPrevious, strin
121133
var src = changeLogBuilderDirectory.CombineWithFilePath(version + ".md");
122134
var dest = ChangeLogGenDirectory.Combine("details").CombineWithFilePath(version + ".md");
123135
this.CopyFile(src, dest);
124-
this.Verbose($"Changelog for {version}: {dest}");
136+
this.Information($"Changelog for {version}: {dest}");
125137
}
126138

127139
public void DocfxChangelogGenerate(string version)
128140
{
129-
this.Verbose("DocfxChangelogGenerate: " + version);
141+
this.Information("DocfxChangelogGenerate: " + version);
130142
var header = ChangeLogGenDirectory.Combine("header").CombineWithFilePath(version + ".md");
131143
var footer = ChangeLogGenDirectory.Combine("footer").CombineWithFilePath(version + ".md");
132144
var details = ChangeLogGenDirectory.Combine("details").CombineWithFilePath(version + ".md");
@@ -281,15 +293,12 @@ public override bool ShouldRun(BuildContext context)
281293

282294
public override void Run(BuildContext context)
283295
{
284-
var targetVersions = context.IsRunningOnWindows()
296+
var targetFrameworks = context.IsRunningOnWindows()
285297
? new[] { "net461", "net5.0" }
286298
: new[] { "net5.0" };
287299

288-
foreach (var version in targetVersions)
289-
{
290-
var dotNetTestSettings = context.GetTestSettingsParameters(version);
291-
context.DotNetTest(context.UnitTestsProjectFile.FullPath, dotNetTestSettings);
292-
}
300+
foreach (var targetFramework in targetFrameworks)
301+
context.RunTests(context.UnitTestsProjectFile, "UnitTests", targetFramework);
293302
}
294303
}
295304

@@ -304,7 +313,7 @@ public override bool ShouldRun(BuildContext context)
304313

305314
public override void Run(BuildContext context)
306315
{
307-
context.DotNetTest(context.IntegrationTestsProjectFile.FullPath, context.GetTestSettingsParameters("net461"));
316+
context.RunTests(context.IntegrationTestsProjectFile, "IntegrationTests", "net461");
308317
}
309318
}
310319

@@ -319,7 +328,7 @@ public override bool ShouldRun(BuildContext context)
319328

320329
public override void Run(BuildContext context)
321330
{
322-
context.DotNetTest(context.IntegrationTestsProjectFile.FullPath, context.GetTestSettingsParameters("net5.0"));
331+
context.RunTests(context.IntegrationTestsProjectFile, "IntegrationTests", "net5.0");
323332
}
324333
}
325334

@@ -355,41 +364,9 @@ public override void Run(BuildContext context)
355364
}
356365
}
357366

358-
[TaskName("CiPack")]
359-
[IsDependentOn(typeof(PackTask))]
360-
public class CiPackTask : FrostingTask<BuildContext>
361-
{
362-
public override bool ShouldRun(BuildContext context)
363-
{
364-
return context.IsCiBuild && context.IsOnAppVeyorAndNotPr && context.IsRunningOnWindows();
365-
}
366-
}
367-
368-
[TaskName("Ci")]
369-
[IsDependentOn(typeof(AllTestsTask))]
370-
[IsDependentOn(typeof(CiPackTask))]
371-
public class CiTask : FrostingTask<BuildContext>
372-
{
373-
public override bool ShouldRun(BuildContext context)
374-
{
375-
return context.IsCiBuild;
376-
}
377-
}
378-
379-
[TaskName("Local")]
367+
[TaskName("Default")]
380368
[IsDependentOn(typeof(AllTestsTask))]
381369
[IsDependentOn(typeof(PackTask))]
382-
public class LocalTask : FrostingTask<BuildContext>
383-
{
384-
public override bool ShouldRun(BuildContext context)
385-
{
386-
return context.IsLocalBuild;
387-
}
388-
}
389-
390-
[TaskName("Default")]
391-
[IsDependentOn(typeof(LocalTask))]
392-
[IsDependentOn(typeof(CiTask))]
393370
public class DefaultTask : FrostingTask
394371
{
395372
}

tests/BenchmarkDotNet.IntegrationTests/AllSetupAndCleanupTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using BenchmarkDotNet.Engines;
66
using BenchmarkDotNet.Jobs;
77
using BenchmarkDotNet.Tests.Loggers;
8+
using BenchmarkDotNet.Tests.XUnit;
89
using Xunit;
910
using Xunit.Abstractions;
1011

@@ -234,7 +235,7 @@ public class AllSetupAndCleanupAttributeBenchmarksAsyncValueTaskSetup
234235
public void Benchmark() => Console.WriteLine(BenchmarkCalled);
235236
}
236237

237-
[Fact]
238+
[FactNotGitHubActionsWindows]
238239
public void AllSetupAndCleanupMethodRunsAsyncGenericValueTaskSetupTest()
239240
{
240241
var logger = new OutputLogger(Output);

tests/BenchmarkDotNet.Tests/XUnit/NotTravisFactAttribute.cs renamed to tests/BenchmarkDotNet.Tests/XUnit/FactNotGitHubActionsAttribute.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
namespace BenchmarkDotNet.Tests.XUnit
55
{
6-
public class NotTravisFactAttributeAttribute : FactAttribute
6+
public class FactNotGitHubActionsAttribute : FactAttribute
77
{
8-
private const string Message = "Test is not available on Travis";
8+
private const string Message = "Test is not available on GitHub Actions";
99
private static readonly string skip;
1010

11-
static NotTravisFactAttributeAttribute()
11+
static FactNotGitHubActionsAttribute()
1212
{
13-
string value = Environment.GetEnvironmentVariable("TRAVIS"); // https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
13+
string value = Environment.GetEnvironmentVariable("GITHUB_WORKFLOW"); // https://docs.github.com/en/actions/learn-github-actions/environment-variables
1414
skip = !string.IsNullOrEmpty(value) ? Message : null;
1515
}
1616

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using BenchmarkDotNet.Portability;
3+
using Xunit;
4+
5+
namespace BenchmarkDotNet.Tests.XUnit
6+
{
7+
public class FactNotGitHubActionsWindowsAttribute : FactAttribute
8+
{
9+
private const string Message = "Test is not available on GitHub Actions Windows";
10+
private static readonly string skip;
11+
12+
static FactNotGitHubActionsWindowsAttribute()
13+
{
14+
string value = Environment.GetEnvironmentVariable("GITHUB_WORKFLOW"); // https://docs.github.com/en/actions/learn-github-actions/environment-variables
15+
skip = !string.IsNullOrEmpty(value) && RuntimeInformation.IsWindows() ? Message : null;
16+
}
17+
18+
public override string Skip => skip;
19+
}
20+
}

0 commit comments

Comments
 (0)