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()) - { - item.IncludePaths = LocalConstants.PathsIgnore; - } - - configuration.Jobs.RemoveAt(1); ( (RocketSurgeonsGithubActionsJob)configuration.Jobs[0] ).Steps = new List { 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()) - { - item.ExcludePaths = LocalConstants.PathsIgnore; - } - - var buildJob = configuration.Jobs.OfType().First(z => z.Name == "Build"); - buildJob.FailFast = false; - var checkoutStep = buildJob.Steps.OfType().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 - { - ["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() + .First(z => z.Name == "Build") + .UseDotNetSdks("3.1", "6.0") + .AddNuGetCache() + // .ConfigureForGitVersion() + .ConfigureStep(step => step.FetchDepth = 0) + .PublishLogs() + .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 +public partial class Pipeline : NukeBuild, + ICanRestoreWithDotNetCore, + ICanBuildWithDotNetCore, + ICanTestWithDotNetCore, + IComprehendSamples, + IHaveNuGetPackages, + IHaveDataCollector, + ICanClean, + ICanUpdateReadme, + IGenerateCodeCoverageReport, + IGenerateCodeCoverageSummary, + IGenerateCodeCoverageBadges, + IHaveConfiguration { /// /// Support plugins are available for: @@ -48,7 +47,7 @@ public partial class BuildSolution : NukeBuild, /// public static int Main() { - return Execute(x => x.Default); + return Execute(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(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(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(x => x.CoreBuild); public Target Clean => _ => _.Inherit(x => x.Clean); public Target Restore => _ => _.Inherit(x => x.CoreRestore); + Nuke.Common.ProjectModel.Solution IHaveSolution.Solution => Solution; + [ComputedGitVersion] public GitVersion GitVersion { get; } = null!; public Target Test => _ => _.Inherit(x => x.CoreTest); - [Parameter("Configuration to build")] public Configuration Configuration { get; } = IsLocalBuild ? Configuration.Debug : Configuration.Release; } - -public static class Extensions -{ - public static T As(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