Skip to content

Commit

Permalink
Automatically linting code
Browse files Browse the repository at this point in the history
  • Loading branch information
rsg-bot authored Sep 10, 2024
1 parent edabb4c commit 523365b
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 119 deletions.
114 changes: 48 additions & 66 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -1,69 +1,51 @@
{
"version": 1,
"isRoot": true,
"tools": {
"gitversion.tool": {
"version": "6.0.2",
"commands": [
"dotnet-gitversion"
],
"rollForward": false
},
"dotnet-reportgenerator-globaltool": {
"version": "5.3.9",
"commands": [
"reportgenerator"
],
"rollForward": false
},
"nuke.globaltool": {
"version": "8.1.0",
"commands": [
"nuke"
],
"rollForward": false
},
"codecov.tool": {
"version": "1.13.0",
"commands": [
"codecov"
],
"rollForward": false
},
"jetbrains.resharper.globaltools": {
"version": "2024.2.4",
"commands": [
"jb"
],
"rollForward": false
},
"nukeeper": {
"version": "0.35.0",
"commands": [
"nukeeper"
],
"rollForward": false
},
"dotnet-outdated-tool": {
"version": "4.6.4",
"commands": [
"dotnet-outdated"
],
"rollForward": false
},
"husky": {
"version": "0.7.1",
"commands": [
"husky"
],
"rollForward": false
},
"liquidtestreports.cli": {
"version": "2.0.0-beta.2",
"commands": [
"liquid"
],
"rollForward": false
"version": 1,
"isRoot": true,
"tools": {
"gitversion.tool": {
"version": "6.0.2",
"commands": ["dotnet-gitversion"],
"rollForward": false
},
"dotnet-reportgenerator-globaltool": {
"version": "5.3.9",
"commands": ["reportgenerator"],
"rollForward": false
},
"nuke.globaltool": {
"version": "8.1.0",
"commands": ["nuke"],
"rollForward": false
},
"codecov.tool": {
"version": "1.13.0",
"commands": ["codecov"],
"rollForward": false
},
"jetbrains.resharper.globaltools": {
"version": "2024.2.4",
"commands": ["jb"],
"rollForward": false
},
"nukeeper": {
"version": "0.35.0",
"commands": ["nukeeper"],
"rollForward": false
},
"dotnet-outdated-tool": {
"version": "4.6.4",
"commands": ["dotnet-outdated"],
"rollForward": false
},
"husky": {
"version": "0.7.1",
"commands": ["husky"],
"rollForward": false
},
"liquidtestreports.cli": {
"version": "2.0.0-beta.2",
"commands": ["liquid"],
"rollForward": false
}
}
}
}
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>

<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
Expand Down Expand Up @@ -55,6 +56,5 @@
</ItemGroup>
<Import
Project="$(MSBuildThisFileDirectory)/Directory.Packages.support.props"
Condition="Exists('$(MSBuildThisFileDirectory)/Directory.Packages.support.props')"
/>
</Project>
Condition="Exists('$(MSBuildThisFileDirectory)/Directory.Packages.support.props')" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.Execution;
using Nuke.Common.IO;
Expand All @@ -12,50 +13,20 @@ namespace Rocket.Surgery.Nuke.ContinuousIntegration;
[PublicAPI]
#pragma warning disable CA1813
[AttributeUsage(AttributeTargets.Class)]
[System.Diagnostics.DebuggerDisplay("{DebuggerDisplay,nq}")]
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class ContinuousIntegrationConventionsAttribute : BuildExtensionAttributeBase, IOnBuildFinished
#pragma warning restore CA1813
{
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private string DebuggerDisplay
{
get
{
return ToString();
}
}

/// <inheritdoc />
public void OnBuildFinished()
{
if (Build is not IHaveArtifacts nukeBuild)
{
return;
}

switch (nukeBuild.Host)
{
case GitHubActions:
{
EmitTestSummaryMarkdown(Build, GitHubActions.Instance.StepSummaryFile);
break;
}

default:
{
EmitTestSummaryMarkdown(Build, nukeBuild.ArtifactsDirectory / "github" / "summary.md");
break;
}
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string DebuggerDisplay => ToString();

Check warning on line 21 in src/Nuke/ContinuousIntegration/ContinuousIntegrationConventionsAttribute.cs

View workflow job for this annotation

GitHub Actions / lint

Possible null reference return.

Check warning on line 21 in src/Nuke/ContinuousIntegration/ContinuousIntegrationConventionsAttribute.cs

View workflow job for this annotation

GitHub Actions / lint

Possible null reference return.

Check warning on line 21 in src/Nuke/ContinuousIntegration/ContinuousIntegrationConventionsAttribute.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 21 in src/Nuke/ContinuousIntegration/ContinuousIntegrationConventionsAttribute.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 21 in src/Nuke/ContinuousIntegration/ContinuousIntegrationConventionsAttribute.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 21 in src/Nuke/ContinuousIntegration/ContinuousIntegrationConventionsAttribute.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

private void EmitTestSummaryMarkdown(INukeBuild build, AbsolutePath summary)
{
// ReSharper disable once SuspiciousTypeConversion.Global
if (build.ExecutionPlan.Any(z => z.Name == nameof(IHaveTestTarget.Test))
&& build is IHaveTestArtifacts testResultReports
&& testResultReports.TestResultsDirectory.GlobFiles("**/*.trx") is
{ Count: > 0, } results)
{ Count: > 0, } results)
{
// summary.TouchFile();
// var reporter = new LiquidReporter(results.Select(z => z.ToString()), Log.Logger);
Expand All @@ -67,7 +38,7 @@ private void EmitTestSummaryMarkdown(INukeBuild build, AbsolutePath summary)
.Add("--inputs {0}", results.Select(z => $"File={z}"), ' ', quoteMultiple: true)
.Add("--output-file {0}", summary)
.RenderForExecution(),
workingDirectory: build.RootDirectory,
build.RootDirectory,
logOutput: false
);
}
Expand All @@ -87,4 +58,28 @@ private void EmitTestSummaryMarkdown(INukeBuild build, AbsolutePath summary)
_ = summary.WriteAllText(coverageSummary + summary.ReadAllText().TrimStart());
}
}
}

/// <inheritdoc />
public void OnBuildFinished()
{
if (Build is not IHaveArtifacts nukeBuild)
{
return;
}

switch (nukeBuild.Host)
{
case GitHubActions:
{
EmitTestSummaryMarkdown(Build, GitHubActions.Instance.StepSummaryFile);
break;
}

default:
{
EmitTestSummaryMarkdown(Build, nukeBuild.ArtifactsDirectory / "github" / "summary.md");
break;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Nuke/ICanLint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,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)*/);
}
}
}
2 changes: 1 addition & 1 deletion src/Nuke/LocalBuildConventionsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public void OnBuildInitialized(IReadOnlyCollection<ExecutableTarget> executableT
// if (Build is not (INukeBuild nukeBuild and IHaveSolution haveSolution)) return;
// if (nukeBuild.IsServerBuild) return;
}
}
}
22 changes: 11 additions & 11 deletions src/Nuke/SolutionUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,30 @@ private static void AddNukeBuilds(Solution solution, SolutionFolder configFolder
.Where(z => z.Configurations.Count > 0)
.SelectMany(
project => project.Configurations.Where(z => z.Key.Contains(".Build.", StringComparison.OrdinalIgnoreCase)),
(project, pair) => ( Project: project, Key: pair.Key )
(project, pair) => ( Project: project, pair.Key )
)
.ToArray();
foreach (var (project, key) in projects)
foreach (( var project, var key ) in projects)
{
Log.Logger.Information("Removing {Key} from {Project} configuration", key, project.Name);
project.Configurations.Remove(key);
}

var itemsToRemove = solution
.AllSolutionFolders
.SelectMany(z => z.Items, (folder, pair) => (Folder: folder, ItemPath: pair.Key, FilePath: pair.Value ))
.Where(z => !AbsolutePath.Create(z.FilePath).FileExists())
.ToArray();
foreach (var (folder, itemPath, _) in itemsToRemove)
.AllSolutionFolders
.SelectMany(z => z.Items, (folder, pair) => ( Folder: folder, ItemPath: pair.Key, FilePath: pair.Value ))
.Where(z => !AbsolutePath.Create(z.FilePath).FileExists())
.ToArray();
foreach (( var folder, var itemPath, _ ) in itemsToRemove)
{
Log.Logger.Information("Removing {ItemPath} from {Folder}", itemPath, folder.Name);
folder.Items.Remove(itemPath);
}

var emptyFoldersToRemove = solution
.AllSolutionFolders
.Where(z => z.Items.Count == 0 && z.Projects.Count == 0)
.ToArray();
.AllSolutionFolders
.Where(z => z.Items.Count == 0 && z.Projects.Count == 0)
.ToArray();
foreach (var folder in emptyFoldersToRemove)
{
Log.Logger.Information("Removing {Folder}", folder.Name);
Expand Down Expand Up @@ -186,4 +186,4 @@ private static void AddSolutionItemToFolder(SolutionFolder folder, UnixRelativeP
Log.Logger.Information("Adding {Path} to {Folder}", path, folder.Name);
folder.Items.Add(path, path);
}
}
}

0 comments on commit 523365b

Please sign in to comment.