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

Upgrade to .NET 8 #270

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
push:
branches:
- main
- net80incremental

jobs:
build:
name: Build
Expand All @@ -19,20 +21,19 @@ jobs:
NUGET_CERT_REVOCATION_MODE: offline
steps:
- name: Get Source
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install .NET Core SDK
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
3.1.x
6.0.x
8.x
- name: Build and Test
run: dotnet test --logger "trx;LogFileName=test-results.trx"
- name: Upload Test Results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3 # Stick with v3 until https://github.com/dorny/test-reporter/issues/343 is resolved
if: success() || failure()
with:
name: test-results-${{ matrix.os }}
path: '**/test-results.trx'
path: "**/test-results.trx"
12 changes: 6 additions & 6 deletions .github/workflows/test-report.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'Test Report'
name: "Test Report"
on:
workflow_run:
workflows: [ 'Build' ]
workflows: ["Build"]
types:
- completed
jobs:
Expand All @@ -13,9 +13,9 @@ jobs:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- name: Process Test Results
uses: dorny/test-reporter@v1
uses: dorny/test-reporter@v1.7.0
with:
artifact: test-results-${{ matrix.os }}
name: 'Test Results (${{ matrix.os }})'
path: '**/*.trx'
reporter: dotnet-trx
name: "Test Results (${{ matrix.os }})"
path: "**/*.trx"
reporter: dotnet-trx
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904;CA1724</WarningsNotAsErrors>
<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904;CA1040;CA1724;CA1062;CA1710;CA1711;CA1725;CS8600;CS8601;CS8602;CS8603;CS8604;CS8618;CS8619;CS8620;CS8622;CS8625;CS8631</WarningsNotAsErrors>
</PropertyGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\LICENSE.md" Pack="true" PackagePath=""/>
<None Include="$(MSBuildThisFileDirectory)\icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All"/>
<PackageReference Include="Roslynator.Analyzers" Version="4.0.2" PrivateAssets="All"/>
<!-- It appears as though there might be a performance issue in versions of Microsoft.VisualStudio.Threading.Analyzers past this at least through 17.0.64 -->
Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.App/Commands/PipelinesCommand{TSettings}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ protected override async Task<int> ExecuteEngineAsync(
{
new ConsoleListener(() =>
{
#pragma warning disable VSTHRD103
cancellationTokenSource.Cancel();
#pragma warning restore VSTHRD103
return Task.CompletedTask;
});
return (int)await engineManager.ExecuteAsync(cancellationTokenSource);
Expand Down
16 changes: 8 additions & 8 deletions src/core/Statiq.App/Statiq.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="3.1.18" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.18" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.18" />
<PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="3.1.18" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.18" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.18" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.18" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.4.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="NetEscapades.Configuration.Yaml" Version="3.1.0" />
<PackageReference Include="NetEscapades.Extensions.Logging.RollingFile" Version="2.2.0" />
<PackageReference Include="Spectre.Console" Version="0.45.0" />
Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.Common/Content/MediaTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,9 @@ async Task Main()
/// <param name="mediaType">The media type.</param>
/// <param name="defaultIfNotFound">Will return a "text/x-[extension]" default media type if a mapping is not found.</param>
/// <returns><c>true</c> if the media type could be determined, <c>false</c> otherwise.</returns>
#pragma warning disable CA1021 // Avoid out parameters
public static bool TryGet(string path, out string mediaType, bool defaultIfNotFound = true)
#pragma warning restore CA1021 // Avoid out parameters
{
if (string.IsNullOrWhiteSpace(path))
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.Common/Documents/ObjectDocument{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public sealed class ObjectDocument<T> : IDocument
/// <summary>
/// The underlying object.
/// </summary>
#pragma warning disable CA1720 // Identifier contains type name
public T Object { get; }
#pragma warning restore CA1720 // Identifier contains type name

/// <inheritdoc />
public NormalizedPath Source { get; }
Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.Common/IO/IReadOnlyFileSystemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ public static class IReadOnlyFileSystemExtensions
/// path is deeper than the real one). This contains all the mapped input paths that couldn't be unmapped.
/// </param>
/// <returns>The "unmapped" input paths.</returns>
#pragma warning disable CA1021
public static IEnumerable<NormalizedPath> GetUnmappedInputPaths(
this IReadOnlyFileSystem fileSystem,
in NormalizedPath path,
out HashSet<NormalizedPath> nonExistingMappedPaths)
#pragma warning restore CA1021
{
fileSystem.ThrowIfNull(nameof(fileSystem));
path.ThrowIfNull(nameof(path));
Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.Common/Scripting/IScriptHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public interface IScriptHelper
/// <c>true</c> if the candidate string is a script string that should be cached,
/// <c>false</c> if the candidate string is a script string that should not be cached,
/// and null otherwise.</returns>
#pragma warning disable CA1021
public static bool? TryGetScriptString(string str, out string script)
#pragma warning restore CA1021
{
if (TryGetScriptString(str, true, out script))
{
Expand Down
14 changes: 7 additions & 7 deletions src/core/Statiq.Common/Statiq.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<PackageTags>Statiq Static StaticContent StaticSite Blog BlogEngine</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AngleSharp" Version="0.16.1" />
<PackageReference Include="ConcurrentHashSet" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.18" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.18" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="3.1.18" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.18" />
<PackageReference Include="AngleSharp" Version="1.0.7" />
<PackageReference Include="ConcurrentHashSet" Version="1.3.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="NetFabric.Hyperlinq" Version="3.0.0-beta48" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.Common/Util/ItemStreams/ItemStream{TItem}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ public sealed override int Read(Span<byte> buffer)

public sealed override int WriteTimeout { get => base.WriteTimeout; set => base.WriteTimeout = value; }

#pragma warning disable CS0672,SYSLIB0010 // Member overrides obsolete member
public sealed override object InitializeLifetimeService() => base.InitializeLifetimeService();
#pragma warning restore CS0672,SYSLIB0010 // Member overrides obsolete member

public sealed override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) => base.BeginRead(buffer, offset, count, callback, state);

Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.Common/Util/LockingStreamWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public LockingStreamWrapper(Stream stream, bool disposeStream)
_disposeStream = disposeStream;
}

#pragma warning disable CA1721
protected Stream Stream { get; }
#pragma warning restore CA1721

/// <summary>
/// Gets the wrapped stream and locks access until it's disposed.
Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.Common/Util/StringStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ protected override void Dispose(bool disposing)
}
}

#pragma warning disable CA1720 // Identifier contains type name
public string String { get; }
#pragma warning restore CA1720 // Identifier contains type name

public override bool CanRead => true;

Expand Down
2 changes: 1 addition & 1 deletion src/core/Statiq.Core/Execution/ExecutionPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected ExecutionPipeline()
public virtual ExecutionPolicy ExecutionPolicy { get; set; }

protected sealed override Task<IEnumerable<IDocument>> ExecuteContextAsync(IExecutionContext context) =>
context.Phase switch
(context ?? throw new ArgumentNullException(nameof(context))).Phase switch
{
Phase.Input => ExecuteInputPhaseAsync(context),
Phase.Process => ExecuteProcessPhaseAsync(context),
Expand Down
12 changes: 8 additions & 4 deletions src/core/Statiq.Core/Execution/IEngineExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.Logging;
using Polly;
using Statiq.Common;

namespace Statiq.Core
Expand All @@ -10,6 +11,9 @@ public static class IEngineExtensions
{
public static void LogAndCheckVersion(this IEngine engine, Assembly assembly, string name, string minimumVersionKey)
{
ArgumentNullException.ThrowIfNull(assembly);
ArgumentNullException.ThrowIfNull(engine);

if (!(Attribute.GetCustomAttribute(assembly, typeof(AssemblyInformationalVersionAttribute)) is AssemblyInformationalVersionAttribute versionAttribute))
{
throw new Exception($"Could not determine the {name} version from {assembly.FullName}");
Expand All @@ -18,16 +22,16 @@ public static void LogAndCheckVersion(this IEngine engine, Assembly assembly, st
// Get and print the version
string informationalVersion = versionAttribute.InformationalVersion;
engine.Logger.LogInformation($"{name} version {informationalVersion}", true);
SemVer.Version version = new SemVer.Version(informationalVersion, true);
SemanticVersioning.Version version = new SemanticVersioning.Version(informationalVersion, true);

// Get all version ranges
(string Key, SemVer.Version Version)[] minimumVersions = engine.Settings.Keys
(string Key, SemanticVersioning.Version Version)[] minimumVersions = engine.Settings.Keys
.Where(k => k.StartsWith(minimumVersionKey))
.Select(k => (Key: k, Value: engine.Settings.GetString(k)))
.Where(x => !x.Value.IsNullOrWhiteSpace())
.Select(x => (x.Key, new SemVer.Version(x.Value, true)))
.Select(x => (x.Key, new SemanticVersioning.Version(x.Value, true)))
.ToArray();
foreach ((string Key, SemVer.Version Version) minimumVersion in minimumVersions)
foreach ((string Key, SemanticVersioning.Version Version) minimumVersion in minimumVersions)
{
if (version < minimumVersion.Version)
{
Expand Down
11 changes: 6 additions & 5 deletions src/core/Statiq.Core/Execution/MemoryStreamFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ public class MemoryStreamFactory : IMemoryStreamFactory
private const int BlockSize = 16384;

private readonly RecyclableMemoryStreamManager _manager =
new RecyclableMemoryStreamManager(
#pragma warning disable SA1000
new(new RecyclableMemoryStreamManager.Options(
#pragma warning restore SA1000
BlockSize,
RecyclableMemoryStreamManager.DefaultLargeBufferMultiple,
RecyclableMemoryStreamManager.DefaultMaximumBufferSize)
{
MaximumFreeSmallPoolBytes = BlockSize * 32768L * 2, // 1 GB
};
RecyclableMemoryStreamManager.DefaultMaximumBufferSize,
BlockSize * 32768L * 2, // 1 GB
0));

public virtual MemoryStream GetStream() => _manager.GetStream();

Expand Down
6 changes: 5 additions & 1 deletion src/core/Statiq.Core/Execution/NamespaceCollection.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ConcurrentCollections;
using Polly;
using Statiq.Common;

namespace Statiq.Core
Expand Down Expand Up @@ -40,6 +42,8 @@ public virtual bool Add(string ns)

public virtual void AddRange(IEnumerable<string> namespaces)
{
ArgumentNullException.ThrowIfNull(namespaces);

// Iterate manually so we can throw for null or white space
foreach (string ns in namespaces)
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.Core/Modules/Content/AddContentToMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ protected override async Task<IEnumerable<IDocument>> ExecuteChildrenAsync(
IExecutionContext context,
ImmutableArray<IDocument> childOutputs)
{
ArgumentNullException.ThrowIfNull(context);

if (childOutputs.Length == 0)
{
return context.Inputs;
Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.Core/Modules/Content/AddRtlSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ private static bool IsRightToLeft(int c)
c == 0x00FB3E;
}

#pragma warning disable CA1505 // Avoid unmaintainable code
private static bool IsLeftToRight(int c)
#pragma warning restore CA1505 // Avoid unmaintainable code
{
// Generated from Table D.2 of RFC3454
// http://www.ietf.org/rfc/rfc3454.txt
Expand Down
10 changes: 9 additions & 1 deletion src/core/Statiq.Core/Modules/Content/EscapeHtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Polly;
using Statiq.Common;

namespace Statiq.Core
Expand Down Expand Up @@ -159,6 +161,8 @@ public EscapeHtml WithDefaultStandard()
/// <returns>The current module instance.</returns>
public EscapeHtml WithStandard(params char[] standard)
{
ArgumentNullException.ThrowIfNull(standard);

foreach (char c in standard)
{
_standardCharacters.Add(c);
Expand All @@ -185,6 +189,8 @@ public EscapeHtml EscapeAllNonstandard()
/// <returns>The current module instance.</returns>
public EscapeHtml WithEscapedChar(params char[] toEscape)
{
ArgumentNullException.ThrowIfNull(toEscape);

foreach (char c in toEscape)
{
_currentlyEscapedCharacters.Add(
Expand All @@ -201,6 +207,8 @@ private string GenerateEscape(char c)

protected override async Task<IEnumerable<IDocument>> ExecuteInputAsync(IDocument input, IExecutionContext context)
{
ArgumentNullException.ThrowIfNull(input);

string oldContent = await input.GetContentStringAsync();
StringWriter outputString = new StringWriter();
bool escaped = false;
Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.Core/Modules/Content/GenerateRedirects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public GenerateRedirects AlwaysCreateAdditionalOutput(bool alwaysCreateAdditiona
/// <inheritdoc />
protected override async Task<IEnumerable<IDocument>> ExecuteContextAsync(IExecutionContext context)
{
ArgumentNullException.ThrowIfNull(context);

// Iterate redirects and generate all of the per-redirect documents (I.e., meta refresh pages)
ConcurrentDictionary<NormalizedPath, string> redirects = new ConcurrentDictionary<NormalizedPath, string>();

Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.Core/Modules/Content/GenerateSitemap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public GenerateSitemap(Config<object> sitemapItemOrLocation, Func<string, string
/// <inheritdoc />
protected override async Task<IEnumerable<IDocument>> ExecuteContextAsync(IExecutionContext context)
{
ArgumentNullException.ThrowIfNull(context);

HashSet<string> locations = new HashSet<string>(); // Remove duplicate locations
List<string> content = new List<string>();
content.Add("<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
Expand Down
2 changes: 1 addition & 1 deletion src/core/Statiq.Core/Modules/Content/InsertLinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public InsertLinks WithEndWordSeparators(params char[] endWordSeparators)
foreach (IElement element in htmlDocument.QuerySelectorAll(_querySelector).Where(t => !t.Ancestors<IHtmlAnchorElement>().Any()))
{
// Enumerate all descendant text nodes not already in a link element
foreach (IText text in element.Descendents().OfType<IText>().Where(t => !t.Ancestors<IHtmlAnchorElement>().Any()))
foreach (IText text in element.Descendants().OfType<IText>().Where(t => !t.Ancestors<IHtmlAnchorElement>().Any()))
{
if (ReplaceStrings(text, links, out string newText))
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/Statiq.Core/Modules/Content/JoinDocuments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public JoinDocuments(string delimiter, JoinedMetadata metaDataMode = JoinedMetad
/// <returns>A single document in a list.</returns>
protected override async Task<IEnumerable<IDocument>> ExecuteContextAsync(IExecutionContext context)
{
ArgumentNullException.ThrowIfNull(context);

if (context.Inputs.Length < 1)
{
return context.CreateDocument().Yield();
Expand Down
2 changes: 1 addition & 1 deletion src/core/Statiq.Core/Modules/Content/MergeContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ protected override IEnumerable<IDocument> ExecuteChildren(
ImmutableArray<IDocument> childOutputs) =>
_reverse
? childOutputs.SelectMany(childOutput => context.Inputs.Select(input => childOutput.Clone(input.ContentProvider)))
: context.Inputs.SelectMany(input => childOutputs.Select(result => input.Clone(result.ContentProvider)));
: (context ?? throw new ArgumentNullException(nameof(context))).Inputs.SelectMany(input => childOutputs.Select(result => input.Clone(result.ContentProvider)));
}
}
Loading