Skip to content

Commit

Permalink
Merge branch 'release/0.11.0'
Browse files Browse the repository at this point in the history
* release/0.11.0:
  (#56) Update all artifacts through build provider
  (#57) Fixed casing of test file names
  (#58) Ensure log file is generated from xBuild
  (maint) Fix information message
  • Loading branch information
gep13 committed May 7, 2022
2 parents 4ffd512 + 18a8295 commit 43ebf40
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 18 deletions.
7 changes: 6 additions & 1 deletion Chocolatey.Cake.Recipe/Content/analyzing.cake
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ BuildParameters.Tasks.InspectCodeTask = Task("InspectCode")
data.RepositoryRoot);
Information("{0} InspectCode issues are found.", issues.Count());
data.AddIssues(issues);

if (FileExists(inspectCodeLogFilePath))
{
BuildParameters.BuildProvider.UploadArtifact(inspectCodeLogFilePath);
}
})
);

Expand All @@ -63,7 +68,7 @@ BuildParameters.Tasks.CreateIssuesReportTask = Task("CreateIssuesReport")
"./",
issueReportFile);

if (!BuildParameters.IsLocalBuild && FileExists(issueReportFile))
if (FileExists(issueReportFile))
{
BuildParameters.BuildProvider.UploadArtifact(issueReportFile);
}
Expand Down
14 changes: 9 additions & 5 deletions Chocolatey.Cake.Recipe/Content/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,16 @@ BuildParameters.Tasks.BuildTask = Task("Build")
.WithTarget("Build")
.WithProperty("TreatWarningsAsErrors", BuildParameters.TreatWarningsAsErrors.ToString());

xbuildSettings.ArgumentCustomization = args => args.Append(string.Format("/filelogger /flp1:LogFile={0};Append;Encoding=ASCII", BuildParameters.Paths.Files.BuildLogFilePath.FullPath));

XBuild(BuildParameters.SolutionFilePath, xbuildSettings);
}

if (FileExists(BuildParameters.Paths.Files.BuildLogFilePath))
{
BuildParameters.BuildProvider.UploadArtifact(BuildParameters.Paths.Files.BuildLogFilePath);
}

CopyBuildOutput();
}));

Expand Down Expand Up @@ -410,9 +417,6 @@ BuildParameters.Tasks.BuildMsiTask = Task("Build-MSI")
})
);

BuildParameters.Tasks.PackageTask = Task("Package")
.IsDependentOn("Export-Release-Notes");

BuildParameters.Tasks.DefaultTask = Task("Default")
.IsDependentOn("Package");

Expand Down Expand Up @@ -531,7 +535,7 @@ public class Builder
BuildParameters.Tasks.GenerateLocalCoverageReportTask.IsDependentOn("Test-NUnit");
BuildParameters.Tasks.GenerateLocalCoverageReportTask.IsDependentOn("Test-xUnit");
BuildParameters.Tasks.TestTask.IsDependentOn("Generate-FriendlyTestReport");
BuildParameters.Tasks.TestTask.IsDependentOn("Generate-LocalCoverageReport");
BuildParameters.Tasks.TestTask.IsDependentOn("Generate-FriendlyCoverageReport");
BuildParameters.Tasks.TestTask.IsDependentOn("Report-UnitTestResults");
BuildParameters.Tasks.TestTask.IsDependentOn("Report-Code-Coverage-Metrics");
}
Expand All @@ -544,7 +548,7 @@ public class Builder

BuildParameters.Tasks.PackageTask.IsDependentOn(prefix + "Pack");
BuildParameters.Tasks.GenerateLocalCoverageReportTask.IsDependentOn(prefix + "Test");
BuildParameters.Tasks.TestTask.IsDependentOn("Generate-LocalCoverageReport");
BuildParameters.Tasks.TestTask.IsDependentOn("Generate-FriendlyCoverageReport");
BuildParameters.Tasks.TestTask.IsDependentOn("Report-UnitTestResults");
BuildParameters.Tasks.TestTask.IsDependentOn("Report-Code-Coverage-Metrics");
}
Expand Down
1 change: 1 addition & 0 deletions Chocolatey.Cake.Recipe/Content/github-actions.cake
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public class GitHubActionBuildProvider : IBuildProvider

public void UploadArtifact(FilePath file)
{
_context.Information("Uploading artifact from path: {0}", file.FullPath);
_context.Information("Uploading artifacts is currently not supported in Cake.Recipe. Please use the actions/upload-artifacts GitHub Action");
}
}
5 changes: 5 additions & 0 deletions Chocolatey.Cake.Recipe/Content/ilmerge.cake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ BuildParameters.Tasks.ILMergeTask = Task("Run-ILMerge")

Information("Running ILMerge...");
ILMerge(ilMergeConfig.Output, ilMergeConfig.PrimaryAssemblyName, ilMergeConfig.AssemblyPaths, settings);

if (FileExists(ilMergeConfig.LogFile))
{
BuildParameters.BuildProvider.UploadArtifact(ilMergeConfig.LogFile);
}
}
}
else
Expand Down
1 change: 1 addition & 0 deletions Chocolatey.Cake.Recipe/Content/localbuild.cake
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public class LocalBuildBuildProvider : IBuildProvider

public void UploadArtifact(FilePath file)
{
_context.Information("Uploading artifact from path: {0}", file.FullPath);
_context.Information("Unable to upload artifacts as running local build");
}
}
16 changes: 15 additions & 1 deletion Chocolatey.Cake.Recipe/Content/packages.cake
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,18 @@ public void PushNuGetPackages(ICakeContext context, bool isRelease, List<Package
{
context.Information("Unable to publish NuGet Packages as NuGet Packages Directory doesn't exist.");
}
}
}

BuildParameters.Tasks.PackageTask = Task("Package")
.IsDependentOn("Export-Release-Notes")
.Does(() => {
foreach (var nuGetPackage in GetFiles(BuildParameters.Paths.Directories.NuGetPackages + "/**/*.nupkg"))
{
BuildParameters.BuildProvider.UploadArtifact(nuGetPackage);
}

foreach (var chocolateyPackage in GetFiles(BuildParameters.Paths.Directories.ChocolateyPackages + "/*.nupkg"))
{
BuildParameters.BuildProvider.UploadArtifact(chocolateyPackage);
}
});
4 changes: 4 additions & 0 deletions Chocolatey.Cake.Recipe/Content/teamcity.cake
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public class TeamCityBuildProvider : IBuildProvider
Repository = new TeamCityRepositoryInfo(teamCity, context);

_teamCity = teamCity;
_context = context;
}

public IRepositoryInfo Repository { get; }
Expand All @@ -169,8 +170,11 @@ public class TeamCityBuildProvider : IBuildProvider

private readonly ITeamCityProvider _teamCity;

private readonly ICakeContext _context;

public void UploadArtifact(FilePath file)
{
_context.Information("Uploading artifact from path: {0}", file.FullPath);
_teamCity.PublishArtifacts(file.FullPath);
}
}
64 changes: 53 additions & 11 deletions Chocolatey.Cake.Recipe/Content/testing.cake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BuildParameters.Tasks.TestNUnitTask = Task("Test-NUnit")
Information("Running OpenCover and NUnit...");

OpenCover(tool => {
tool.NUnit3(GetFiles(BuildParameters.Paths.Directories.PublishedNUnitTests + (BuildParameters.TestFilePattern ?? "/**/*Tests.dll")), new NUnit3Settings {
tool.NUnit3(GetFiles(BuildParameters.Paths.Directories.PublishedNUnitTests + (BuildParameters.TestFilePattern ?? "/**/*[tT]ests.dll")), new NUnit3Settings {
Work = BuildParameters.Paths.Directories.NUnitTestResults
});
},
Expand All @@ -37,10 +37,10 @@ BuildParameters.Tasks.TestNUnitTask = Task("Test-NUnit")
}
else
{
Information("Running OpenCover and NUnit...");
Information("Running NUnit...");

// OpenCover doesn't work on anything non-windows, so let's just run NUnit by itself
NUnit3(GetFiles(BuildParameters.Paths.Directories.PublishedNUnitTests + (BuildParameters.TestFilePattern ?? "/**/*Tests.dll")), new NUnit3Settings {
NUnit3(GetFiles(BuildParameters.Paths.Directories.PublishedNUnitTests + (BuildParameters.TestFilePattern ?? "/**/*[tT]ests.dll")), new NUnit3Settings {
Work = BuildParameters.Paths.Directories.NUnitTestResults
});
}
Expand All @@ -51,14 +51,14 @@ BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit")
.IsDependentOn("Install-OpenCover")
.WithCriteria(() => DirectoryExists(BuildParameters.Paths.Directories.PublishedxUnitTests), "Skipping because there are no published xUnit tests")
.Does(() => RequireTool(ToolSettings.XUnitTool, () => {
EnsureDirectoryExists(BuildParameters.Paths.Directories.xUnitTestResults);
EnsureDirectoryExists(BuildParameters.Paths.Directories.xUnitTestResults);

if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows)
{
Information("Running OpenCover and xUnit...");

OpenCover(tool => {
tool.XUnit2(GetFiles(BuildParameters.Paths.Directories.PublishedxUnitTests + (BuildParameters.TestFilePattern ?? "/**/*Tests.dll")), new XUnit2Settings {
tool.XUnit2(GetFiles(BuildParameters.Paths.Directories.PublishedxUnitTests + (BuildParameters.TestFilePattern ?? "/**/*[tT]ests.dll")), new XUnit2Settings {
OutputDirectory = BuildParameters.Paths.Directories.xUnitTestResults,
XmlReport = true,
NoAppDomain = true
Expand All @@ -79,7 +79,7 @@ BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit")
Information("Running xUnit...");

// OpenCover doesn't work on anything non-windows, so let's just run xUnit by itself
XUnit2(GetFiles(BuildParameters.Paths.Directories.PublishedxUnitTests + (BuildParameters.TestFilePattern ?? "/**/*Tests.dll")), new XUnit2Settings {
XUnit2(GetFiles(BuildParameters.Paths.Directories.PublishedxUnitTests + (BuildParameters.TestFilePattern ?? "/**/*[tT]ests.dll")), new XUnit2Settings {
OutputDirectory = BuildParameters.Paths.Directories.xUnitTestResults,
XmlReport = true,
NoAppDomain = true
Expand Down Expand Up @@ -214,6 +214,13 @@ BuildParameters.Tasks.GenerateFriendlyTestReportTask = Task("Generate-FriendlyTe
foreach (var directory in possibleDirectories.Where((d) => DirectoryExists(d)))
{
ReportUnit(directory, directory, new ReportUnitSettings());

var reportUnitFiles = GetFiles(directory + "/*.html");
var reportUnitZipFileName = directory.FullPath.Contains("xunit") ? "xunit-reportunit.zip" : "nunit-reportunit.zip";
var rootPath =directory.FullPath.Contains("xunit") ? "./code_drop/TestResults/xUnit" : "./code_drop/TestResults/NUnit";
Zip(rootPath, directory + "/" + reportUnitZipFileName, reportUnitFiles);

BuildParameters.BuildProvider.UploadArtifact(directory + "/" + reportUnitZipFileName);
}
})
);
Expand Down Expand Up @@ -256,8 +263,6 @@ BuildParameters.Tasks.ReportCodeCoverageMetricsTask = Task("Report-Code-Coverage

foreach(var coverageFile in coverageFiles)
{
BuildParameters.BuildProvider.UploadArtifact(coverageFile);

XDocument doc = XDocument.Load(coverageFile.FullPath);
XElement summary = doc.XPathSelectElement("/CoverageSession/Summary");

Expand Down Expand Up @@ -318,8 +323,7 @@ private void ReportCoverageMetric(
Information($"##teamcity[buildStatisticValue key='{tcCoverageKey}' value='{coverage}']");
}

BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Generate-LocalCoverageReport")
.WithCriteria(() => BuildParameters.IsLocalBuild, "Skipping due to not running a local build")
BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Generate-FriendlyCoverageReport")
.Does(() => RequireTool(BuildParameters.IsDotNetCoreBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.ReportGeneratorGlobalTool : ToolSettings.ReportGeneratorTool, () => {
var coverageFiles = GetFiles(BuildParameters.Paths.Directories.TestCoverage + "/coverlet/*.xml");
if (FileExists(BuildParameters.Paths.Files.TestCoverageOutputFilePath))
Expand All @@ -338,6 +342,17 @@ BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Generate-LocalCove
}

ReportGenerator(coverageFiles, BuildParameters.Paths.Directories.TestCoverage, settings);

var reportGeneratorFiles = GetFiles(BuildParameters.Paths.Directories.TestCoverage + "/*.html")
+ GetFiles(BuildParameters.Paths.Directories.TestCoverage + "/*.htm")
+ GetFiles(BuildParameters.Paths.Directories.TestCoverage + "/*.js")
+ GetFiles(BuildParameters.Paths.Directories.TestCoverage + "/*.svg")
+ GetFiles(BuildParameters.Paths.Directories.TestCoverage + "/*.css");

var reportGeneratorZipFileName = "coverage.zip";
Zip("./code_drop/TestCoverage", BuildParameters.Paths.Directories.TestCoverage + "/" + reportGeneratorZipFileName, reportGeneratorFiles);

BuildParameters.BuildProvider.UploadArtifact(BuildParameters.Paths.Directories.TestCoverage + "/" + reportGeneratorZipFileName);
}
else
{
Expand Down Expand Up @@ -372,4 +387,31 @@ BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Convert-OpenCoverT
})
);

BuildParameters.Tasks.TestTask = Task("Test");
BuildParameters.Tasks.TestTask = Task("Test")
.Does(() => {
var coverageFiles = GetFiles(BuildParameters.Paths.Directories.TestCoverage + "/coverlet/*.xml");
if (FileExists(BuildParameters.Paths.Files.TestCoverageOutputFilePath))
{
coverageFiles += BuildParameters.Paths.Files.TestCoverageOutputFilePath;
}

foreach (var coverageFile in coverageFiles)
{
BuildParameters.BuildProvider.UploadArtifact(coverageFile);
}

foreach (var nUnitResultFile in GetFiles(BuildParameters.Paths.Directories.NUnitTestResults + "/*.xml"))
{
BuildParameters.BuildProvider.UploadArtifact(nUnitResultFile);
}

foreach (var xUnitResultFile in GetFiles(BuildParameters.Paths.Directories.xUnitTestResults + "/*.xml"))
{
BuildParameters.BuildProvider.UploadArtifact(xUnitResultFile);
}

if (FileExists(BuildParameters.Paths.Directories.TestCoverage + "/lcov.info"))
{
BuildParameters.BuildProvider.UploadArtifact(BuildParameters.Paths.Directories.TestCoverage + "/lcov.info");
}
});

0 comments on commit 43ebf40

Please sign in to comment.