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

drop support for .NET Core 2.1 #586

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ jobs:
tests:
framework: net5.0
sdk: "5.0.301"
- job:
os: ubuntu-20.04
build: ./build.sh
tests:
framework: netcoreapp2.1
sdk: "2.1.816"
- job:
os: ubuntu-20.04
build: ./build.sh
Expand Down
2 changes: 1 addition & 1 deletion MinVer.Lib/Git.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static IEnumerable<Tag> GetTagsOrEmpty(string directory, ILogger log) =>
? output
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
.Select(line => line.Split(new[] { ' ' }, 2))
.Select(tokens => new Tag(tokens[1].Substring(10).RemoveFromEnd("^{}"), tokens[0]))
.Select(tokens => new Tag(tokens[1][10..].RemoveFromEnd("^{}"), tokens[0]))
: Enumerable.Empty<Tag>();

private static string RemoveFromEnd(this string text, string value) =>
Expand Down
81 changes: 40 additions & 41 deletions MinVer.Lib/GitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,48 @@ internal static class GitCommand
{
public static bool TryRun(string args, string workingDirectory, ILogger log, out string output)
{
using (var process = new Process())
using var process = new Process();

process.StartInfo = new ProcessStartInfo
{
FileName = "git",
Arguments = args,
WorkingDirectory = workingDirectory,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
};

var tcs = new TaskCompletionSource<object>();
process.Exited += (s, e) => tcs.SetResult(default);
process.EnableRaisingEvents = true;

log.Trace($"Running Git: {process.StartInfo.FileName} {process.StartInfo.Arguments}");

try
{
_ = process.Start();
}
catch (Win32Exception ex)
{
process.StartInfo = new ProcessStartInfo
{
FileName = "git",
Arguments = args,
WorkingDirectory = workingDirectory,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
};

var tcs = new TaskCompletionSource<object>();
process.Exited += (s, e) => tcs.SetResult(default);
process.EnableRaisingEvents = true;

log.Trace($"Running Git: {process.StartInfo.FileName} {process.StartInfo.Arguments}");

try
{
_ = process.Start();
}
catch (Win32Exception ex)
{
throw new InvalidOperationException("\"git\" is not present in PATH.", ex);
}

var runProcess = tcs.Task;
var readOutput = process.StandardOutput.ReadToEndAsync();
var readError = process.StandardError.ReadToEndAsync();

Task.WaitAll(runProcess, readOutput, readError);

var exitCode = process.ExitCode;
output = readOutput.Result;
var error = readError.Result;

log.Trace($"Git exit code: {exitCode}");
log.Trace($"Git stdout:{Environment.NewLine}{output}");
log.Trace($"Git stderr:{Environment.NewLine}{error}");

return exitCode == 0;
throw new InvalidOperationException("\"git\" is not present in PATH.", ex);
}

var runProcess = tcs.Task;
var readOutput = process.StandardOutput.ReadToEndAsync();
var readError = process.StandardError.ReadToEndAsync();

Task.WaitAll(runProcess, readOutput, readError);

var exitCode = process.ExitCode;
output = readOutput.Result;
var error = readError.Result;

log.Trace($"Git exit code: {exitCode}");
log.Trace($"Git stdout:{Environment.NewLine}{output}");
log.Trace($"Git stderr:{Environment.NewLine}{error}");

return exitCode == 0;
}
}
}
2 changes: 1 addition & 1 deletion MinVer.Lib/MinVer.Lib.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
29 changes: 10 additions & 19 deletions MinVer.Lib/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,16 @@ public Version Satisfying(MajorMinor minMajorMinor, string defaultPreReleasePhas
? this
: new Version(minMajorMinor.Major, minMajorMinor.Minor, 0, new[] { defaultPreReleasePhase, "0" }, this.height, this.buildMetadata);

public Version WithHeight(int height, VersionPart autoIncrement, string defaultPreReleasePhase)
{
if (this.preReleaseIdentifiers.Count == 0 && height > 0)
{
switch (autoIncrement)
public Version WithHeight(int height, VersionPart autoIncrement, string defaultPreReleasePhase) =>
this.preReleaseIdentifiers.Count == 0 && height > 0
? autoIncrement switch
{
case VersionPart.Major:
return new Version(this.major + 1, 0, 0, new[] { defaultPreReleasePhase, "0" }, height, null);
case VersionPart.Minor:
return new Version(this.major, this.minor + 1, 0, new[] { defaultPreReleasePhase, "0" }, height, null);
case VersionPart.Patch:
return new Version(this.major, this.minor, this.patch + 1, new[] { defaultPreReleasePhase, "0" }, height, null);
default:
throw new ArgumentOutOfRangeException(nameof(autoIncrement));
VersionPart.Major => new Version(this.major + 1, 0, 0, new[] { defaultPreReleasePhase, "0" }, height, null),
VersionPart.Minor => new Version(this.major, this.minor + 1, 0, new[] { defaultPreReleasePhase, "0" }, height, null),
VersionPart.Patch => new Version(this.major, this.minor, this.patch + 1, new[] { defaultPreReleasePhase, "0" }, height, null),
_ => throw new ArgumentOutOfRangeException(nameof(autoIncrement)),
}
}

return new Version(this.major, this.minor, this.patch, this.preReleaseIdentifiers, height, height == 0 ? this.buildMetadata : null);
}
: new Version(this.major, this.minor, this.patch, this.preReleaseIdentifiers, height, height == 0 ? this.buildMetadata : null);

public Version AddBuildMetadata(string buildMetadata)
{
Expand All @@ -132,7 +123,7 @@ public Version AddBuildMetadata(string buildMetadata)
public static bool TryParse(string text, out Version version) => (version = ParseOrDefault(text, null)) != null;

public static Version ParseOrDefault(string text, string prefix) =>
text == null || !text.StartsWith(prefix ?? "", StringComparison.OrdinalIgnoreCase) ? null : ParseOrDefault(text.Substring(prefix?.Length ?? 0));
text == null || !text.StartsWith(prefix ?? "", StringComparison.OrdinalIgnoreCase) ? null : ParseOrDefault(text[(prefix?.Length ?? 0)..]);

private static Version ParseOrDefault(string text)
{
Expand Down Expand Up @@ -168,7 +159,7 @@ public override int GetHashCode()
code = (code * 23) + this.patch.GetHashCode();
code = (code * 23) + this.preReleaseIdentifiers.GetHashCode();
code = (code * 23) + this.height.GetHashCode();
code = (code * 23) + this.buildMetadata.GetHashCode();
code = (code * 23) + this.buildMetadata.GetHashCode(StringComparison.Ordinal);

return code;
}
Expand Down
2 changes: 1 addition & 1 deletion MinVer.Lib/Versioner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class Versioner
{
public static Version GetVersion(string workDir, string tagPrefix, MajorMinor minMajorMinor, string buildMeta, VersionPart autoIncrement, string defaultPreReleasePhase, ILogger log)
{
log = log ?? new NullLogger();
log ??= new NullLogger();

defaultPreReleasePhase = string.IsNullOrEmpty(defaultPreReleasePhase)
? "alpha"
Expand Down
2 changes: 1 addition & 1 deletion 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>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion MinVer/VerbosityMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static VerbosityMap()
Add(Verbosity.Detailed, 1);
Add(Verbosity.Diagnostic, 4);

void Add(Verbosity verbosity, int shortLength)
static void Add(Verbosity verbosity, int shortLength)
{
map.Add(verbosity.ToString(), verbosity);
map.Add(verbosity.ToString().Substring(0, shortLength), verbosity);
Expand Down
4 changes: 0 additions & 4 deletions MinVerTests.Infra/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ private static void DeleteDirectory(string path)
// Directory.Delete fails if anything in the tree has the read-only attribute set. ¯\_(ツ)_/¯
ResetAttributes(new DirectoryInfo(path));

#if NET
static void ResetAttributes(DirectoryInfo directory)
#else
void ResetAttributes(DirectoryInfo directory)
#endif
{
foreach (var childDirectory in directory.GetDirectories())
{
Expand Down
2 changes: 1 addition & 1 deletion MinVerTests.Infra/MinVerCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public static class MinVerCli
}

public static string GetPath(string configuration) =>
Solution.GetFullPath($"minver-cli/bin/{configuration}/netcoreapp2.1/minver-cli.dll");
Solution.GetFullPath($"minver-cli/bin/{configuration}/netcoreapp3.1/minver-cli.dll");
}
}
2 changes: 1 addition & 1 deletion MinVerTests.Infra/MinVerTests.Infra.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 1 addition & 5 deletions MinVerTests.Lib/MinVerTests.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

<PropertyGroup>
<RollForward>major</RollForward>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<CopyLocalLockFileAssemblies Condition="'$(TargetFramework)' == 'netcoreapp2.1'">true</CopyLocalLockFileAssemblies>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion MinVerTests.Packages/MultipleProjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MultipleProjects

public MultipleProjects(ITestOutputHelper output) => this.output = output;

// for some reason, when using SDK 2.1 or 3.1,
// for some reason, when using SDK 3.1,
// there is a 15 minute delay after the `dotnet build` command,
// so we only run this test on SDK 5.0 and later
[Net5PlusFact]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Also available as a [command line tool](#can-i-use-minver-to-version-software-wh

## Prerequisites

- [.NET Core SDK 2.1 or later](https://www.microsoft.com/net/download)
- [.NET Core SDK 3.1 or later](https://www.microsoft.com/net/download)
- [Git](https://git-scm.com/)

## Quick start
Expand Down
Loading