diff --git a/CHANGELOG.md b/CHANGELOG.md index ec9cf9f5..924a92e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Please ADD ALL Changes to the UNRELEASED SECTION and not a specific release - Dependencies - Updated xunit.analyzers to 1.7.0 - Dependencies - Updated xunit to 2.6.3 - Dependencies - Updated xunit.runner.visualstudio to 2.5.5 +- Dependencies - Updated Nullable.Extended.Analyzer to 1.14.6129 ### Removed ### Deployment Changes diff --git a/src/FunFair.BuildVersion.Detection.Tests/FunFair.BuildVersion.Detection.Tests.csproj b/src/FunFair.BuildVersion.Detection.Tests/FunFair.BuildVersion.Detection.Tests.csproj index abcda50b..d98ae0f4 100644 --- a/src/FunFair.BuildVersion.Detection.Tests/FunFair.BuildVersion.Detection.Tests.csproj +++ b/src/FunFair.BuildVersion.Detection.Tests/FunFair.BuildVersion.Detection.Tests.csproj @@ -60,7 +60,7 @@ - + diff --git a/src/FunFair.BuildVersion.Detection/BranchClassification.cs b/src/FunFair.BuildVersion.Detection/BranchClassification.cs index 3a0bad37..08228891 100644 --- a/src/FunFair.BuildVersion.Detection/BranchClassification.cs +++ b/src/FunFair.BuildVersion.Detection/BranchClassification.cs @@ -9,16 +9,16 @@ namespace FunFair.BuildVersion.Detection; public sealed class BranchClassification : IBranchClassification { - private const string PULL_REQUEST_PREFIX = @"refs/pull/"; - private const string PULL_REQUEST_SUFFIX = @"/head"; + private const string PULL_REQUEST_PREFIX = "refs/pull/"; + private const string PULL_REQUEST_SUFFIX = "/head"; private readonly string _hotfixBranch; private readonly string _releaseBranch; public BranchClassification(IBranchSettings branchSettings) { - this._releaseBranch = BuildBranch(branchSettings: branchSettings, branch: @"release"); - this._hotfixBranch = BuildBranch(branchSettings: branchSettings, branch: @"hotfix"); + this._releaseBranch = BuildBranch(branchSettings: branchSettings, branch: "release"); + this._hotfixBranch = BuildBranch(branchSettings: branchSettings, branch: "hotfix"); } public bool IsRelease(string branchName, [NotNullWhen(true)] out NuGetVersion? version) diff --git a/src/FunFair.BuildVersion.Detection/ExternalBranchLocators/GitBranchEnvironmentVariableBranchLocator.cs b/src/FunFair.BuildVersion.Detection/ExternalBranchLocators/GitBranchEnvironmentVariableBranchLocator.cs index c6f8330b..7bc107de 100644 --- a/src/FunFair.BuildVersion.Detection/ExternalBranchLocators/GitBranchEnvironmentVariableBranchLocator.cs +++ b/src/FunFair.BuildVersion.Detection/ExternalBranchLocators/GitBranchEnvironmentVariableBranchLocator.cs @@ -5,7 +5,7 @@ namespace FunFair.BuildVersion.Detection.ExternalBranchLocators; public sealed class GitBranchEnvironmentVariableBranchLocator : EnvironmentVariableBranchLocator { public GitBranchEnvironmentVariableBranchLocator(ILogger logger) - : base(environmentVariable: @"GIT_BRANCH", logger: logger) + : base(environmentVariable: "GIT_BRANCH", logger: logger) { } } \ No newline at end of file diff --git a/src/FunFair.BuildVersion.Detection/ExternalBranchLocators/GitHubRefEnvironmentVariableBranchLocator.cs b/src/FunFair.BuildVersion.Detection/ExternalBranchLocators/GitHubRefEnvironmentVariableBranchLocator.cs index c615a9ce..4a4487cf 100644 --- a/src/FunFair.BuildVersion.Detection/ExternalBranchLocators/GitHubRefEnvironmentVariableBranchLocator.cs +++ b/src/FunFair.BuildVersion.Detection/ExternalBranchLocators/GitHubRefEnvironmentVariableBranchLocator.cs @@ -5,7 +5,7 @@ namespace FunFair.BuildVersion.Detection.ExternalBranchLocators; public sealed class GitHubRefEnvironmentVariableBranchLocator : EnvironmentVariableBranchLocator { public GitHubRefEnvironmentVariableBranchLocator(ILogger logger) - : base(environmentVariable: @"GITHUB_REF", logger: logger) + : base(environmentVariable: "GITHUB_REF", logger: logger) { } } \ No newline at end of file diff --git a/src/FunFair.BuildVersion.Detection/FunFair.BuildVersion.Detection.csproj b/src/FunFair.BuildVersion.Detection/FunFair.BuildVersion.Detection.csproj index f966329b..21a1c0b5 100644 --- a/src/FunFair.BuildVersion.Detection/FunFair.BuildVersion.Detection.csproj +++ b/src/FunFair.BuildVersion.Detection/FunFair.BuildVersion.Detection.csproj @@ -62,7 +62,7 @@ - + diff --git a/src/FunFair.BuildVersion.Detection/PreReleaseTagBuilder.cs b/src/FunFair.BuildVersion.Detection/PreReleaseTagBuilder.cs index 4ec0a4bf..404e527b 100644 --- a/src/FunFair.BuildVersion.Detection/PreReleaseTagBuilder.cs +++ b/src/FunFair.BuildVersion.Detection/PreReleaseTagBuilder.cs @@ -15,12 +15,9 @@ internal static class PreReleaseTagBuilder public static StringBuilder NormalizeSourceBranchName(this string currentBranch, IBranchClassification branchClassification) { - if (branchClassification.IsPullRequest(currentBranch: currentBranch, out long pullRequestId)) - { - return new(@"pr-" + pullRequestId.ToString(CultureInfo.InvariantCulture)); - } - - return new(currentBranch.ToLowerInvariant()); + return new(branchClassification.IsPullRequest(currentBranch: currentBranch, out long pullRequestId) + ? "pr-" + pullRequestId.ToString(CultureInfo.InvariantCulture) + : currentBranch.ToLowerInvariant()); } public static StringBuilder ReplaceInvalidCharacters(this StringBuilder suffix) @@ -81,7 +78,7 @@ public static string EnsureNotBlank(this StringBuilder suffix) if (string.IsNullOrWhiteSpace(usedSuffix)) { - return @"prerelease"; + return "prerelease"; } return usedSuffix; diff --git a/src/FunFair.BuildVersion.Detection/VersionDetector.cs b/src/FunFair.BuildVersion.Detection/VersionDetector.cs index c2e93e0d..3e4dd5a4 100644 --- a/src/FunFair.BuildVersion.Detection/VersionDetector.cs +++ b/src/FunFair.BuildVersion.Detection/VersionDetector.cs @@ -42,6 +42,14 @@ public NuGetVersion FindVersion(int buildNumber) private NuGetVersion DetermineLatestReleaseFromPreviousReleaseBranches(int buildNumber) { + IReadOnlyList branches = this._branchDiscovery.FindBranches(); + + NuGetVersion? latestVersion = branches.Select(GetReleaseVersion) + .RemoveNulls() + .Max(); + + return AddBuildNumberToVersion(latestVersion ?? InitialVersion, buildNumber: buildNumber); + NuGetVersion? GetReleaseVersion(string branch) { this._logger.LogDebug($" * => {branch}"); @@ -50,14 +58,6 @@ private NuGetVersion DetermineLatestReleaseFromPreviousReleaseBranches(int build ? version : null; } - - IReadOnlyList branches = this._branchDiscovery.FindBranches(); - - NuGetVersion? latestVersion = branches.Select(GetReleaseVersion) - .RemoveNulls() - .Max(); - - return AddBuildNumberToVersion(latestVersion ?? InitialVersion, buildNumber: buildNumber); } private static NuGetVersion AddBuildNumberToVersion(NuGetVersion version, int buildNumber) diff --git a/src/FunFair.BuildVersion.Interfaces/FunFair.BuildVersion.Interfaces.csproj b/src/FunFair.BuildVersion.Interfaces/FunFair.BuildVersion.Interfaces.csproj index 4bc56300..1550d97c 100644 --- a/src/FunFair.BuildVersion.Interfaces/FunFair.BuildVersion.Interfaces.csproj +++ b/src/FunFair.BuildVersion.Interfaces/FunFair.BuildVersion.Interfaces.csproj @@ -57,7 +57,7 @@ - + diff --git a/src/FunFair.BuildVersion.Publishers.Tests/FunFair.BuildVersion.Publishers.Tests.csproj b/src/FunFair.BuildVersion.Publishers.Tests/FunFair.BuildVersion.Publishers.Tests.csproj index 0608db02..c962f05a 100644 --- a/src/FunFair.BuildVersion.Publishers.Tests/FunFair.BuildVersion.Publishers.Tests.csproj +++ b/src/FunFair.BuildVersion.Publishers.Tests/FunFair.BuildVersion.Publishers.Tests.csproj @@ -57,7 +57,7 @@ - + diff --git a/src/FunFair.BuildVersion.Publishers/FunFair.BuildVersion.Publishers.csproj b/src/FunFair.BuildVersion.Publishers/FunFair.BuildVersion.Publishers.csproj index 30563d55..fdc44728 100644 --- a/src/FunFair.BuildVersion.Publishers/FunFair.BuildVersion.Publishers.csproj +++ b/src/FunFair.BuildVersion.Publishers/FunFair.BuildVersion.Publishers.csproj @@ -57,7 +57,7 @@ - + diff --git a/src/FunFair.BuildVersion.Publishers/GitHubActionsVersionPublisher.cs b/src/FunFair.BuildVersion.Publishers/GitHubActionsVersionPublisher.cs index e532a21a..c30a9971 100644 --- a/src/FunFair.BuildVersion.Publishers/GitHubActionsVersionPublisher.cs +++ b/src/FunFair.BuildVersion.Publishers/GitHubActionsVersionPublisher.cs @@ -14,10 +14,9 @@ public void Publish(NuGetVersion version) if (!string.IsNullOrEmpty(env)) { File.AppendAllLines(path: env, - new[] - { - $"BUILD_VERSION={version}" - }); + [ + $"BUILD_VERSION={version}" + ]); } } } \ No newline at end of file diff --git a/src/FunFair.BuildVersion/EnumExtensions.cs b/src/FunFair.BuildVersion/EnumExtensions.cs index 7ce2c41e..d5527622 100644 --- a/src/FunFair.BuildVersion/EnumExtensions.cs +++ b/src/FunFair.BuildVersion/EnumExtensions.cs @@ -10,4 +10,5 @@ namespace FunFair.BuildVersion; [SuppressMessage(category: "ReSharper", checkId: "PartialTypeWithSinglePart", Justification = "Needed for generated code")] internal static partial class EnumExtensions { + // Code generated } \ No newline at end of file diff --git a/src/FunFair.BuildVersion/ExecutableVersionInformation.cs b/src/FunFair.BuildVersion/ExecutableVersionInformation.cs index 5413ab9d..c1018d72 100644 --- a/src/FunFair.BuildVersion/ExecutableVersionInformation.cs +++ b/src/FunFair.BuildVersion/ExecutableVersionInformation.cs @@ -1,64 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; - -namespace FunFair.BuildVersion; +namespace FunFair.BuildVersion; internal static class ExecutableVersionInformation { - public static string ProgramVersion() - { - return CommonVersion(typeof(Program)); - } - - private static string CommonVersion(Type type) - { - Assembly assembly = type.Assembly; - - return GetAssemblyFileVersionFile() ?? GetAssemblyFileVersion(assembly) ?? GetAssemblyVersion(assembly); - } - - private static string? GetAssemblyFileVersionFile() - { - IReadOnlyList args = Environment.GetCommandLineArgs(); - - if (args.Count == 0) - { - return null; - } - - string location = args[0]; - - if (string.IsNullOrWhiteSpace(location) || !File.Exists(location)) - { - return null; - } - - FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(location); - - return fileVersionInfo.ProductVersion!; - } - - private static string? GetAssemblyFileVersion(Assembly assembly) - { - AssemblyFileVersionAttribute? fvi = assembly.GetCustomAttributes() - .FirstOrDefault(); - - return fvi?.Version; - } - - private static string GetAssemblyVersion(Assembly assembly) - { - Console.Write("Finding Assembly Version"); - Version? assemblyVersion = assembly.GetName() - .Version; - - return assemblyVersion is null - ? throw new VersionNotFoundException() - : assemblyVersion.ToString(); - } + public const string ProgramVersion = ThisAssembly.Info.FileVersion; } \ No newline at end of file diff --git a/src/FunFair.BuildVersion/FunFair.BuildVersion.csproj b/src/FunFair.BuildVersion/FunFair.BuildVersion.csproj index 32a4a192..9c43f114 100644 --- a/src/FunFair.BuildVersion/FunFair.BuildVersion.csproj +++ b/src/FunFair.BuildVersion/FunFair.BuildVersion.csproj @@ -70,7 +70,7 @@ - + @@ -78,6 +78,7 @@ + \ No newline at end of file diff --git a/src/FunFair.BuildVersion/Program.cs b/src/FunFair.BuildVersion/Program.cs index 6c1f17e2..28c5ff62 100644 --- a/src/FunFair.BuildVersion/Program.cs +++ b/src/FunFair.BuildVersion/Program.cs @@ -66,7 +66,7 @@ public static int Main(params string[] args) { try { - Console.WriteLine($"{typeof(Program).Namespace} {ExecutableVersionInformation.ProgramVersion()}"); + Console.WriteLine($"{typeof(Program).Namespace} {ExecutableVersionInformation.ProgramVersion}"); return Parser.Default.ParseArguments(args) .MapResult(parsedFunc: ParsedOk, notParsedFunc: NotParsed); @@ -145,7 +145,7 @@ private static int FindBuildNumber(int buildNumberFromCommandLine) return buildNumberFromCommandLine; } - string? buildNumber = Environment.GetEnvironmentVariable(variable: @"BUILD_NUMBER"); + string? buildNumber = Environment.GetEnvironmentVariable(variable: "BUILD_NUMBER"); if (!string.IsNullOrWhiteSpace(buildNumber)) {