Skip to content

Commit

Permalink
target .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
adamralph committed Dec 25, 2023
1 parent c62dfcd commit 75d923d
Show file tree
Hide file tree
Showing 49 changed files with 154 additions and 146 deletions.
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"
52 changes: 23 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,23 @@ jobs:
- job:
os: macos-11
tests:
framework: net6.0
sdk: "6.0.417"
sdk-major-minor: "6.0"
framework: net8.0
sdk: "8.0.100"
sdk-major-minor: "8.0"
# current macOS, latest LTS and latest
- job:
os: macos-12
tests:
framework: net6.0
sdk: "6.0.417"
sdk-major-minor: "6.0"
- job:
os: macos-12
tests:
framework: net7.0
sdk: "7.0.404"
sdk-major-minor: "7.0"
framework: net8.0
sdk: "8.0.100"
sdk-major-minor: "8.0"
# old Linux, latest LTS
- job:
os: ubuntu-20.04
tests:
framework: net6.0
sdk: "6.0.417"
sdk-major-minor: "6.0"
framework: net8.0
sdk: "8.0.100"
sdk-major-minor: "8.0"
# current Linux, all
- job:
os: ubuntu-22.04
Expand All @@ -53,34 +47,34 @@ jobs:
framework: net7.0
sdk: "7.0.404"
sdk-major-minor: "7.0"
# old Windows, latest LTS
- job:
os: windows-2019
os: ubuntu-22.04
tests:
framework: net6.0
sdk: "6.0.417"
sdk-major-minor: "6.0"
# current Windows, latest LTS and latest
framework: net8.0
sdk: "8.0.100"
sdk-major-minor: "8.0"
# old Windows, latest LTS
- job:
os: windows-2022
os: windows-2019
tests:
framework: net6.0
sdk: "6.0.417"
sdk-major-minor: "6.0"
framework: net8.0
sdk: "8.0.100"
sdk-major-minor: "8.0"
# current Windows, latest LTS and latest
- job:
os: windows-2022
tests:
framework: net7.0
sdk: "7.0.404"
sdk-major-minor: "7.0"
framework: net8.0
sdk: "8.0.100"
sdk-major-minor: "8.0"
name: ${{ matrix.job.os }}-sdk-${{ matrix.tests.sdk-major-minor }}
runs-on: ${{ matrix.job.os }}
steps:
- uses: actions/[email protected]
with:
dotnet-version: |
${{ matrix.tests.sdk }}
7.0.404
8.0.100
- run: dotnet --info
- run: git --version
- uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
dotnet-version: 7.0.404
dotnet-version: 8.0.100
- uses: actions/[email protected]
- env:
MINVER_VERSION: ${{ vars.MINVER_VERSION }}
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": ".NET Launch (console)",
"type": "coreclr",
"request": "launch",
"program": "${workspaceFolder}/targets/bin/Debug/net7.0/Targets.dll",
"program": "${workspaceFolder}/targets/bin/Debug/net8.0/Targets.dll",
"args": [
"default"
],
Expand Down
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<!-- workaround for https:/dotnet/roslyn/issues/41640 -->
<NoWarn>EnableGenerateDocumentationFile</NoWarn>
<Nullable>enable</Nullable>
<!-- MinVer doesn't use MinVer for versioning because
the environment variables for the build and for the package tests
Expand Down
8 changes: 3 additions & 5 deletions MinVer.Lib/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

namespace MinVer.Lib;

internal sealed class Commit
internal sealed class Commit(string sha)
{
public Commit(string sha) => this.Sha = sha;

public string Sha { get; }
public string Sha { get; } = sha;

public string ShortSha => this.Sha[..Math.Min(7, this.Sha.Length)];

public List<Commit> Parents { get; } = new();
public List<Commit> Parents { get; } = [];

public override string ToString() => this.ShortSha;
}
10 changes: 6 additions & 4 deletions MinVer.Lib/Git.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace MinVer.Lib;

internal static class Git
{
private static readonly char[] newLineChars = ['\r', '\n',];

public static bool IsWorkingDirectory(string directory, ILogger log) => GitCommand.TryRun("status --short", directory, log, out _);

public static bool TryGetHead(string directory, [NotNullWhen(returnValue: true)] out Commit? head, ILogger log)
Expand All @@ -18,7 +20,7 @@ public static bool TryGetHead(string directory, [NotNullWhen(returnValue: true)]
return false;
}

var lines = output.Split(new[] { '\r', '\n', }, StringSplitOptions.RemoveEmptyEntries);
var lines = output.Split(newLineChars, StringSplitOptions.RemoveEmptyEntries);

if (lines.Length == 0)
{
Expand All @@ -28,7 +30,7 @@ public static bool TryGetHead(string directory, [NotNullWhen(returnValue: true)]
var commits = new Dictionary<string, Commit>();

foreach (var shas in lines
.Select(line => line.Split(new[] { ' ', }, StringSplitOptions.RemoveEmptyEntries)))
.Select(line => line.Split(" ", StringSplitOptions.RemoveEmptyEntries)))
{
commits.GetOrAdd(shas[0], () => new Commit(shas[0]))
.Parents.AddRange(shas.Skip(1).Select(parentSha => commits.GetOrAdd(parentSha, () => new Commit(parentSha))));
Expand All @@ -42,8 +44,8 @@ public static bool TryGetHead(string directory, [NotNullWhen(returnValue: true)]
public static IEnumerable<(string Name, string Sha)> GetTags(string directory, ILogger log) =>
GitCommand.TryRun("show-ref --tags --dereference", directory, log, out var output)
? output
.Split(new[] { '\r', '\n', }, StringSplitOptions.RemoveEmptyEntries)
.Select(line => line.Split(new[] { ' ', }, 2))
.Split(newLineChars, StringSplitOptions.RemoveEmptyEntries)
.Select(line => line.Split(" ", 2))
.Select(tokens => (tokens[1][10..].RemoveFromEnd("^{}"), tokens[0]))
: Enumerable.Empty<(string, string)>();

Expand Down
3 changes: 1 addition & 2 deletions MinVer.Lib/MinVer.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="NuGet.Versioning" Version="6.8.0" />
</ItemGroup>

Expand Down
5 changes: 1 addition & 4 deletions MinVer.Lib/NoGitException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
namespace MinVer.Lib;

#pragma warning disable CA1032 // Implement standard exception constructors
public class NoGitException : Exception
public class NoGitException(string message, Exception innerException) : Exception(message, innerException)
#pragma warning restore CA1032
{
public NoGitException(string message, Exception innerException) : base(message, innerException)
{
}
}
35 changes: 14 additions & 21 deletions MinVer.Lib/Versioner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ private static List<Candidate> GetCandidates(Commit head, IEnumerable<(string Na
}
}

tagsAndVersions = tagsAndVersions
.OrderBy(tagAndVersion => tagAndVersion.Version)
.ThenBy(tagsAndVersion => tagsAndVersion.Name)
.ToList();
tagsAndVersions =
[
.. tagsAndVersions
.OrderBy(tagAndVersion => tagAndVersion.Version)
.ThenBy(tagsAndVersion => tagsAndVersion.Name)
];

var itemsToCheck = new Stack<(Commit Commit, int Height, Commit? Child)>();
itemsToCheck.Push((head, 0, null));
Expand All @@ -117,7 +119,7 @@ private static List<Candidate> GetCandidates(Commit head, IEnumerable<(string Na

var commitTagsAndVersions = tagsAndVersions.Where(tagAndVersion => tagAndVersion.Sha == item.Commit.Sha).ToList();

if (commitTagsAndVersions.Any())
if (commitTagsAndVersions.Count != 0)
{
foreach (var (name, _, version) in commitTagsAndVersions)
{
Expand All @@ -131,7 +133,7 @@ private static List<Candidate> GetCandidates(Commit head, IEnumerable<(string Na

_ = log.IsTraceEnabled && log.Trace($"Found no version tags on commit {item.Commit}.");

if (!item.Commit.Parents.Any())
if (item.Commit.Parents.Count == 0)
{
candidates.Add(new Candidate(item.Commit, item.Height, "", new Version(defaultPreReleaseIdentifiers), candidates.Count));
_ = log.IsTraceEnabled && log.Trace($"Found root commit {candidates.Last()}.");
Expand All @@ -157,26 +159,17 @@ private static List<Candidate> GetCandidates(Commit head, IEnumerable<(string Na
return candidates;
}

private sealed class Candidate
private sealed class Candidate(Commit commit, int height, string tag, Version version, int index)
{
public Candidate(Commit commit, int height, string tag, Version version, int index)
{
this.Commit = commit;
this.Height = height;
this.Tag = tag;
this.Version = version;
this.Index = index;
}

public Commit Commit { get; }
public Commit Commit { get; } = commit;

public int Height { get; }
public int Height { get; } = height;

public string Tag { get; }
public string Tag { get; } = tag;

public Version Version { get; }
public Version Version { get; } = version;

public int Index { get; }
public int Index { get; } = index;

public override string ToString() => this.ToString(0, 0, 0);

Expand Down
6 changes: 2 additions & 4 deletions MinVer/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

namespace MinVer;

internal sealed class Logger : ILogger
internal sealed class Logger(Verbosity verbosity) : ILogger
{
private readonly Verbosity verbosity;

public Logger(Verbosity verbosity) => this.verbosity = verbosity;
private readonly Verbosity verbosity = verbosity;

public bool IsTraceEnabled => this.verbosity >= Verbosity.Diagnostic;

Expand Down
3 changes: 1 addition & 2 deletions MinVer/MinVer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<RollForward>major</RollForward>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>default</LangVersion>
</PropertyGroup>

Expand All @@ -29,7 +29,6 @@

<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.0" PrivateAssets="All" Publish="true" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Update="Microsoft.NETCore.App" PrivateAssets="All" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions MinVer/build/MinVer.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<MinVerDetailed Condition="'$(MinVerVerbosity)' == 'detailed' Or '$(MinVerVerbosity)' == 'd' Or '$(MinVerVerbosity)' == 'diagnostic' Or '$(MinVerVerbosity)' == 'diag'">high</MinVerDetailed>
<MinVerTargetFramework>net6.0</MinVerTargetFramework>
<MinVerTargetFramework Condition="'$(MSBuildAssemblyVersion)' &gt;= '17.4'">net7.0</MinVerTargetFramework>
<MinVerTargetFramework Condition="'$(MSBuildAssemblyVersion)' &gt;= '17.8'">net8.0</MinVerTargetFramework>
<NoWarn>$(NoWarn);NU5105</NoWarn>
</PropertyGroup>

Expand Down
3 changes: 3 additions & 0 deletions MinVerTests.Infra/MinVerCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public static string GetPath(string configuration) =>
#endif
#if NET7_0
Solution.GetFullPath($"minver-cli/bin/{configuration}/net7.0/minver-cli.dll");
#endif
#if NET8_0
Solution.GetFullPath($"minver-cli/bin/{configuration}/net8.0/minver-cli.dll");
#endif
}
}
2 changes: 1 addition & 1 deletion MinVerTests.Infra/MinVerTests.Infra.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 75d923d

Please sign in to comment.