Skip to content

Commit

Permalink
Update to .NET 8.0 / Replace NDepend.Path with Spectre.IO (#208)
Browse files Browse the repository at this point in the history
* Update to .NET 8.0
* Add new compiled regexps
* Remove NDepend.Path and replace with Spectre.IO
* Include output path in message
* Change Status field so that superseding works correctly
* Fix #203
* Fix #190
  • Loading branch information
HowardvanRooijen authored Nov 25, 2023
1 parent bda598d commit 03395cf
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
needs: prepareConfig
uses: endjin/Endjin.RecommendedPractices.GitHubActions/.github/workflows/scripted-build-pipeline.yml@main
with:
netSdkVersion: '7.x'
netSdkVersion: '8.x'
# workflow_dispatch inputs are always strings, the type property is just for the UI
forcePublish: ${{ github.event.inputs.forcePublish == 'true' }}
skipCleanup: ${{ github.event.inputs.skipCleanup == 'true' }}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ Set as the default template using `adr templates set business-case`
Architectural Decisions using Markdown and Architectural Decision Records, by [Oliver Kopp](https://adr.github.io/madr/), which distils the decision record into the following headings:

- Title
- Status
- Context and Problem Statement
- Decision Drivers
- Considered Options
Expand Down Expand Up @@ -360,7 +361,7 @@ Last Modified: YYYY-MM-DD HH:MM

<PropertyGroup>
<AssemblyName>thirdparty.adr.templates</AssemblyName>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IncludeBuildOutput>false</IncludeBuildOutput>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<!-- https://learn.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support -->
Expand Down
4 changes: 2 additions & 2 deletions Solutions/Endjin.Adr.Cli.Specs/Endjin.Adr.Cli.Specs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<RootNamespace>Endjin.AdrCli.Specs</RootNamespace>
Expand Down
19 changes: 14 additions & 5 deletions Solutions/Endjin.Adr.Cli/Commands/New/NewAdrCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace Endjin.Adr.Cli.Commands.New;

public class NewAdrCommand : AsyncCommand<NewAdrCommand.Settings>
public partial class NewAdrCommand : AsyncCommand<NewAdrCommand.Settings>
{
private readonly ITemplateSettingsManager templateSettingsManager;
private readonly IAppEnvironmentManager appEnvironmentManager;
Expand Down Expand Up @@ -98,7 +98,7 @@ public override async Task<int> ExecuteAsync([NotNull] CommandContext context, [

if (supersede is not null)
{
Regex supersedeRegEx = new(@"(?<=## Status.*\n)((?:.|\n)+?)(?=\n##)", RegexOptions.Multiline);
Regex supersedeRegEx = SupersedeRegex();

string updatedContent = supersedeRegEx.Replace(supersede.Content, $"\nSuperseded by ADR {adr.RecordNumber:D4} - {adr.Title}\n");

Expand All @@ -110,7 +110,7 @@ public override async Task<int> ExecuteAsync([NotNull] CommandContext context, [

await File.WriteAllTextAsync(Path.Combine(targetPath, adr.SafeFileName()), adr.Content).ConfigureAwait(false);

AnsiConsole.MarkupLine($"""Created ADR Record: [aqua]"{settings.Title}"[/]""");
AnsiConsole.MarkupLine($"""Created ADR Record: [aqua]"{settings.Title}"[/] in [yellow]{targetPath}[/]""");
}
catch (InvalidOperationException)
{
Expand All @@ -133,7 +133,7 @@ private static string CreateNewDefaultTemplate(string title, ITemplateSettingsMa
TemplatePackageDetail template = templateSettings.MetaData.Details.Find(x => x.FullPath == templateSettings.DefaultTemplate);
string templateContents = File.ReadAllText(template.FullPath);

Regex yamlHeaderRegExp = new(@"((?:^-{3})(?:.*\n)*(?:^-{3})\n# Title)", RegexOptions.Multiline);
Regex yamlHeaderRegExp = YamlHeaderRegex();

return yamlHeaderRegExp.Replace(templateContents, $"# {title}");
}
Expand All @@ -146,7 +146,7 @@ private static async Task<List<Adr>> GetAllAdrFilesFromCurrentDirectoryAsync(str
}

List<Adr> documents = new();
Regex fileNameRegExp = new(@"(\d{4}.*\.md)");
Regex fileNameRegExp = FileNameRegex();

foreach (string file in Directory.EnumerateFiles(targetPath, "*.md").Where(path => fileNameRegExp.IsMatch(path)))
{
Expand All @@ -164,6 +164,15 @@ private static async Task<List<Adr>> GetAllAdrFilesFromCurrentDirectoryAsync(str
return documents;
}

[GeneratedRegex(@"(\d{4}.*\.md)")]
private static partial Regex FileNameRegex();

[GeneratedRegex(@"((?:^-{3})(?:.*\n)*(?:^-{3})\n# Title)", RegexOptions.Multiline)]
private static partial Regex YamlHeaderRegex();

[GeneratedRegex(@"(?<=## Status.*\n)((?:.|\n)+?)(?=\n##)", RegexOptions.Multiline)]
private static partial Regex SupersedeRegex();

public class Settings : CommandSettings
{
[CommandArgument(0, "<TITLE>")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@

using System.Collections.Generic;
using System.Threading.Tasks;

using NDepend.Path;
using Spectre.IO;

namespace Endjin.Adr.Cli.Configuration.Contracts;

public interface IAppEnvironment : IAppEnvironmentConfiguration
{
IAbsoluteFilePath NuGetConfigFilePath { get; }
FilePath NuGetConfigFilePath { get; }

IAbsoluteDirectoryPath TemplatesPath { get; }
DirectoryPath TemplatesPath { get; }

IAbsoluteDirectoryPath PluginPath { get; }
DirectoryPath PluginPath { get; }

IEnumerable<IAbsoluteDirectoryPath> PluginPaths { get; }
IEnumerable<DirectoryPath> PluginPaths { get; }

void Clean();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Copyright (c) Endjin Limited. All rights reserved.
// </copyright>

using NDepend.Path;
using Spectre.IO;

namespace Endjin.Adr.Cli.Configuration.Contracts;

public interface IAppEnvironmentConfiguration
{
IAbsoluteDirectoryPath AppPath { get; }
DirectoryPath AppPath { get; }

IAbsoluteDirectoryPath ConfigurationPath { get; }
DirectoryPath ConfigurationPath { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
using System.Threading.Tasks;

using Endjin.Adr.Cli.Configuration.Contracts;

using NDepend.Path;

using Endjin.Adr.Cli.Extensions;
using Spectre.Console;
using Spectre.IO;
using Environment = System.Environment;
using Path = System.IO.Path;

namespace Endjin.Adr.Cli.Configuration;

Expand All @@ -33,22 +34,22 @@ public class FileSystemLocalProfileAppEnvironment : IAppEnvironment
</packageSources>
</configuration>";

public IAbsoluteDirectoryPath AppPath
public DirectoryPath AppPath
{
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppOrgName, AppName).ToAbsoluteDirectoryPath(); }
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppOrgName, AppName); }
}

public IAbsoluteDirectoryPath TemplatesPath
public DirectoryPath TemplatesPath
{
get { return Path.Combine(this.AppPath.ToString(), TemplatesDirectoryName).ToAbsoluteDirectoryPath(); }
get { return Path.Combine(this.AppPath.ToString(), TemplatesDirectoryName); }
}

public IAbsoluteDirectoryPath PluginPath
public DirectoryPath PluginPath
{
get { return Path.Combine(this.AppPath.ToString(), PluginsDirectoryName).ToAbsoluteDirectoryPath(); }
get { return Path.Combine(this.AppPath.ToString(), PluginsDirectoryName); }
}

public IEnumerable<IAbsoluteDirectoryPath> PluginPaths
public IEnumerable<DirectoryPath> PluginPaths
{
get
{
Expand All @@ -67,18 +68,18 @@ public IEnumerable<IAbsoluteDirectoryPath> PluginPaths

foreach (string dir in dirs)
{
yield return dir.ToAbsoluteDirectoryPath();
yield return dir;
}
}
else
{
foreach (IAbsoluteDirectoryPath path in this.PluginPath.ChildrenDirectoriesPath)
foreach (DirectoryPath path in this.PluginPath.ChildrenDirectoriesPath())
{
IEnumerable<IAbsoluteDirectoryPath> leafPaths = Directory
IEnumerable<DirectoryPath> leafPaths = Directory
.EnumerateDirectories(path.ToString(), "*.*", SearchOption.AllDirectories)
.Where(f => !Directory.EnumerateDirectories(f, "*.*", SearchOption.TopDirectoryOnly).Any()).Select(x => x.ToAbsoluteDirectoryPath());
.Where(f => !Directory.EnumerateDirectories(f, "*.*", SearchOption.TopDirectoryOnly).Any()).Select(x => new DirectoryPath(x));

foreach (IAbsoluteDirectoryPath leafPath in leafPaths)
foreach (DirectoryPath leafPath in leafPaths)
{
yield return leafPath;
}
Expand All @@ -87,14 +88,14 @@ public IEnumerable<IAbsoluteDirectoryPath> PluginPaths
}
}

public IAbsoluteDirectoryPath ConfigurationPath
public DirectoryPath ConfigurationPath
{
get { return Path.Combine(this.AppPath.ToString(), ConfigurationDirectorName).ToAbsoluteDirectoryPath(); }
get { return Path.Combine(this.AppPath.ToString(), ConfigurationDirectorName); }
}

public IAbsoluteFilePath NuGetConfigFilePath
public FilePath NuGetConfigFilePath
{
get { return Path.Combine(this.ConfigurationPath.ToString(), NuGetFileName).ToAbsoluteFilePath(); }
get { return Path.Combine(this.ConfigurationPath.ToString(), NuGetFileName); }
}

public void Clean()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
using System.Threading.Tasks;

using Endjin.Adr.Cli.Configuration.Contracts;

using NDepend.Path;

using Endjin.Adr.Cli.Extensions;
using Spectre.Console;
using Spectre.IO;
using Environment = System.Environment;
using Path = System.IO.Path;

namespace Endjin.Adr.Cli.Configuration;

Expand All @@ -32,22 +33,22 @@ public class FileSystemRoamingProfileAppEnvironment : IAppEnvironment
</packageSources>
</configuration>";

public IAbsoluteDirectoryPath AppPath
public DirectoryPath AppPath
{
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppOrgName, AppName).ToAbsoluteDirectoryPath(); }
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppOrgName, AppName); }
}

public IAbsoluteDirectoryPath TemplatesPath
public DirectoryPath TemplatesPath
{
get { return Path.Combine(this.AppPath.ToString(), TemplatesDirectoryName).ToAbsoluteDirectoryPath(); }
get { return Path.Combine(this.AppPath.ToString(), TemplatesDirectoryName); }
}

public IAbsoluteDirectoryPath PluginPath
public DirectoryPath PluginPath
{
get { return Path.Combine(this.AppPath.ToString(), PluginsDirectoryName).ToAbsoluteDirectoryPath(); }
get { return Path.Combine(this.AppPath.ToString(), PluginsDirectoryName); }
}

public IEnumerable<IAbsoluteDirectoryPath> PluginPaths
public IEnumerable<DirectoryPath> PluginPaths
{
get
{
Expand All @@ -66,18 +67,18 @@ public IEnumerable<IAbsoluteDirectoryPath> PluginPaths

foreach (string dir in dirs)
{
yield return dir.ToAbsoluteDirectoryPath();
yield return dir;
}
}
else
{
foreach (IAbsoluteDirectoryPath path in this.PluginPath.ChildrenDirectoriesPath)
foreach (DirectoryPath path in this.PluginPath.ChildrenDirectoriesPath())
{
IEnumerable<IAbsoluteDirectoryPath> leafPaths = Directory
IEnumerable<DirectoryPath> leafPaths = Directory
.EnumerateDirectories(path.ToString(), "*.*", SearchOption.AllDirectories)
.Where(f => !Directory.EnumerateDirectories(f, "*.*", SearchOption.TopDirectoryOnly).Any()).Select(x => x.ToAbsoluteDirectoryPath());
.Where(f => !Directory.EnumerateDirectories(f, "*.*", SearchOption.TopDirectoryOnly).Any()).Select(x => new DirectoryPath(x));

foreach (IAbsoluteDirectoryPath leafPath in leafPaths)
foreach (DirectoryPath leafPath in leafPaths)
{
yield return leafPath;
}
Expand All @@ -86,14 +87,14 @@ public IEnumerable<IAbsoluteDirectoryPath> PluginPaths
}
}

public IAbsoluteDirectoryPath ConfigurationPath
public DirectoryPath ConfigurationPath
{
get { return Path.Combine(this.AppPath.ToString(), ConfigurationDirectorName).ToAbsoluteDirectoryPath(); }
get { return Path.Combine(this.AppPath.ToString(), ConfigurationDirectorName); }
}

public IAbsoluteFilePath NuGetConfigFilePath
public FilePath NuGetConfigFilePath
{
get { return Path.Combine(this.ConfigurationPath.ToString(), NuGetFileName).ToAbsoluteFilePath(); }
get { return Path.Combine(this.ConfigurationPath.ToString(), NuGetFileName); }
}

public void Clean()
Expand Down
30 changes: 15 additions & 15 deletions Solutions/Endjin.Adr.Cli/Endjin.Adr.Cli.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="$(EndjinProjectPropsPath)" Condition="$(EndjinProjectPropsPath) != ''" />

Expand All @@ -9,7 +9,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Endjin.Adr.Cli</RootNamespace>
</PropertyGroup>

Expand All @@ -29,37 +29,37 @@
</PropertyGroup>

<ItemGroup>
<None Include="NuGet.Readme.md" Pack="true" PackagePath="\readme.md"/>
<None Include="NuGet.Readme.md" Pack="true" PackagePath="\readme.md" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile></DocumentationFile>
<OutputPath></OutputPath>
<NoWarn>1701;1702; CS1591;SA1600;SA1124</NoWarn>
<NoWarn>1701;1702; CS1591;SA1600;SA1601;SA1124</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702; CS1591;SA1600;SA1124</NoWarn>
<NoWarn>1701;1702; CS1591;SA1600;SA1601;SA1124</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Markdig" Version="0.31.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="NDepend.Path" Version="2.0.0" />
<PackageReference Include="NuGet.Common" Version="6.6.1" />
<PackageReference Include="NuGet.Packaging.Core" Version="6.6.1" />
<PackageReference Include="NuGet.Resolver" Version="6.6.1" />
<PackageReference Include="Spectre.Console" Version="0.47.0" />
<PackageReference Include="Spectre.Console.Cli" Version="0.47.0" />
<PackageReference Include="YamlDotNet" Version="13.1.1" />
<PackageReference Include="Markdig" Version="0.33.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="NuGet.Common" Version="6.8.0" />
<PackageReference Include="NuGet.Packaging.Core" Version="6.8.0" />
<PackageReference Include="NuGet.Resolver" Version="6.8.0" />
<PackageReference Include="Spectre.Console" Version="0.48.0" />
<PackageReference Include="Spectre.Console.Cli" Version="0.48.0" />
<PackageReference Include="Spectre.IO" Version="0.14.0" />
<PackageReference Include="YamlDotNet" Version="13.7.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Spectre.Console.Analyzer" Version="0.47.0">
<PackageReference Include="Spectre.Console.Analyzer" Version="0.48.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit 03395cf

Please sign in to comment.