Retry converting GitHubAction `coveralls` to NUKE with `coveralls.net` by IT-VBFK · Pull Request #2095 · fluentassertions/fluentassertions · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions .github/workflows/build.yml
11 changes: 9 additions & 2 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
},
"CoverallsToken": {
"type": "string",
"description": "The coveralls specific token"
},
"Help": {
"type": "boolean",
"description": "Shows the help text for this build assembly"
Expand Down Expand Up @@ -41,8 +45,7 @@
},
"NuGetApiKey": {
"type": "string",
"description": "The key to push to Nuget",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
"description": "The key to push to Nuget"
},
"Partition": {
"type": "string",
Expand Down Expand Up @@ -74,6 +77,8 @@
"Clean",
"CodeCoverage",
"Compile",
"Coveralls",
"Info",
"Pack",
"Push",
"Restore",
Expand All @@ -100,6 +105,8 @@
"Clean",
"CodeCoverage",
"Compile",
"Coveralls",
"Info",
"Pack",
"Push",
"Restore",
Expand Down
58 changes: 52 additions & 6 deletions Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.CoverallsNet;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Tools.ReportGenerator;
using Nuke.Common.Tools.Xunit;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction;
using static Nuke.Common.Tools.CoverallsNet.CoverallsNetTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.ReportGenerator.ReportGeneratorTasks;
using static Nuke.Common.Tools.Xunit.XunitTasks;
Expand All @@ -40,8 +42,10 @@ class Build : NukeBuild
string PullRequestBase => GitHubActions?.BaseRef;

[Parameter("The key to push to Nuget")]
[Secret]
readonly string NuGetApiKey;
readonly string ApiKey;

[Parameter("The coveralls specific token")]
readonly string CoverallsToken;

[Solution(GenerateProjects = true)]
readonly Solution Solution;
Expand Down Expand Up @@ -70,8 +74,24 @@ class Build : NukeBuild

AbsolutePath TestResultsDirectory => RootDirectory / "TestResults";

AbsolutePath CoverageResultDirectory => TestResultsDirectory / "reports";

string SemVer;

Target Info => _ => _
.Executes(() =>
{
if (string.IsNullOrWhiteSpace(CoverallsToken))
{
Warning("Coveralls token is null or empty");
}

if (string.IsNullOrWhiteSpace(ApiKey))
{
Warning("NuGet API key is null or empty");
}
});

Target Clean => _ => _
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
Expand Down Expand Up @@ -152,7 +172,7 @@ class Build : NukeBuild
{
IEnumerable<string> testAssemblies = Projects
.SelectMany(project => GlobFiles(project.Directory, "bin/Debug/net47/*.Specs.dll"));

Assert.NotEmpty(testAssemblies.ToList());

Xunit2(s => s
Expand Down Expand Up @@ -193,9 +213,11 @@ class Build : NukeBuild
.DependsOn(UnitTestsNetCore);

Target CodeCoverage => _ => _
.DependsOn(TestFrameworks)
.DependsOn(TestFrameworks)
.DependsOn(UnitTests)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Produces(CoverageResultDirectory / "lcov.info")
.Triggers(Coveralls)
.Executes(() =>
{
ReportGenerator(s => s
Expand All @@ -208,10 +230,33 @@ class Build : NukeBuild
.AddFileFilters("-*.g.cs")
.SetAssemblyFilters("+FluentAssertions"));

string link = TestResultsDirectory / "reports" / "index.html";
string link = CoverageResultDirectory / "index.html";
Information($"Code coverage report: \x1b]8;;file://{link.Replace('\\', '/')}\x1b\\{link}\x1b]8;;\x1b\\");
});

Target Coveralls => _ => _
.OnlyWhenDynamic(() => !string.IsNullOrWhiteSpace(CoverallsToken) && (RunAllTargets || HasSourceChanges))
.DependsOn(CodeCoverage)
.Consumes(CodeCoverage)
.Executes(() =>
{
CoverallsNet(s => s
.SetDryRun(IsLocalBuild)
.SetProcessArgumentConfigurator(x => x
.Add("--lcov"))
.SetInput(CoverageResultDirectory / "lcov.info")
.SetRepoToken(CoverallsToken)
Comment thread
IT-VBFK marked this conversation as resolved.
.When(IsPullRequest,
s => s.SetPullRequest(GitHubActions?.PullRequestNumber)
)
.EnableUserRelativePaths()
.SetCommitBranch(GitRepository.Branch)
.SetCommitId(GitRepository.Commit)
.SetCommitAuthor(Repository.Head.Tip.Author.Name)
.SetCommitEmail(Repository.Head.Tip.Author.Email)
.SetCommitMessage(Repository.Head.Tip.MessageShort));
});

Target TestFrameworks => _ => _
.DependsOn(Compile)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
Expand Down Expand Up @@ -279,7 +324,7 @@ from framework in supportedFrameworks
Assert.NotEmpty(packages.ToList());

DotNetNuGetPush(s => s
.SetApiKey(NuGetApiKey)
.SetApiKey(ApiKey)
.EnableSkipDuplicate()
.SetSource("https://api.nuget.org/v3/index.json")
.EnableNoSymbols()
Expand Down Expand Up @@ -318,3 +363,4 @@ from framework in supportedFrameworks

bool IsTag => BranchSpec != null && BranchSpec.Contains("refs/tags", StringComparison.InvariantCultureIgnoreCase);
}

1 change: 1 addition & 0 deletions Build/_build.csproj