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

revert name change, add new IHaveCommonLintTargets to group common li… #1310

Merged
merged 3 commits into from
Sep 4, 2024
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
23 changes: 9 additions & 14 deletions .build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using JetBrains.Annotations;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.Execution;
Expand Down Expand Up @@ -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<Configuration>
{
/// <summary>
Expand Down Expand Up @@ -64,11 +59,6 @@ public static int Main()

public Target Build => _ => _;

[OptionalGitRepository]
public GitRepository? GitRepository { get; }

public Target Lint => _ => _.Inherit<ICanLint>(x => x.Lint);

public Target Pack => _ => _;


Expand All @@ -82,6 +72,11 @@ public static int Main()

public Target Test => _ => _;

[OptionalGitRepository]
public GitRepository? GitRepository { get; }

public Target Lint => _ => _.Inherit<ICanLint>(x => x.Lint);

[Parameter("Configuration to build")]
public Configuration Configuration { get; } = IsLocalBuild ? Configuration.Debug : Configuration.Release;
}
}
3 changes: 3 additions & 0 deletions src/Nuke/DotNetCore/ICanDotNetFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Rocket.Surgery.Nuke.DotNetCore;
/// <summary>
/// Defines the targets and properties for using DotNet Format
/// </summary>
[PublicAPI]
public interface ICanDotNetFormat : IHaveSolution, ICanLint, IHaveOutputLogs
{
private static Matcher? jbMatcher;
Expand Down Expand Up @@ -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(
() =>
Expand Down
93 changes: 93 additions & 0 deletions src/Nuke/ICanClean.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Nuke.Common.IO;
using Nuke.Common.Utilities.Collections;

// ReSharper disable SuspiciousTypeConversion.Global

namespace Rocket.Surgery.Nuke;

/// <summary>
/// Defines a target that cleans common directories
/// </summary>
[PublicAPI]
public interface ICanClean : IHaveCleanTarget, IHaveBuildTarget
{
/// <summary>
/// clean all artifact directories
/// </summary>
[NonEntryTarget]
public Target CleanWellKnownTemporaryFiles => d => d
.Before(Build)
.TryDependentFor<IHaveCleanTarget>(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
);
}
88 changes: 0 additions & 88 deletions src/Nuke/ICanCleanStuff.cs

This file was deleted.

13 changes: 8 additions & 5 deletions src/Nuke/ICanLint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[PublicAPI]
public interface ICanLint : IHaveGitRepository, IHaveLintTarget
{
static IEnumerable<string> FilterFiles(TreeChanges patch)

Check warning on line 18 in src/Nuke/ICanLint.cs

View workflow job for this annotation

GitHub Actions / lint

Missing XML comment for publicly visible type or member 'ICanLint.FilterFiles(TreeChanges)'

Check warning on line 18 in src/Nuke/ICanLint.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ICanLint.FilterFiles(TreeChanges)'
{
foreach (var item in patch)
{
Expand Down Expand Up @@ -92,7 +92,7 @@
.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);
}
);
Expand Down Expand Up @@ -126,9 +126,9 @@
_ = 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)
);
}
);
Expand Down Expand Up @@ -201,7 +201,10 @@
{
trigger = LintTrigger.PullRequest;
message = "Linting only the files in the Pull Request";
var diff = repo.Diff.Compare<TreeChanges>([$"origin/{GitHubActions.Instance.BaseRef}", $"origin/{GitHubActions.Instance.HeadRef}",]);
var diff = repo.Diff.Compare<TreeChanges>(
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<TreeChanges>(repo.Head.Tip?.Tree, DiffTargets.Index)).ToArray() is { Length: > 0, } stagedFiles)
Expand All @@ -215,4 +218,4 @@
? new(LintMatcher, trigger, message, files)
: new(LintMatcher, trigger, message, [] /*GitTasks.Git("ls-files", logOutput: false, logInvocation: false).Select(z => z.Text)*/);
}
}
}
14 changes: 14 additions & 0 deletions src/Nuke/IHaveCommonLintTargets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Rocket.Surgery.Nuke.DotNetCore;

namespace Rocket.Surgery.Nuke;

/// <summary>
/// Defines a target that cleans common directories
/// </summary>
public interface IHaveCommonLintTargets :
ICanDotNetFormat,
ICanPrettier,
IHavePublicApis,
ICanUpdateReadme,
ICanUpdateSolution,
ICanRegenerateBuildConfiguration;
Loading