diff --git a/.build/Build.cs b/.build/Build.cs index 6ac0b99b..1c408aba 100644 --- a/.build/Build.cs +++ b/.build/Build.cs @@ -1,4 +1,3 @@ -using JetBrains.Annotations; using Nuke.Common; using Nuke.Common.CI; using Nuke.Common.Execution; @@ -26,16 +25,12 @@ public partial class Pipeline : NukeBuild, ICanTestWithDotNetCore, ICanPackWithDotNetCore, IHaveDataCollector, - ICanCleanStuff, - ICanDotNetFormat, - ICanPrettier, - IHavePublicApis, - ICanUpdateReadme, - ICanUpdateSolution, + ICanClean, + IHaveCommonLintTargets, + // IHavePublicApis, IGenerateCodeCoverageReport, IGenerateCodeCoverageSummary, IGenerateCodeCoverageBadges, - ICanRegenerateBuildConfiguration, IHaveConfiguration { /// @@ -64,11 +59,6 @@ public static int Main() public Target Build => _ => _; - [OptionalGitRepository] - public GitRepository? GitRepository { get; } - - public Target Lint => _ => _.Inherit(x => x.Lint); - public Target Pack => _ => _; @@ -82,6 +72,11 @@ public static int Main() public Target Test => _ => _; + [OptionalGitRepository] + public GitRepository? GitRepository { get; } + + public Target Lint => _ => _.Inherit(x => x.Lint); + [Parameter("Configuration to build")] public Configuration Configuration { get; } = IsLocalBuild ? Configuration.Debug : Configuration.Release; -} +} \ No newline at end of file diff --git a/src/Nuke/DotNetCore/ICanDotNetFormat.cs b/src/Nuke/DotNetCore/ICanDotNetFormat.cs index d12dcef3..865b3c5b 100644 --- a/src/Nuke/DotNetCore/ICanDotNetFormat.cs +++ b/src/Nuke/DotNetCore/ICanDotNetFormat.cs @@ -11,6 +11,7 @@ namespace Rocket.Surgery.Nuke.DotNetCore; /// /// Defines the targets and properties for using DotNet Format /// +[PublicAPI] public interface ICanDotNetFormat : IHaveSolution, ICanLint, IHaveOutputLogs { private static Matcher? jbMatcher; @@ -110,6 +111,8 @@ public interface ICanDotNetFormat : IHaveSolution, ICanLint, IHaveOutputLogs .After(DotnetFormat) .Before(PostLint) .OnlyWhenStatic(() => DotNetTool.IsInstalled("jb")) + // disable for local stagged runs, as it takes a long time. + .OnlyWhenStatic(() => ( IsLocalBuild && LintPaths.Trigger != LintTrigger.Staged ) || !IsLocalBuild) .OnlyWhenDynamic(() => LintPaths.IsLocalLintOrMatches(JetBrainsCleanupCodeMatcher)) .Executes( () => diff --git a/src/Nuke/ICanClean.cs b/src/Nuke/ICanClean.cs new file mode 100644 index 00000000..94dc65fe --- /dev/null +++ b/src/Nuke/ICanClean.cs @@ -0,0 +1,93 @@ +using Nuke.Common.IO; +using Nuke.Common.Utilities.Collections; + +// ReSharper disable SuspiciousTypeConversion.Global + +namespace Rocket.Surgery.Nuke; + +/// +/// Defines a target that cleans common directories +/// +[PublicAPI] +public interface ICanClean : IHaveCleanTarget, IHaveBuildTarget +{ + /// + /// clean all artifact directories + /// + [NonEntryTarget] + public Target CleanWellKnownTemporaryFiles => d => d + .Before(Build) + .TryDependentFor(z => z.Clean) + .Executes( + () => + { + if (this is IHaveArtifacts artifacts) + { + _ = artifacts.ArtifactsDirectory.CreateOrCleanDirectory(); + if (artifacts is IHaveOutputLogs logs) + { + _ = logs.LogsDirectory.CreateDirectory(); + } + + if (artifacts is IHaveTestArtifacts testArtifacts) + { + _ = testArtifacts.TestResultsDirectory.CreateDirectory(); + } + + if (artifacts is IHaveNuGetPackages nuGetArtifacts) + { + _ = nuGetArtifacts.NuGetPackageDirectory.CreateDirectory(); + } + + if (artifacts is IHavePublishArtifacts publishArtifacts) + { + _ = publishArtifacts.PublishDirectory.CreateDirectory(); + } + + if (artifacts is IHaveOutputArtifacts outputArtifacts) + { + _ = outputArtifacts.OutputArtifactsDirectory.CreateDirectory(); + } + } + + if (this is IHaveCodeCoverage codeCoverage) + { + _ = codeCoverage.CoverageDirectory.CreateOrCleanDirectory(); + } + + // ReSharper disable SuspiciousTypeConversion.Global + if (this is not IMayTheForceBeWithYou forceBeWithYou || !forceBeWithYou.Force) + { + return; + } + + if (this is IComprehendSamples samples && samples.SampleDirectory.DirectoryExists()) + { + samples + .SampleDirectory.GlobDirectories("**/bin", "**/obj") + .ForEach(AbsolutePathExtensions.DeleteDirectory); + } + + if (this is IComprehendSources sources && sources.SourceDirectory.DirectoryExists()) + { + sources + .SourceDirectory.GlobDirectories("**/bin", "**/obj") + .ForEach(AbsolutePathExtensions.DeleteDirectory); + } + + if (this is IComprehendTemplates templates && templates.TemplatesDirectory.DirectoryExists()) + { + templates + .TemplatesDirectory.GlobDirectories("**/bin", "**/obj") + .ForEach(AbsolutePathExtensions.DeleteDirectory); + } + + if (this is IComprehendTests tests && tests.TestsDirectory.DirectoryExists()) + { + tests + .TestsDirectory.GlobDirectories("**/bin", "**/obj") + .ForEach(AbsolutePathExtensions.DeleteDirectory); + } + } // ReSharper restore SuspiciousTypeConversion.Global + ); +} \ No newline at end of file diff --git a/src/Nuke/ICanCleanStuff.cs b/src/Nuke/ICanCleanStuff.cs deleted file mode 100644 index 40fb9667..00000000 --- a/src/Nuke/ICanCleanStuff.cs +++ /dev/null @@ -1,88 +0,0 @@ -using Nuke.Common.IO; -using Nuke.Common.Utilities.Collections; -using Rocket.Surgery.Nuke.GithubActions; - -// ReSharper disable SuspiciousTypeConversion.Global - -namespace Rocket.Surgery.Nuke; - -/// -/// Defines a target that cleans common directories -/// -[PublicAPI] -public interface ICanCleanStuff : IHaveCleanTarget, IHaveBuildTarget -{ - /// - /// clean all artifact directories - /// - [NonEntryTarget] - public Target CleanWellKnownTemporaryFiles => d => d - .Before(Build) - .TryDependentFor(z => z.Clean) - .Executes( - () => - { - if (this is IHaveArtifacts artifacts) - { - _ = artifacts.ArtifactsDirectory.CreateOrCleanDirectory(); - if (artifacts is IHaveOutputLogs logs) - { - _ = logs.LogsDirectory.CreateDirectory(); - } - - if (artifacts is IHaveTestArtifacts testArtifacts) - { - _ = testArtifacts.TestResultsDirectory.CreateDirectory(); - } - - if (artifacts is IHaveNuGetPackages nuGetArtifacts) - { - _ = nuGetArtifacts.NuGetPackageDirectory.CreateDirectory(); - } - - if (artifacts is IHavePublishArtifacts publishArtifacts) - { - _ = publishArtifacts.PublishDirectory.CreateDirectory(); - } - - if (artifacts is IHaveOutputArtifacts outputArtifacts) - { - _ = outputArtifacts.OutputArtifactsDirectory.CreateDirectory(); - } - } - - if (this is IHaveCodeCoverage codeCoverage) - { - _ = codeCoverage.CoverageDirectory.CreateOrCleanDirectory(); - } - - // ReSharper disable SuspiciousTypeConversion.Global - if (this is not IMayTheForceBeWithYou forceBeWithYou || !forceBeWithYou.Force) - { - return; - } - - if (this is IComprehendSamples samples && samples.SampleDirectory.DirectoryExists()) - { - samples.SampleDirectory.GlobDirectories("**/bin", "**/obj").ForEach(AbsolutePathExtensions.DeleteDirectory); - } - - if (this is IComprehendSources sources && sources.SourceDirectory.DirectoryExists()) - { - sources.SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(AbsolutePathExtensions.DeleteDirectory); - } - - if (this is IComprehendTemplates templates && templates.TemplatesDirectory.DirectoryExists()) - { - templates - .TemplatesDirectory.GlobDirectories("**/bin", "**/obj") - .ForEach(AbsolutePathExtensions.DeleteDirectory); - } - - if (this is IComprehendTests tests && tests.TestsDirectory.DirectoryExists()) - { - tests.TestsDirectory.GlobDirectories("**/bin", "**/obj").ForEach(AbsolutePathExtensions.DeleteDirectory); - } - } // ReSharper restore SuspiciousTypeConversion.Global - ); -} diff --git a/src/Nuke/ICanLint.cs b/src/Nuke/ICanLint.cs index 823dc335..093e7382 100644 --- a/src/Nuke/ICanLint.cs +++ b/src/Nuke/ICanLint.cs @@ -92,7 +92,7 @@ private static void WriteFileTreeWithEmoji(IEnumerable stagedFiles .Executes( () => { - Log.Information("Linting {Count} files with trigger {Trigger}", LintPaths.Paths.Count(), LintPaths.Trigger); + Log.Information("Linting {Count} files with trigger {Trigger}", LintPaths.Paths.Length, LintPaths.Trigger); WriteFileTreeWithEmoji(LintPaths.Paths); } ); @@ -126,9 +126,9 @@ private static void WriteFileTreeWithEmoji(IEnumerable stagedFiles _ = tool( "run --group lint", logOutput: true, + logInvocation: Verbosity == Verbosity.Verbose, // ReSharper disable once TemplateIsNotCompileTimeConstantProblem - logger: static (t, s) => Log.Write(t == OutputType.Err ? LogEventLevel.Error : LogEventLevel.Information, s), - logInvocation: Verbosity == Verbosity.Verbose + logger: static (t, s) => Log.Write(t == OutputType.Err ? LogEventLevel.Error : LogEventLevel.Information, s) ); } ); @@ -201,7 +201,10 @@ private LintPaths ResolveLintPathsImpl() { trigger = LintTrigger.PullRequest; message = "Linting only the files in the Pull Request"; - var diff = repo.Diff.Compare([$"origin/{GitHubActions.Instance.BaseRef}", $"origin/{GitHubActions.Instance.HeadRef}",]); + var diff = repo.Diff.Compare( + repo.Branches[$"origin/{GitHubActions.Instance.BaseRef}"].Tip.Tree, + repo.Branches[$"origin/{GitHubActions.Instance.HeadRef}"].Tip.Tree + ); files.AddRange(FilterFiles(diff)); } else if (IsLocalBuild && FilterFiles(repo.Diff.Compare(repo.Head.Tip?.Tree, DiffTargets.Index)).ToArray() is { Length: > 0, } stagedFiles) @@ -215,4 +218,4 @@ private LintPaths ResolveLintPathsImpl() ? new(LintMatcher, trigger, message, files) : new(LintMatcher, trigger, message, [] /*GitTasks.Git("ls-files", logOutput: false, logInvocation: false).Select(z => z.Text)*/); } -} +} \ No newline at end of file diff --git a/src/Nuke/IHaveCommonLintTargets.cs b/src/Nuke/IHaveCommonLintTargets.cs new file mode 100644 index 00000000..4640780f --- /dev/null +++ b/src/Nuke/IHaveCommonLintTargets.cs @@ -0,0 +1,14 @@ +using Rocket.Surgery.Nuke.DotNetCore; + +namespace Rocket.Surgery.Nuke; + +/// +/// Defines a target that cleans common directories +/// +public interface IHaveCommonLintTargets : + ICanDotNetFormat, + ICanPrettier, + IHavePublicApis, + ICanUpdateReadme, + ICanUpdateSolution, + ICanRegenerateBuildConfiguration; \ No newline at end of file