Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated build pipeline naming, and added strongly typed solution #1144

Merged
merged 2 commits into from
Jun 10, 2022
Merged
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
146 changes: 15 additions & 131 deletions .build/Build.CI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,6 @@

#pragma warning disable CA1050

internal class LocalConstants
{
public static string[] PathsIgnore =
{
".codecov.yml",
".editorconfig",
".gitattributes",
".gitignore",
".gitmodules",
".lintstagedrc.js",
".prettierignore",
".prettierrc",
"LICENSE",
"nukeeper.settings.json",
"omnisharp.json",
"package-lock.json",
"package.json",
"Readme.md",
".github/dependabot.yml",
".github/labels.yml",
".github/release.yml",
".github/renovate.json",
};
}

[GitHubActionsSteps(
"ci-ignore",
GitHubActionsImage.WindowsLatest,
Expand Down Expand Up @@ -71,18 +46,10 @@ internal class LocalConstants
[UploadLogs]
[TitleEvents]
[ContinuousIntegrationConventions]
public partial class BuildSolution
public partial class Pipeline
{
public static RocketSurgeonGitHubActionsConfiguration CiIgnoreMiddleware(
RocketSurgeonGitHubActionsConfiguration configuration
)
public static RocketSurgeonGitHubActionsConfiguration CiIgnoreMiddleware(RocketSurgeonGitHubActionsConfiguration configuration)
{
foreach (var item in configuration.DetailedTriggers.OfType<RocketSurgeonGitHubActionsVcsTrigger>())
{
item.IncludePaths = LocalConstants.PathsIgnore;
}

configuration.Jobs.RemoveAt(1);
( (RocketSurgeonsGithubActionsJob)configuration.Jobs[0] ).Steps = new List<GitHubActionsStep>
{
new RunStep("N/A")
Expand All @@ -91,105 +58,22 @@ RocketSurgeonGitHubActionsConfiguration configuration
}
};

return configuration;
return configuration.IncludeRepositoryConfigurationFiles();
}

public static RocketSurgeonGitHubActionsConfiguration CiMiddleware(
RocketSurgeonGitHubActionsConfiguration configuration
)
public static RocketSurgeonGitHubActionsConfiguration CiMiddleware(RocketSurgeonGitHubActionsConfiguration configuration)
{
foreach (var item in configuration.DetailedTriggers.OfType<RocketSurgeonGitHubActionsVcsTrigger>())
{
item.ExcludePaths = LocalConstants.PathsIgnore;
}

var buildJob = configuration.Jobs.OfType<RocketSurgeonsGithubActionsJob>().First(z => z.Name == "Build");
buildJob.FailFast = false;
var checkoutStep = buildJob.Steps.OfType<CheckoutStep>().Single();
// For fetch all
checkoutStep.FetchDepth = 0;
buildJob.Environment["NUGET_PACKAGES"] = "${{ github.workspace }}/.nuget/packages";
buildJob.Steps.InsertRange(
buildJob.Steps.IndexOf(checkoutStep) + 1,
new BaseGitHubActionsStep[]
{
new RunStep("Fetch all history for all tags and branches")
{
Run = "git fetch --prune"
},
new UsingStep("NuGet Cache")
{
Uses = "actions/cache@v2",
With =
{
["path"] = "${{ github.workspace }}/.nuget/packages",
// keep in mind using central package versioning here
["key"] =
"${{ runner.os }}-nuget-${{ hashFiles('**/Directory.Packages.props') }}-${{ hashFiles('**/Directory.Packages.support.props') }}",
["restore-keys"] = @"|
${{ runner.os }}-nuget-"
}
},
new SetupDotNetStep("Use .NET Core 3.1 SDK")
{
DotNetVersion = "3.1.x"
},
new SetupDotNetStep("Use .NET Core 6.0 SDK")
{
DotNetVersion = "6.0.x"
}
}
);

buildJob.Steps.Add(
new UsingStep("Publish Coverage")
{
Uses = "codecov/codecov-action@v1",
If = new(
"(github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || ((github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.pull_request.user.login != 'renovate[bot]' && github.event.pull_request.user.login != 'dependabot[bot]')"
),
With = new Dictionary<string, string>
{
["name"] = "actions-${{ matrix.os }}",
}
}
);

buildJob.Steps.Add(
new UploadArtifactStep("Publish logs")
{
Name = "logs",
Path = "artifacts/logs/",
If = "always()"
}
);

buildJob.Steps.Add(
new UploadArtifactStep("Publish coverage data")
{
Name = "coverage",
Path = "coverage/",
If = "always()"
}
);

buildJob.Steps.Add(
new UploadArtifactStep("Publish test data")
{
Name = "test data",
Path = "artifacts/test/",
If = "always()"
}
);

buildJob.Steps.Add(
new UploadArtifactStep("Publish NuGet Packages")
{
Name = "nuget",
Path = "artifacts/nuget/",
If = "always()"
}
);
configuration
.ExcludeRepositoryConfigurationFiles()
.AddNugetPublish()
.Jobs.OfType<RocketSurgeonsGithubActionsJob>()
.First(z => z.Name == "Build")
.UseDotNetSdks("3.1", "6.0")
.AddNuGetCache()
// .ConfigureForGitVersion()
.ConfigureStep<CheckoutStep>(step => step.FetchDepth = 0)
.PublishLogs<Pipeline>()
.FailFast = false;

return configuration;
}
Expand Down
50 changes: 19 additions & 31 deletions .build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Nuke.Common.Tools.MSBuild;
using Rocket.Surgery.Nuke.DotNetCore;
using Serilog;
using NukeSolution = Nuke.Common.ProjectModel.Solution;

[PublicAPI]
[CheckBuildProjectConfigurations]
Expand All @@ -25,19 +24,19 @@
[MSBuildVerbosityMapping]
[NuGetVerbosityMapping]
[ShutdownDotNetAfterServerBuild]
public partial class BuildSolution : NukeBuild,
ICanRestoreWithDotNetCore,
ICanBuildWithDotNetCore,
ICanTestWithDotNetCore,
IComprehendSamples,
IHaveNuGetPackages,
IHaveDataCollector,
ICanClean,
ICanUpdateReadme,
IGenerateCodeCoverageReport,
IGenerateCodeCoverageSummary,
IGenerateCodeCoverageBadges,
IHaveConfiguration<Configuration>
public partial class Pipeline : NukeBuild,
ICanRestoreWithDotNetCore,
ICanBuildWithDotNetCore,
ICanTestWithDotNetCore,
IComprehendSamples,
IHaveNuGetPackages,
IHaveDataCollector,
ICanClean,
ICanUpdateReadme,
IGenerateCodeCoverageReport,
IGenerateCodeCoverageSummary,
IGenerateCodeCoverageBadges,
IHaveConfiguration<Configuration>
{
/// <summary>
/// Support plugins are available for:
Expand All @@ -48,7 +47,7 @@ public partial class BuildSolution : NukeBuild,
/// </summary>
public static int Main()
{
return Execute<BuildSolution>(x => x.Default);
return Execute<Pipeline>(x => x.Default);
}

public static int FindFreePort()
Expand All @@ -69,9 +68,6 @@ public static int FindFreePort()

return port;
}

[OptionalGitRepository] public GitRepository? GitRepository { get; }

// public Target Pack => _ => _.Inherit<ICanPackWithDotNetCore>(x => x.CorePack)
// .DependsOn(Clean);

Expand Down Expand Up @@ -172,30 +168,22 @@ public static int FindFreePort()
}
);

[Solution(GenerateProjects = true)] private NukeSolution Solution { get; } = null!;
[OptionalGitRepository] public GitRepository? GitRepository { get; }

private Target Default => _ => _
.DependsOn(Restore)
.DependsOn(Build)
.DependsOn(Test)
.DependsOn(Pack);

public Target Build => _ => _.Inherit<ICanBuildWithDotNetCore>(x => x.CoreBuild);
NukeSolution IHaveSolution.Solution => Solution;
[Solution(GenerateProjects = true)] private Solution Solution { get; } = null!;

[ComputedGitVersion] public GitVersion GitVersion { get; } = null!;
public Target Build => _ => _.Inherit<ICanBuildWithDotNetCore>(x => x.CoreBuild);

public Target Clean => _ => _.Inherit<ICanClean>(x => x.Clean);
public Target Restore => _ => _.Inherit<ICanRestoreWithDotNetCore>(x => x.CoreRestore);
Nuke.Common.ProjectModel.Solution IHaveSolution.Solution => Solution;
[ComputedGitVersion] public GitVersion GitVersion { get; } = null!;
public Target Test => _ => _.Inherit<ICanTestWithDotNetCore>(x => x.CoreTest);

[Parameter("Configuration to build")] public Configuration Configuration { get; } = IsLocalBuild ? Configuration.Debug : Configuration.Release;
}

public static class Extensions
{
public static T As<T>(this T value)
{
return value;
}
}
15 changes: 6 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ jobs:
with:
clean: 'false'
fetch-depth: '0'
- name: Fetch all history for all tags and branches
run: |
git fetch --prune
- name: NuGet Cache
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -119,6 +116,12 @@ jobs:
- name: 📦 Pack
run: |
dotnet nuke Pack --skip
- name: 🏺 Publish coverage data
if: always()
uses: actions/upload-artifact@v3.1.0
with:
name: 'coverage'
path: 'coverage/'
- name: 🐿 Publish Coverage
if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || ((github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.pull_request.user.login != 'renovate[bot]' && github.event.pull_request.user.login != 'dependabot[bot]')
uses: codecov/codecov-action@v3.1.0
Expand All @@ -130,12 +133,6 @@ jobs:
with:
name: 'logs'
path: 'artifacts/logs/'
- name: 🏺 Publish coverage data
if: always()
uses: actions/upload-artifact@v3.1.0
with:
name: 'coverage'
path: 'coverage/'
- name: 🏺 Publish test data
if: always()
uses: actions/upload-artifact@v3.1.0
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageVersion Include="JetBrains.ReSharper.GlobalTools" Version="2022.1.2" />
<PackageVersion Include="Nuke.Common" Version="6.0.3" />
<PackageVersion Include="ReportGenerator" Version="5.1.9" />
<PackageVersion Include="Rocket.Surgery.Nuke" Version="0.17.12" />
<PackageVersion Include="Rocket.Surgery.Nuke" Version="0.17.14" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
Expand Down