diff --git a/.build/Build.CI.cs b/.build/Build.CI.cs index d22ae5d34..6bfec0279 100644 --- a/.build/Build.CI.cs +++ b/.build/Build.CI.cs @@ -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, @@ -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") @@ -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; } diff --git a/.build/Build.cs b/.build/Build.cs index cdcd5451c..0162b7a6e 100644 --- a/.build/Build.cs +++ b/.build/Build.cs @@ -13,7 +13,6 @@ using Nuke.Common.Tools.MSBuild; using Rocket.Surgery.Nuke.DotNetCore; using Serilog; -using NukeSolution = Nuke.Common.ProjectModel.Solution; [PublicAPI] [CheckBuildProjectConfigurations] @@ -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: @@ -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() @@ -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); @@ -172,7 +168,7 @@ public static int FindFreePort() } ); - [Solution(GenerateProjects = true)] private NukeSolution Solution { get; } = null!; + [OptionalGitRepository] public GitRepository? GitRepository { get; } private Target Default => _ => _ .DependsOn(Restore) @@ -180,22 +176,14 @@ public static int FindFreePort() .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; - } -} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5a1e1a66..65e0cfe1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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 @@ -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 diff --git a/Directory.Packages.props b/Directory.Packages.props index 4ef814794..16e0d8765 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -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" />