Skip to content

Commit

Permalink
Merge pull request #908 from adamralph/net8
Browse files Browse the repository at this point in the history
target .NET 8
  • Loading branch information
adamralph committed Dec 21, 2023
2 parents f208efa + 06d907c commit bfd9f63
Show file tree
Hide file tree
Showing 36 changed files with 4,883 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: mcr.microsoft.com/dotnet/sdk:7.0
- image: mcr.microsoft.com/dotnet/sdk:8.0
steps:
- checkout
- run:
Expand Down
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
container:
image: mcr.microsoft.com/dotnet/sdk:7.0
image: mcr.microsoft.com/dotnet/sdk:8.0
build_task:
build_script: ./build
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-7.0
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-8.0

RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install lts/* && npm install -g cspell 2>&1"
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
dotnet-version: |
6.0.417
7.0.404
8.0.100
- uses: actions/checkout@v4.1.1
with:
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: 7.0.404
dotnet-version: 8.0.100
- uses: actions/checkout@v4.1.1
- run: dotnet build --configuration Release --nologo
- name: push
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build:
image: mcr.microsoft.com/dotnet/sdk:7.0
image: mcr.microsoft.com/dotnet/sdk:8.0
script: ./build
3 changes: 1 addition & 2 deletions Bullseye/Bullseye.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>https://github.com/adamralph/bullseye/blob/main/CHANGELOG.md</PackageReleaseNotes>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="5.0.0-beta.1" PrivateAssets="All" />
</ItemGroup>

Expand Down
8 changes: 7 additions & 1 deletion Bullseye/Internal/ActionTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@

namespace Bullseye.Internal
{
#if NET8_0_OR_GREATER
public class ActionTarget(string name, string description, IEnumerable<string> dependencies, Func<Task> action)
: Target(name, description, dependencies)
{
private readonly Func<Task> action = action;
#else
public class ActionTarget : Target
{
private readonly Func<Task> action;

public ActionTarget(string name, string description, IEnumerable<string> dependencies, Func<Task> action)
: base(name, description, dependencies) => this.action = action;

#endif
public override async Task RunAsync(bool dryRun, bool parallel, Output output, Func<Exception, bool> messageOnly, IReadOnlyCollection<Target> dependencyPath)
{
await output.BeginGroup(this).Tax();
Expand Down
9 changes: 8 additions & 1 deletion Bullseye/Internal/ActionTarget`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

namespace Bullseye.Internal
{
#if NET8_0_OR_GREATER
public class ActionTarget<TInput>(string name, string description, IEnumerable<string> dependencies, IEnumerable<TInput> inputs, Func<TInput, Task> action)
: Target(name, description, dependencies), IHaveInputs
{
private readonly IEnumerable<TInput> inputs = inputs;
private readonly Func<TInput, Task> action = action;
#else
public class ActionTarget<TInput> : Target, IHaveInputs
{
private readonly IEnumerable<TInput> inputs;
Expand All @@ -17,7 +24,7 @@ public ActionTarget(string name, string description, IEnumerable<string> depende
this.inputs = inputs;
this.action = action;
}

#endif
public IEnumerable<object?> Inputs => this.inputs.Cast<object?>();

public override async Task RunAsync(bool dryRun, bool parallel, Output output, Func<Exception, bool> messageOnly, IReadOnlyCollection<Target> dependencyPath)
Expand Down
4 changes: 4 additions & 0 deletions Bullseye/Internal/ArgsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public static (IReadOnlyList<string> Targets, Options Options, IReadOnlyList<str
showHelp: nonHelpArgs.Count != args.Count);
}

#if NET8_0_OR_GREATER
private static bool IsTarget(string arg) => !arg.StartsWith('-');
#else
private static bool IsTarget(string arg) => !arg.StartsWith("-", StringComparison.Ordinal);
#endif

private static bool IsNotTarget(string arg) => !IsTarget(arg);
}
Expand Down
33 changes: 13 additions & 20 deletions Bullseye/Internal/Output.Results.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,50 +116,43 @@ private static string GetResultLines(IEnumerable<KeyValuePair<Target, TargetResu
text.PadRight(totalWidth + (text.Length - Palette.StripColors(text).Length), paddingChar);
}

#if NET8_0_OR_GREATER
private sealed class TargetResult(int ordinal)
{
public int Ordinal { get; } = ordinal;
#else
private sealed class TargetResult
{
public TargetResult(int ordinal) => this.Ordinal = ordinal;

public int Ordinal { get; }

#endif
public TargetOutcome Outcome { get; set; }

public TimeSpan Duration { get; set; }

public ConcurrentDictionary<Guid, TargetInputResult> InputResults { get; } = new();
}

#if NET8_0_OR_GREATER
private sealed class TargetInputResult(int ordinal)
{
public int Ordinal { get; } = ordinal;
#else
private sealed class TargetInputResult
{
public TargetInputResult(int ordinal) => this.Ordinal = ordinal;

public int Ordinal { get; }

#endif
public object? Input { get; set; }

public TargetInputOutcome Outcome { get; set; }

public TimeSpan Duration { get; set; }
}

private sealed class SummaryRow
{
public SummaryRow(string targetOrInput, string outcome, string duration, string percentage)
{
this.TargetOrInput = targetOrInput;
this.Outcome = outcome;
this.Duration = duration;
this.Percentage = percentage;
}

public string TargetOrInput { get; }

public string Outcome { get; }

public string Duration { get; }

public string Percentage { get; }
}
private sealed record SummaryRow(string TargetOrInput, string Outcome, string Duration, string Percentage);

private enum TargetOutcome
{
Expand Down
41 changes: 40 additions & 1 deletion Bullseye/Internal/Output.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,45 @@

namespace Bullseye.Internal
{
#if NET8_0_OR_GREATER
public partial class Output(
TextWriter writer,
TextWriter diagnosticsWriter,
IReadOnlyCollection<string> args,
bool dryRun,
Host host,
bool hostForced,
bool noColor,
bool noExtendedChars,
OSPlatform osPlatform,
bool parallel,
Func<string> getPrefix,
bool skipDependencies,
bool verbose)
{
private const string NoInputsMessage = "No inputs!";
private const string StartingMessage = "Starting...";
private const string FailedMessage = "FAILED!";
private const string SucceededMessage = "Succeeded";

private readonly TextWriter writer = writer;
private readonly TextWriter diagnosticsWriter = diagnosticsWriter;

private readonly IReadOnlyCollection<string> args = args;
private readonly bool dryRun = dryRun;
private readonly Host host = host;
private readonly bool hostForced = hostForced;
private readonly bool noColor = noColor;
private readonly OSPlatform osPlatform = osPlatform;
private readonly bool parallel = parallel;
private readonly Func<string> getPrefix = getPrefix;
private readonly bool skipDependencies = skipDependencies;

private readonly Palette palette = new(noColor, noExtendedChars, host, osPlatform);
private readonly string scriptExtension = osPlatform == OSPlatform.Windows ? "cmd" : "sh";

public bool Verbose { get; } = verbose;
#else
public partial class Output
{
private const string NoInputsMessage = "No inputs!";
Expand Down Expand Up @@ -65,7 +104,7 @@ public partial class Output
this.palette = new Palette(noColor, noExtendedChars, host, osPlatform);
this.scriptExtension = osPlatform == OSPlatform.Windows ? "cmd" : "sh";
}

#endif
public async Task Header(Func<string> getVersion)
{
if (!this.Verbose)
Expand Down
10 changes: 10 additions & 0 deletions Bullseye/Internal/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

namespace Bullseye.Internal
{
#if NET8_0_OR_GREATER
public class Target(string name, string description, IEnumerable<string> dependencies)
{
public string Name { get; } = name;

public string Description { get; } = description;

public IReadOnlyCollection<string> Dependencies { get; } = dependencies.ToList();
#else
public class Target
{
public Target(string name, string description, IEnumerable<string> dependencies)
Expand All @@ -19,6 +28,7 @@ public Target(string name, string description, IEnumerable<string> dependencies)
public string Description { get; }

public IReadOnlyCollection<string> Dependencies { get; }
#endif

public virtual Task RunAsync(bool dryRun, bool parallel, Output output, Func<Exception, bool> messageOnly, IReadOnlyCollection<Target> dependencyPath) => output.Succeeded(this, dependencyPath, TimeSpan.Zero);

Expand Down
4 changes: 4 additions & 0 deletions Bullseye/Internal/TargetCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ private void CheckForMissingDependencies()
{
_ = (missingDependencies.TryGetValue(dependency, out var set)
? set
#if NET8_0_OR_GREATER
: missingDependencies[dependency] = [])
#else
: missingDependencies[dependency] = new SortedSet<string>())
#endif
.Add(target.Name);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Bullseye/Internal/TargetCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ private static IEnumerable<string> Expand(this TargetCollection targets, IEnumer
continue;
}

yield return matches.Any() ? matches[0].Name : name;
yield return matches.Count != 0 ? matches[0].Name : name;
}

if (ambiguousNames.Any())
if (ambiguousNames.Count != 0)
{
throw new InvalidUsageException($"Ambiguous target{(ambiguousNames.Count > 1 ? "s" : "")}: {ambiguousNames.Spaced()}");
}
Expand Down
4 changes: 4 additions & 0 deletions Bullseye/Palette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ namespace Bullseye
/// </summary>
public class Palette
{
#if NET8_0_OR_GREATER
private static readonly int[] numbers = [0, 30, 31, 32, 33, 34, 35, 36, 37, 90, 91, 92, 93, 94, 95, 96, 97,];
#else
private static readonly int[] numbers = { 0, 30, 31, 32, 33, 34, 35, 36, 37, 90, 91, 92, 93, 94, 95, 96, 97, };
#endif

/// <summary>
/// Constructs an instance of <see cref="Palette"/>.
Expand Down
4 changes: 4 additions & 0 deletions Bullseye/Targets.Instance.Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ namespace Bullseye
/// </summary>
public partial class Targets
{
#if NET8_0_OR_GREATER
private static readonly List<string> defaultList = [];
#else
private static readonly List<string> defaultList = new();
#endif
private static readonly Func<Exception, bool> defaultMessageOnly = _ => false;

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions Bullseye/Targets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ namespace Bullseye
/// </summary>
public partial class Targets
{
#if NET8_0_OR_GREATER
private readonly TargetCollection targetCollection = [];
#else
private readonly TargetCollection targetCollection = new();
#endif
}
}
3 changes: 3 additions & 0 deletions BullseyeSmokeTester.CommandLine/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[*.cs]

# CA1861: Avoid constant arrays as arguments
dotnet_diagnostic.CA1861.severity = none

# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = none
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<RollForward>major</RollForward>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<RollForward>major</RollForward>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<RollForward>major</RollForward>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion BullseyeSmokeTester/BullseyeSmokeTester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<RollForward>major</RollForward>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions BullseyeTests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# CA1002: Do not expose generic lists
dotnet_diagnostic.CA1002.severity = none

# CA1861: Avoid constant arrays as arguments
dotnet_diagnostic.CA1861.severity = none

# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = none

Expand Down
2 changes: 1 addition & 1 deletion BullseyeTests/BullseyeTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<RollForward>major</RollForward>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions BullseyeTests/OutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public static async Task DefaultHost()
#if NET7_0
var expectedPath = "../../../output.default.host.net7.0.txt";
#endif
#if NET8_0
var expectedPath = "../../../output.default.host.net8.0.txt";
#endif

await AssertFile.Contains(expectedPath, output.ToString().Replace(Environment.NewLine, "\r\n", StringComparison.Ordinal));
}
Expand Down Expand Up @@ -66,6 +69,9 @@ public static async Task AllHosts(Host host)
#if NET7_0
var expectedPath = $"../../../output.all.hosts.{host}.net7.0.txt";
#endif
#if NET8_0
var expectedPath = $"../../../output.all.hosts.{host}.net8.0.txt";
#endif

await AssertFile.Contains(expectedPath, output.ToString().Replace(Environment.NewLine, "\r\n", StringComparison.Ordinal));
}
Expand Down
Loading

0 comments on commit bfd9f63

Please sign in to comment.