Skip to content

Commit

Permalink
Merge pull request #221 from alphacloud/releases/4.0.0
Browse files Browse the repository at this point in the history
v4.0.0
  • Loading branch information
cd21h authored May 30, 2022
2 parents 27040ee + 1874db5 commit e6c2bfa
Show file tree
Hide file tree
Showing 31 changed files with 1,410 additions and 1,494 deletions.
12 changes: 6 additions & 6 deletions .build/definitions.cake
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// ADDINS
#addin nuget:?package=Cake.Coveralls&version=1.0.1
#addin nuget:?package=Cake.Coveralls&version=1.1.0
#addin nuget:?package=Cake.FileHelpers&version=4.0.1
#addin nuget:?package=Cake.AppVeyor&version=5.0.1

// TOOLS
#tool nuget:?package=GitReleaseManager&version=0.11.0
#tool nuget:?package=GitVersion.CommandLine&version=5.6.8
#tool nuget:?package=GitReleaseManager&version=0.12.1
#tool nuget:?package=GitVersion.CommandLine&version=5.7.0
#tool nuget:?package=coveralls.io&version=1.4.2
#tool nuget:?package=OpenCover&version=4.7.922
#tool nuget:?package=ReportGenerator&version=4.8.7
#tool nuget:?package=OpenCover&version=4.7.1221
#tool nuget:?package=ReportGenerator&version=4.8.13


public class CodeCoverageSettings
{
public string ExcludeByFile { get; set; } = "*/*Designer.cs";
public string ExcludeByAttribute { get; set; } = "*.ExcludeFromCodeCoverage*";
public string ExcludeFilter { get; set; } = "-[Tests*]*";
public string ExcludeFilter { get; set; } = "-[Tests*]*;-[*]Microsoft.CodeAnalysis*;-[*]System.Runtime.CompilerServices.*";
public string IncludeFilter { get; set; }
}

Expand Down
123 changes: 73 additions & 50 deletions .build/tasks.cake
Original file line number Diff line number Diff line change
Expand Up @@ -41,57 +41,80 @@ Task("RunXunitTests")
{
var projectPath = build.Paths.SrcDir;
var projectFilename = build.Settings.SolutionName;
Information("Calculating code coverage for {0} ...", projectFilename);

Func<string,ProcessArgumentBuilder> buildProcessArgs = (buildCfg) => {
var pb = new ProcessArgumentBuilder()
.AppendSwitch("--configuration", buildCfg)
.AppendSwitch("--filter", "Category!=ManualTests")
.AppendSwitch("--results-directory", build.Paths.RootDir.Combine(build.Paths.ArtifactsDir).FullPath)
.Append("--no-restore")
.Append("--no-build");
if (!build.IsLocal) {
pb.AppendSwitch("--test-adapter-path", ".")
.AppendSwitch("--logger", "AppVeyor");
}
else {
pb.AppendSwitch("--logger", $"trx;LogFileName={projectFilename}.trx");
}
return pb;
// keep in sync with src/Directory.Build.props
var testTargets = new KeyValuePair<string, bool>[] {
new KeyValuePair<string,bool>("netcoreapp3.1", true),
new KeyValuePair<string,bool>("net6.0", true),
new KeyValuePair<string,bool>("net7.0", false) // opencover does not work with .NET 7 preview
};

var openCoverSettings = new OpenCoverSettings
{
OldStyle = true,
ReturnTargetCodeOffset = 0,
ArgumentCustomization = args => args.Append("-mergeoutput").Append("-hideskipped:File;Filter;Attribute"),
WorkingDirectory = projectPath,
}
.WithFilter($"{build.Settings.CodeCoverage.IncludeFilter} {build.Settings.CodeCoverage.ExcludeFilter}")
.ExcludeByAttribute(build.Settings.CodeCoverage.ExcludeByAttribute)
.ExcludeByFile(build.Settings.CodeCoverage.ExcludeByFile);

// run open cover for debug build configuration
OpenCover(
tool => tool.DotNetCoreTool(
projectPath.ToString(),
"test",
buildProcessArgs("Debug")
),
build.Paths.RootDir.Combine(build.Paths.TestCoverageOutputFile).FullPath,
openCoverSettings
);

// run tests again if Release mode was requested
if (build.IsRelease)
foreach(var targetFw in testTargets)
{
var solutionFullPath = build.Paths.RootDir.Combine(build.Paths.SrcDir).Combine(build.Settings.SolutionName) + ".sln";
Information("Running Release mode tests for {0}", projectFilename);
DotNetCoreTool(
solutionFullPath,
"test",
buildProcessArgs("Release")
);
Func<string,string,ProcessArgumentBuilder> buildProcessArgs = (buildCfg, targetFramework) => {
var pb = new ProcessArgumentBuilder()
.AppendSwitch("--configuration", buildCfg)
.AppendSwitch("--filter", "Category!=ManualTests")
.AppendSwitch("--results-directory", build.Paths.RootDir.Combine(build.Paths.ArtifactsDir).FullPath)
.AppendSwitch("--framework", targetFramework)
.Append("--no-restore")
.Append("--no-build");
if (!build.IsLocal) {
pb.AppendSwitch("--test-adapter-path", ".")
.AppendSwitch("--logger", "AppVeyor");
}
else {
pb.AppendSwitch("--logger", $"trx;LogFileName={projectFilename}.trx");
}
return pb;
};

if (targetFw.Value) // calculate coverage
{
Information("Calculating code coverage for {0} ({1}) ...", projectFilename, targetFw.Key);

var openCoverSettings = new OpenCoverSettings
{
OldStyle = true,
ReturnTargetCodeOffset = 0,
ArgumentCustomization = args => args.Append("-mergeoutput").Append("-hideskipped:File;Filter;Attribute"),
WorkingDirectory = projectPath,
}
.WithFilter($"{build.Settings.CodeCoverage.IncludeFilter} {build.Settings.CodeCoverage.ExcludeFilter}")
.ExcludeByAttribute(build.Settings.CodeCoverage.ExcludeByAttribute)
.ExcludeByFile(build.Settings.CodeCoverage.ExcludeByFile);

// run open cover for debug build configuration
OpenCover(
tool => tool.DotNetCoreTool(
projectPath.ToString(),
"test",
buildProcessArgs("Debug", targetFw.Key)
),
build.Paths.RootDir.Combine(build.Paths.TestCoverageOutputFile).FullPath,
openCoverSettings
);
} else
{
var solutionFullPath = build.Paths.RootDir.Combine(build.Paths.SrcDir).Combine(build.Settings.SolutionName) + ".sln";
Information("Running Debug mode tests for {0} ({1})", projectFilename, targetFw.Key);
DotNetCoreTool(
solutionFullPath,
"test",
buildProcessArgs("Debug", targetFw.Key)
);

}

// run tests again if Release mode was requested
if (build.IsRelease)
{
var solutionFullPath = build.Paths.RootDir.Combine(build.Paths.SrcDir).Combine(build.Settings.SolutionName) + ".sln";
Information("Running Release mode tests for {0} ({1})", projectFilename, targetFw.Key);
DotNetCoreTool(
solutionFullPath,
"test",
buildProcessArgs("Release", targetFw.Key)
);
}
}
})
.DeferOnError();
Expand All @@ -103,7 +126,7 @@ Task("CleanPreviousTestResults")
DeleteFile(build.Paths.TestCoverageOutputFile);
DeleteFiles(build.Paths.ArtifactsDir + "/*.trx");
if (DirectoryExists(build.Paths.TestCoverageReportDir))
DeleteDirectory(build.Paths.TestCoverageReportDir, new DeleteDirectorySettings
DeleteDirectory(build.Paths.TestCoverageReportDir, new DeleteDirectorySettings
{
Force = true,
Recursive = true
Expand Down
10 changes: 4 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pull_requests:
nuget:
disable_publish_on_pr: true

os: Visual Studio 2019
os: Visual Studio 2022

environment:
# Set the DOTNET_SKIP_FIRST_TIME_EXPERIENCE environment variable to stop wasting time caching packages
Expand All @@ -21,13 +21,11 @@ environment:
secure: SakrMxbclSjNzFQxv8sA35OhulfvNm9VqHBEOgQrebPaF/Bv7AmZRsT8/YEfSQED

install:
- ps: ./dotnet-install.ps1 -Version 3.1.403 -InstallDir "C:\Program Files\dotnet"
- ps: ./dotnet-install.ps1 -Version 2.1.804 -InstallDir "C:\Program Files\dotnet"
- ps: ./dotnet-install.ps1 -Version 6.0.100-preview.6.21355.2 -InstallDir "C:\Program Files\dotnet"
- ps: dotnet tool install Cake.Tool --version 1.1.0 --global
- ps: dotnet tool install Cake.Tool --version 1.3.0 --global
- ps: ./dotnet-install.ps1 -Version 7.0.100-preview.4.22252.9 -InstallDir "C:\Program Files\dotnet"

build_script:
- ps: dotnet-cake
- ps: dotnet cake

test: off

Expand Down
Loading

0 comments on commit e6c2bfa

Please sign in to comment.