Skip to content

Commit

Permalink
Proceed after failed target on independent pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
IT-VBFK committed Jan 11, 2023
1 parent 17159d1 commit 03bdcc4
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 34 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/build.yml
Expand Up @@ -27,16 +27,8 @@ jobs:
- name: Run NUKE
run: ./build.ps1
env:
BranchSpec: ${{ github.ref }}
BuildNumber: ${{ github.run_number }}
PullRequestBase: ${{ github.event.pull_request.base.ref }}
ApiKey: ${{ secrets.NUGETAPIKEY }}

- name: coveralls
uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: TestResults/reports/lcov.info
GithubToken: ${{ secrets.GITHUB_TOKEN }}

- name: Upload artifacts
uses: actions/upload-artifact@v3
Expand Down
23 changes: 7 additions & 16 deletions .nuke/build.schema.json
Expand Up @@ -6,18 +6,6 @@
"build": {
"type": "object",
"properties": {
"ApiKey": {
"type": "string",
"description": "The key to push to Nuget"
},
"BranchSpec": {
"type": "string",
"description": "A branch specification such as develop or refs/pull/1775/merge"
},
"BuildNumber": {
"type": "string",
"description": "An incrementing build number as provided by the build engine"
},
"Continue": {
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
Expand Down Expand Up @@ -51,6 +39,11 @@
"type": "boolean",
"description": "Disables displaying the NUKE logo"
},
"Nugetapikey": {
"type": "string",
"description": "The key to push to Nuget",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Partition": {
"type": "string",
"description": "Partition to use on CI"
Expand All @@ -66,10 +59,6 @@
"type": "string"
}
},
"PullRequestBase": {
"type": "string",
"description": "The target branch for the pull request"
},
"Root": {
"type": "string",
"description": "Root directory during build execution"
Expand All @@ -85,6 +74,7 @@
"Clean",
"CodeCoverage",
"Compile",
"Coveralls",
"Pack",
"Push",
"Restore",
Expand All @@ -109,6 +99,7 @@
"Clean",
"CodeCoverage",
"Compile",
"Coveralls",
"Pack",
"Push",
"Restore",
Expand Down
41 changes: 32 additions & 9 deletions Build/Build.cs
Expand Up @@ -3,17 +3,20 @@
using System.Linq;
using LibGit2Sharp;
using Nuke.Common;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.Execution;
using Nuke.Common.Git;
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 @@ -32,14 +35,14 @@ class Build : NukeBuild

public static int Main() => Execute<Build>(x => x.SpellCheck, x => x.Push);

[Parameter("A branch specification such as develop or refs/pull/1775/merge")]
readonly string BranchSpec;
GitHubActions GitHubActions => GitHubActions.Instance;

[Parameter("An incrementing build number as provided by the build engine")]
readonly string BuildNumber;
string BranchSpec => GitHubActions?.Ref;
string BuildNumber => GitHubActions?.RunNumber.ToString();
string PullRequestBase => GitHubActions?.BaseRef;

[Parameter("The target branch for the pull request")]
readonly string PullRequestBase;
[Parameter]
readonly string GithubToken;

[Parameter("The key to push to Nuget")]
readonly string ApiKey;
Expand Down Expand Up @@ -75,6 +78,9 @@ class Build : NukeBuild
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
{
Information(BranchSpec);
Information(BuildNumber);
Information(PullRequestBase);
EnsureCleanDirectory(ArtifactsDirectory);
EnsureCleanDirectory(TestResultsDirectory);
});
Expand Down Expand Up @@ -192,14 +198,28 @@ class Build : NukeBuild
.SetProcessToolPath(ToolPathResolver.GetPackageExecutable("ReportGenerator", "ReportGenerator.dll", framework: "net6.0"))
.SetTargetDirectory(TestResultsDirectory / "reports")
.AddReports(TestResultsDirectory / "**/coverage.cobertura.xml")
.AddReportTypes("HtmlInline_AzurePipelines_Dark", "lcov")
.AddReportTypes(
ReportTypes.Cobertura,
ReportTypes.lcov,
ReportTypes.HtmlInline_AzurePipelines_Dark)
.AddFileFilters("-*.g.cs")
.SetAssemblyFilters("+FluentAssertions"));
string link = TestResultsDirectory / "reports" / "index.html";
Information($"Code coverage report: \x1b]8;;file://{link.Replace('\\', '/')}\x1b\\{link}\x1b]8;;\x1b\\");
});

Target Coveralls => _ => _
.DependsOn(CodeCoverage)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
{
CoverallsNet(s => s
.SetRepoToken(GithubToken)
.SetInput(TestResultsDirectory / "reports" / "Cobertura.xml")
.EnableDynamicCodeCoverage());
});

Target TestFrameworks => _ => _
.DependsOn(Compile)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
Expand Down Expand Up @@ -240,9 +260,10 @@ class Build : NukeBuild
.DependsOn(ApiChecks)
.DependsOn(TestFrameworks)
.DependsOn(UnitTests)
.DependsOn(CodeCoverage)
.DependsOn(CodeCoverage, Coveralls)
.DependsOn(CalculateNugetVersion)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Produces(ArtifactsDirectory / "*.nupkg")
.Executes(() =>
{
DotNetPack(s => s
Expand All @@ -258,6 +279,7 @@ class Build : NukeBuild
Target Push => _ => _
.DependsOn(Pack)
.OnlyWhenDynamic(() => IsTag)
.ProceedAfterFailure()
.Executes(() =>
{
IReadOnlyCollection<string> packages = GlobFiles(ArtifactsDirectory, "*.nupkg");
Expand All @@ -275,6 +297,7 @@ class Build : NukeBuild

Target SpellCheck => _ => _
.OnlyWhenDynamic(() => RunAllTargets || HasDocumentationChanges)
.ProceedAfterFailure()
.Executes(() =>
{
Node($"{YarnCli} install", workingDirectory: RootDirectory);
Expand All @@ -283,7 +306,7 @@ class Build : NukeBuild
});

string YarnCli => $"{ToolPathResolver.GetPackageExecutable("Yarn.MSBuild", "yarn.js", "1.22.19")} --silent";

bool HasDocumentationChanges =>
Changes.Any(x => x.StartsWith("docs", StringComparison.InvariantCultureIgnoreCase));

Expand Down
55 changes: 55 additions & 0 deletions Build/CustomGitHubActionsAttribute.cs
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.CI.GitHubActions.Configuration;
using Nuke.Common.Execution;
using Nuke.Common.Utilities;

class CustomGitHubActionsAttribute : GitHubActionsAttribute
{
public CustomGitHubActionsAttribute(string name, GitHubActionsImage image, params GitHubActionsImage[] images) : base(name, image, images)
{
}

protected override GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyCollection<ExecutableTarget> relevantTargets)
{
var job = base.GetJobs(image, relevantTargets);

var newSteps = new List<GitHubActionsStep>(job.Steps);

// only need to list the ones that are missing from default image
newSteps.Insert(0, new GitHubActionsSetupDotNetStep("2.1.x", "3.1.x", "6.0.x", "7.0.x"));

job.Steps = newSteps.ToArray();
return job;
}
}

class GitHubActionsSetupDotNetStep : GitHubActionsStep
{
private string[] _versions { get; }
public GitHubActionsSetupDotNetStep(params string[] versions)
{
_versions = versions;
}

public override void Write(CustomFileWriter writer)
{
writer.WriteLine("- uses: actions/setup-dotnet@v3");

using (writer.Indent())
{
writer.WriteLine("with:");
using (writer.Indent())
{
writer.WriteLine("dotnet-version: |");
using (writer.Indent())
{
foreach (var version in _versions)
{
writer.WriteLine(version);
}
}
}
}
}
}
1 change: 1 addition & 0 deletions Build/_build.csproj
Expand Up @@ -17,6 +17,7 @@
<DefineConstants>OS_MAC</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageDownload Include="coveralls.net" Version="[4.0.1]" />
<PackageDownload Include="GitVersion.Tool" Version="[5.11.1]" />
<PackageDownload Include="NSpec" Version="[3.1.0]" />
<PackageDownload Include="ReportGenerator" Version="[5.1.13]" />
Expand Down

0 comments on commit 03bdcc4

Please sign in to comment.