Skip to content

Commit

Permalink
revert name change, add new IHaveCommonLintTargets to group common li… (
Browse files Browse the repository at this point in the history
#1310)

* revert name change, add new IHaveCommonLintTargets to group common linting tasks.

* Try to fix pr list of files..

* Automatically linting code

---------

Co-authored-by: Rocket Understudy <33589210+rsg-bot@users.noreply.github.com>
  • Loading branch information
david-driscoll and rsg-bot authored Sep 4, 2024
1 parent c862ff0 commit 6134894
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 107 deletions.
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 @@ -92,7 +92,7 @@ private static void WriteFileTreeWithEmoji(IEnumerable<AbsolutePath> 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);
}
);
Expand Down Expand Up @@ -126,9 +126,9 @@ private static void WriteFileTreeWithEmoji(IEnumerable<AbsolutePath> 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)
);
}
);
Expand Down Expand Up @@ -201,7 +201,10 @@ private LintPaths ResolveLintPathsImpl()
{
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 @@ private LintPaths ResolveLintPathsImpl()
? 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;

0 comments on commit 6134894

Please sign in to comment.