Skip to content

Commit

Permalink
fixing up lint targets with a minor tweaks. (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll authored Sep 6, 2024
1 parent c3384cc commit 1d493a6
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 91 deletions.
3 changes: 2 additions & 1 deletion .build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static int Main()
[Parameter]
public string? GitHubToken { get; }

[NonEntryTarget]
private Target Default => _ => _
.DependsOn(Restore)
.DependsOn(Build)
Expand Down Expand Up @@ -75,7 +76,7 @@ public static int Main()
[OptionalGitRepository]
public GitRepository? GitRepository { get; }

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

[Parameter("Configuration to build")]
public Configuration Configuration { get; } = IsLocalBuild ? Configuration.Debug : Configuration.Release;
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ jobs:
id: restore
run: |
dotnet nuke DotnetCoreRestore Restore --skip --ThisIsAOtherVariable "${{ vars.THIS_IS_A_VARIABLE }}" --ThisIsAnotherVariable "${{ vars.THIS_IS_ANOTHER_VARIABLE }}" --THIS_IS_A_VARIABLE "${{ vars.THIS_IS_A_VARIABLE }}" --ThisIsAEnv "${{ env.THIS_IS_A_ENV || 'test' }}" --ThisIsASecret "${{ secrets.THIS_IS_A_SECRET }}" --GitHubToken "${{ secrets.GITHUB_TOKEN }}"
- name: Lint
id: lint
- name: Lint Files
id: lintFiles
run: |
dotnet nuke Lint --skip --ThisIsAOtherVariable "${{ vars.THIS_IS_A_VARIABLE }}" --ThisIsAnotherVariable "${{ vars.THIS_IS_ANOTHER_VARIABLE }}" --THIS_IS_A_VARIABLE "${{ vars.THIS_IS_A_VARIABLE }}" --ThisIsAEnv "${{ env.THIS_IS_A_ENV || 'test' }}" --ThisIsASecret "${{ secrets.THIS_IS_A_SECRET }}" --GitHubToken "${{ secrets.GITHUB_TOKEN }}"
dotnet nuke LintFiles --skip --ThisIsAOtherVariable "${{ vars.THIS_IS_A_VARIABLE }}" --ThisIsAnotherVariable "${{ vars.THIS_IS_ANOTHER_VARIABLE }}" --THIS_IS_A_VARIABLE "${{ vars.THIS_IS_A_VARIABLE }}" --ThisIsAEnv "${{ env.THIS_IS_A_ENV || 'test' }}" --ThisIsASecret "${{ secrets.THIS_IS_A_SECRET }}" --GitHubToken "${{ secrets.GITHUB_TOKEN }}"
- name: Lint Public Api Analyzers
id: lintPublicApiAnalyzers
run: |
Expand Down
2 changes: 2 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"HuskyLint",
"JetBrainsCleanupCode",
"Lint",
"LintFiles",
"LintGitAdd",
"LintPublicApiAnalyzers",
"MoveUnshippedToShipped",
Expand Down Expand Up @@ -159,6 +160,7 @@
"HuskyLint",
"JetBrainsCleanupCode",
"Lint",
"LintFiles",
"LintGitAdd",
"LintPublicApiAnalyzers",
"MoveUnshippedToShipped",
Expand Down
4 changes: 1 addition & 3 deletions src/Nuke/ContinuousIntegration/ICIEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Rocket.Surgery.Nuke.GithubActions;
using Serilog;

namespace Rocket.Surgery.Nuke.ContinuousIntegration;
Expand Down Expand Up @@ -28,7 +27,6 @@ public interface ICIEnvironment : IHaveBuildVersion
/// </summary>
[NonEntryTarget]
public Target CIEnvironment => d => d
.TriggeredBy(BuildVersion)
.Unlisted()
.OnlyWhenStatic(() => NukeBuild.IsServerBuild)
.Executes(
Expand All @@ -47,4 +45,4 @@ public interface ICIEnvironment : IHaveBuildVersion
}
}
);
}
}
21 changes: 11 additions & 10 deletions src/Nuke/ICanLint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,17 @@ private static void WriteFileTreeWithEmoji(IEnumerable<AbsolutePath> stagedFiles
/// <summary>
/// The lint target
/// </summary>
public new Target Lint => t => t
.OnlyWhenDynamic(() => LintPaths.Active)
.TryDependsOn<IHaveRestoreTarget>(a => a.Restore)
.Executes(
() =>
{
Log.Information("Linting {Count} files with trigger {Trigger}", LintPaths.Paths.Length, LintPaths.Trigger);
WriteFileTreeWithEmoji(LintPaths.Paths);
}
);
public Target LintFiles => t => t
.OnlyWhenDynamic(() => LintPaths.Active)
.TryDependsOn<IHaveRestoreTarget>(a => a.Restore)
.TryDependentFor<IHaveLintTarget>(a => a.Lint)
.Executes(
() =>
{
Log.Information("Linting {Count} files with trigger {Trigger}", LintPaths.Paths.Length, LintPaths.Trigger);
WriteFileTreeWithEmoji(LintPaths.Paths);
}
);

/// <summary>
/// A lint target that runs last
Expand Down
4 changes: 2 additions & 2 deletions src/Nuke/IGenerateCodeCoverageBadges.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Nuke.Common.IO;
using Nuke.Common.Tools.ReportGenerator;
using Rocket.Surgery.Nuke.GithubActions;

namespace Rocket.Surgery.Nuke;

/// <summary>
/// Generates a code coverage badges
/// </summary>
[PublicAPI]
public interface IGenerateCodeCoverageBadges : ITriggerCodeCoverageReports, IGenerate
{
/// <summary>
Expand All @@ -30,4 +30,4 @@ public interface IGenerateCodeCoverageBadges : ITriggerCodeCoverageReports, IGen
.SetReportTypes(ReportTypes.Badges)
)
);
}
}
4 changes: 2 additions & 2 deletions src/Nuke/IGenerateCodeCoverageReport.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Nuke.Common.IO;
using Nuke.Common.Tools.ReportGenerator;
using Rocket.Surgery.Nuke.GithubActions;

namespace Rocket.Surgery.Nuke;

/// <summary>
/// Defines a task that generates a code coverage report from a given set of report documents
/// </summary>
[PublicAPI]
public interface IGenerateCodeCoverageReport : ITriggerCodeCoverageReports, IGenerate
{
/// <summary>
Expand All @@ -30,4 +30,4 @@ public interface IGenerateCodeCoverageReport : ITriggerCodeCoverageReports, IGen
.SetReportTypes(ReportTypes.HtmlInline_AzurePipelines_Dark)
)
);
}
}
4 changes: 2 additions & 2 deletions src/Nuke/IGenerateCodeCoverageSummary.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Nuke.Common.IO;
using Nuke.Common.Tools.ReportGenerator;
using Rocket.Surgery.Nuke.GithubActions;

namespace Rocket.Surgery.Nuke;

/// <summary>
/// Generates a code coverage summary
/// </summary>
[PublicAPI]
public interface IGenerateCodeCoverageSummary : ITriggerCodeCoverageReports, IGenerate
{
/// <summary>
Expand Down Expand Up @@ -34,4 +34,4 @@ public interface IGenerateCodeCoverageSummary : ITriggerCodeCoverageReports, IGe
)
)
);
}
}
46 changes: 23 additions & 23 deletions src/Nuke/IGenerateDocFx.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Rocket.Surgery.Nuke.GithubActions;

namespace Rocket.Surgery.Nuke;

/// <summary>
/// Interface used during docs generation
/// </summary>
public interface IGenerateDocFx : IHaveDocs, IHaveGenerateDocumentationTarget
[PublicAPI]
public interface IGenerateDocFx : IHaveDocs
{
/// <summary>
/// Parameter to be used to serve documentation
/// </summary>
[Parameter("serve the docs")]
public bool? Serve => EnvironmentInfo.GetVariable<bool?>("Serve")
// ?? ValueInjectionUtility.TryGetValue(() => Serve)
// ?? ValueInjectionUtility.TryGetValue(() => Serve)
?? false;

/// <summary>
Expand All @@ -27,25 +27,25 @@ public interface IGenerateDocFx : IHaveDocs, IHaveGenerateDocumentationTarget
/// </summary>
[NonEntryTarget]
public Target GenerateDocFx => d => d
.TryDependentFor<IHaveGenerateDocumentationTarget>(z => z.GenerateDocumentation)
.OnlyWhenStatic(() => DocumentationDirectory.DirectoryExists())
.OnlyWhenStatic(() => ( DocumentationDirectory / "docfx.json" ).FileExists())
.Executes(
() =>
{
if (Serve == true)
{
Task.Run(() => Docfx($"{DocumentationDirectory / "docfx.json"} --serve"));
.TryDependentFor<IHaveDocs>(z => z.Docs)
.OnlyWhenStatic(() => DocumentationDirectory.DirectoryExists())
.OnlyWhenStatic(() => ( DocumentationDirectory / "docfx.json" ).FileExists())
.Executes(
() =>
{
if (Serve == true)
{
Task.Run(() => Docfx($"{DocumentationDirectory / "docfx.json"} --serve"));

var watcher = new FileSystemWatcher(DocumentationDirectory) { EnableRaisingEvents = true, };
while (true)
{
watcher.WaitForChanged(WatcherChangeTypes.All);
Docfx($"{DocumentationDirectory / "docfx.json"}");
}
}
var watcher = new FileSystemWatcher(DocumentationDirectory) { EnableRaisingEvents = true, };
while (true)
{
watcher.WaitForChanged(WatcherChangeTypes.All);
Docfx($"{DocumentationDirectory / "docfx.json"}");
}
}

Docfx($"{DocumentationDirectory / "docfx.json"}");
}
);
}
Docfx($"{DocumentationDirectory / "docfx.json"}");
}
);
}
15 changes: 1 addition & 14 deletions src/Nuke/IHaveBuildTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,4 @@ public interface IHaveBuildTarget : IHave
/// The Build Target
/// </summary>
Target Build { get; }
}


/// <summary>
/// Defines the build target
/// </summary>
public interface IHaveGenerateDocumentationTarget : IHave
{
/// <summary>
/// The Build Target
/// </summary>
Target GenerateDocumentation { get; }
}

}
29 changes: 14 additions & 15 deletions src/Nuke/IHaveBuildVersion.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
using Rocket.Surgery.Nuke.GithubActions;
using Serilog;

namespace Rocket.Surgery.Nuke;

/// <summary>
/// Defines a build version target
/// </summary>
[PublicAPI]
public interface IHaveBuildVersion : IHaveGitVersion, IHaveSolution, IHaveConfiguration
{
/// <summary>
/// prints the build information.
/// </summary>
[NonEntryTarget]
public Target BuildVersion => d => d
.Executes(
() =>
{
Log.Information(
"Building version {NuGetVersion} of {SolutionName} ({Configuration}) using version {NukeVersion} of Nuke",
GitVersion.NuGetVersionV2 ?? GitVersion.NuGetVersion,
Solution.Name,
Configuration,
typeof(NukeBuild).Assembly.GetVersionText()
);
}
);
}
.Executes(
() =>
{
Log.Information(
"Building version {NuGetVersion} of {SolutionName} ({Configuration}) using version {NukeVersion} of Nuke",
GitVersion.NuGetVersionV2 ?? GitVersion.NuGetVersion,
Solution.Name,
Configuration,
typeof(NukeBuild).Assembly.GetVersionText()
);
}
);
}
14 changes: 1 addition & 13 deletions src/Nuke/IHaveCleanTarget.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Rocket.Surgery.Nuke.GithubActions;

namespace Rocket.Surgery.Nuke;

/// <summary>
Expand All @@ -12,14 +10,4 @@ public interface IHaveCleanTarget : IHave
/// </summary>
[ExcludeTarget]
Target Clean { get; }
}
/// <summary>
/// Defines a clean target
/// </summary>
public interface IHaveLintTarget : IHave
{
/// <summary>
/// The Lint Target
/// </summary>
Target Lint { get; }
}
}
8 changes: 7 additions & 1 deletion src/Nuke/IHaveDocs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ namespace Rocket.Surgery.Nuke;
/// <summary>
/// Interface for a build that has documentation generation
/// </summary>
[PublicAPI]
public interface IHaveDocs : IHaveArtifacts
{
/// <summary>
/// The Build Target
/// </summary>
Target Docs { get; }

/// <summary>
/// Where the docs are stored
/// </summary>
Expand All @@ -16,4 +22,4 @@ public interface IHaveDocs : IHaveArtifacts
/// Where the docs are output
/// </summary>
public AbsolutePath DocumentationsOutputDirectory => ArtifactsDirectory / "docs";
}
}
13 changes: 13 additions & 0 deletions src/Nuke/IHaveLintTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Rocket.Surgery.Nuke;

/// <summary>
/// Defines a clean target
/// </summary>
public interface IHaveLintTarget : IHave
{
/// <summary>
/// The Lint Target
/// </summary>
[NonEntryTarget]
Target Lint { get; }
}
4 changes: 2 additions & 2 deletions src/Nuke/ITriggerCodeCoverageReports.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Nuke.Common.IO;
using Nuke.Common.Tools.ReportGenerator;
using Rocket.Surgery.Nuke.GithubActions;
using static Nuke.Common.IO.FileSystemTasks;

// ReSharper disable SuspiciousTypeConversion.Global
Expand All @@ -13,6 +12,7 @@ namespace Rocket.Surgery.Nuke;
/// <remarks>
/// This causes code coverage to trigger
/// </remarks>
[PublicAPI]
public interface ITriggerCodeCoverageReports : IHaveCodeCoverage, IHaveTestTarget, ITrigger
{
/// <summary>
Expand Down Expand Up @@ -113,4 +113,4 @@ protected ReportGeneratorSettings Defaults(ReportGeneratorSettings settings)
.SetFramework(Constants.ReportGeneratorFramework)
;
}
}
}

0 comments on commit 1d493a6

Please sign in to comment.