Skip to content

Commit

Permalink
♻️ (MigrationTools): refactor version detection and update XML docume…
Browse files Browse the repository at this point in the history
…ntation

- Update `MigrationTools.xml` to reflect the latest commit and version info.
- Replace `GetRunningVersion` with `DetectVersionService2.GetRunningVersion` in `MigrationToolHost.cs`.
- Remove the `GetRunningVersion` method from `MigrationToolHost.cs`.
- Enhance `DetectVersionService2` to handle local version detection more robustly.

The changes improve the maintainability and accuracy of version detection by centralizing the logic in `DetectVersionService2`. This also ensures that the XML documentation is up-to-date with the latest commit and version information.
  • Loading branch information
MrHinsh committed Jul 25, 2024
1 parent 3a2c737 commit 6b65ba1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
14 changes: 7 additions & 7 deletions docs/Reference/Generated/MigrationTools.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 1 addition & 18 deletions src/MigrationTools.Host/MigrationToolHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static IHostBuilder CreateDefaultBuilder(string[] args)

hostBuilder.UseSerilog((hostingContext, services, loggerConfiguration) =>
{
string outputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] [" + GetRunningVersion().versionString + "] {Message:lj}{NewLine}{Exception}"; // {SourceContext}
string outputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] [" + DetectVersionService2.GetRunningVersion().versionString + "] {Message:lj}{NewLine}{Exception}"; // {SourceContext}
string logsPath = CreateLogsPath();
var logPath = Path.Combine(logsPath, $"migration{logs}.log");
Expand Down Expand Up @@ -153,23 +153,6 @@ public static IHostBuilder CreateDefaultBuilder(string[] args)
return hostBuilder;
}

public static (Version version, string PreReleaseLabel, string versionString) GetRunningVersion()
{
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly()?.Location);
var matches = Regex.Matches(myFileVersionInfo.ProductVersion, @"^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<build>0|[1-9]\d*)(?:-((?<label>:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<fullEnd>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$");
Version version = new Version(myFileVersionInfo.FileVersion);
string textVersion = "0.0.0-local";
if (version.CompareTo(new Version(0, 0, 0, 0)) == 0)
{
textVersion = ThisAssembly.Git.SemVer.Major + "." + ThisAssembly.Git.SemVer.Minor + "." + ThisAssembly.Git.SemVer.Patch + "-" + matches[0].Groups[1].Value;
}
else
{
textVersion = version.Major + "." + version.Minor + "." + version.Build + "-" + matches[0].Groups[1].Value;
}
return (version, matches[0].Groups[1].Value, textVersion);
}

public static async Task RunMigrationTools(this IHostBuilder hostBuilder, string[] args)
{
var host = hostBuilder.Build();
Expand Down
15 changes: 14 additions & 1 deletion src/MigrationTools.Host/Services/DetectVersionService2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,20 @@ public static (Version version, string PreReleaseLabel, string versionString) Ge
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly()?.Location);
var matches = Regex.Matches(myFileVersionInfo.ProductVersion, @"^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<build>0|[1-9]\d*)(?:-((?<label>:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<fullEnd>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$");
Version version = new Version(myFileVersionInfo.FileVersion);
string textVersion = "v" + version.Major + "." + version.Minor + "." + version.Build + "-" + matches[0].Groups[1].Value;
string textVersion = "0.0.0-local";
if (version.CompareTo(new Version(0, 0, 0, 0)) == 0)
{
textVersion = ThisAssembly.Git.Tag.Replace("Preview", "Local");
//textVersion = ThisAssembly.Git.SemVer.Major + "." + ThisAssembly.Git.SemVer.Minor + "." + ThisAssembly.Git.SemVer.Patch + "-" + matches[0].Groups[1].Value;
//if (!string.IsNullOrEmpty(ThisAssembly.Git.Commits))
//{
// textVersion += "." + ThisAssembly.Git.Commits;
//}
}
else
{
textVersion = version.Major + "." + version.Minor + "." + version.Build + "-" + matches[0].Groups[1].Value;
}
return (version, matches[0].Groups[1].Value, textVersion);
}
}
Expand Down

0 comments on commit 6b65ba1

Please sign in to comment.