fix(viewer): keep public simulator version stable without git hash or padded spaces
This commit is contained in:
1 parent
74eaea49bf
commit
ae4b194b44
4 files changed
+95
-58
No files matched your search
@@ -34,6 +34,9 @@ jobs:
|
||||
- name: Build Generation 1.1 server and addons
|
||||
run: dotnet build OpenSim.sln --configuration Release --no-restore
|
||||
|
||||
- name: Regression-test stable simulator version without Git commit
|
||||
run: dotnet run --configuration Release --project tools/ci/PublicSimulatorVersionRegression/PublicSimulatorVersionRegression.csproj
|
||||
|
||||
- name: Regression-test .NET 10 Flotsam disk-cache serialization
|
||||
run: dotnet run --configuration Release --project tools/ci/FlotsamCacheNet10Regression/FlotsamCacheNet10Regression.csproj
|
||||
|
||||
@@ -67,6 +70,10 @@ jobs:
|
||||
shell: cmd
|
||||
run: dotnet build OpenSim.sln --configuration Release
|
||||
|
||||
- name: Regression-test stable simulator version on Windows
|
||||
shell: pwsh
|
||||
run: dotnet run --configuration Release --project tools/ci/PublicSimulatorVersionRegression/PublicSimulatorVersionRegression.csproj
|
||||
|
||||
- name: Regression-test .NET 10 Flotsam disk-cache serialization on Windows
|
||||
shell: pwsh
|
||||
run: dotnet run --configuration Release --project tools/ci/FlotsamCacheNet10Regression/FlotsamCacheNet10Regression.csproj
|
||||
|
||||
@@ -33,7 +33,6 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using log4net;
|
||||
using log4net.Appender;
|
||||
@@ -75,15 +74,19 @@ namespace OpenSim.Framework.Servers
|
||||
protected ServerStatsCollector m_serverStatsCollector;
|
||||
|
||||
/// <summary>
|
||||
/// Server version information. Usually VersionInfo + information about git commit, operating system, etc.
|
||||
/// Stable public simulator version for viewer RegionHandshake.
|
||||
/// Never include a .version file or Git SHA: adjacent regions built
|
||||
/// from different commits must not look like different server products.
|
||||
/// Build diagnostics remain available separately in VersionInfo.
|
||||
/// </summary>
|
||||
protected string m_version;
|
||||
|
||||
public ServerBase()
|
||||
{
|
||||
m_startuptime = DateTime.Now;
|
||||
m_version = VersionInfo.Version;
|
||||
EnhanceVersionInformation();
|
||||
// VersionInfo.Version is padded for legacy protocol compatibility.
|
||||
// Trim only its trailing spaces before Scene appends the platform.
|
||||
m_version = VersionInfo.Version.TrimEnd();
|
||||
}
|
||||
|
||||
protected void CreatePIDFile(string path)
|
||||
@@ -753,60 +756,6 @@ namespace OpenSim.Framework.Servers
|
||||
Notice(String.Format("Console log level: {0}", m_consoleAppender.Threshold));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enhance the version string with extra information if it's available.
|
||||
/// </summary>
|
||||
protected void EnhanceVersionInformation()
|
||||
{
|
||||
const string manualVersionFileName = ".version";
|
||||
string buildVersion = string.Empty;
|
||||
|
||||
if (File.Exists(manualVersionFileName))
|
||||
{
|
||||
using (StreamReader CommitFile = File.OpenText(manualVersionFileName))
|
||||
buildVersion = CommitFile.ReadLine();
|
||||
|
||||
if (!string.IsNullOrEmpty(buildVersion))
|
||||
{
|
||||
m_version += buildVersion;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string gitDir = Path.Combine("..", ".git");
|
||||
string gitRefPointerPath = Path.Combine(gitDir, "HEAD");
|
||||
if (File.Exists(gitRefPointerPath))
|
||||
{
|
||||
//m_log.DebugFormat("[SERVER BASE]: Found {0}", gitRefPointerPath);
|
||||
|
||||
string rawPointer = "";
|
||||
|
||||
using (StreamReader pointerFile = File.OpenText(gitRefPointerPath))
|
||||
rawPointer = pointerFile.ReadLine();
|
||||
|
||||
//m_log.DebugFormat("[SERVER BASE]: rawPointer [{0}]", rawPointer);
|
||||
|
||||
Match m = Regex.Match(rawPointer, "^ref: (.+)$");
|
||||
|
||||
if (m.Success)
|
||||
{
|
||||
//m_log.DebugFormat("[SERVER BASE]: Matched [{0}]", m.Groups[1].Value);
|
||||
|
||||
string gitRef = m.Groups[1].Value;
|
||||
string gitRefPath = Path.Combine(gitDir, gitRef);
|
||||
if (File.Exists(gitRefPath))
|
||||
{
|
||||
//m_log.DebugFormat("[SERVER BASE]: Found gitRefPath [{0}]", gitRefPath);
|
||||
using (StreamReader refFile = File.OpenText(gitRefPath))
|
||||
buildVersion = refFile.ReadLine();
|
||||
|
||||
if (!string.IsNullOrEmpty(buildVersion))
|
||||
m_version += buildVersion[..7];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetVersionText()
|
||||
{
|
||||
return $"Version: {m_version} (SIM-{VersionInfo.SimulationServiceVersionSupportedMin}/{VersionInfo.SimulationServiceVersionSupportedMax})";
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using OpenSim;
|
||||
using OpenSim.Framework.Servers;
|
||||
|
||||
// Exercise the actual ServerBase version advertised through Scene's
|
||||
// RegionHandshake, including a checkout with a stamped .version file.
|
||||
internal static class Program
|
||||
{
|
||||
private static int Main()
|
||||
{
|
||||
string originalDirectory = Directory.GetCurrentDirectory();
|
||||
string root = Path.Combine(Path.GetTempPath(),
|
||||
"ogl-public-simulator-version-" + Guid.NewGuid().ToString("N"));
|
||||
string working = Path.Combine(root, "bin");
|
||||
Directory.CreateDirectory(working);
|
||||
|
||||
try
|
||||
{
|
||||
Directory.SetCurrentDirectory(working);
|
||||
File.WriteAllText(".version", "74eaea4");
|
||||
|
||||
string expected = "Version: OpenGenesisLINK Generation 1 (SIM-" +
|
||||
VersionInfo.SimulationServiceVersionSupportedMin + "/" +
|
||||
VersionInfo.SimulationServiceVersionSupportedMax + ")";
|
||||
string actual = new ServerBase().GetVersionText();
|
||||
Check(actual == expected, "stamped .version must not alter public version: " + actual);
|
||||
|
||||
File.Delete(".version");
|
||||
Directory.CreateDirectory(Path.Combine(root, ".git", "refs", "heads"));
|
||||
File.WriteAllText(Path.Combine(root, ".git", "HEAD"), "ref: refs/heads/main");
|
||||
File.WriteAllText(Path.Combine(root, ".git", "refs", "heads", "main"),
|
||||
"74eaea49bfa4efbb1f3f0c9c5889fe4686cd872b");
|
||||
actual = new ServerBase().GetVersionText();
|
||||
Check(actual == expected, "checkout Git HEAD must not alter public version: " + actual);
|
||||
|
||||
// Scene adds a platform label; the public version must have
|
||||
// exactly one separator and no commit identifier.
|
||||
string simulatedHandshake = VersionInfo.PublicVersionName +
|
||||
" (X64/Unix/DotNet)";
|
||||
Check(!simulatedHandshake.Contains("74eaea4"), "Git SHA leaked");
|
||||
Check(VersionInfo.Version.TrimEnd() == VersionInfo.PublicVersionName,
|
||||
"legacy VersionInfo padding changed unexpectedly");
|
||||
|
||||
Console.WriteLine("PASS: stable OpenGenesisLINK Generation 1 viewer version; " +
|
||||
".version and Git HEAD cannot alter RegionHandshake identity");
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.Error.WriteLine(e);
|
||||
return 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Directory.SetCurrentDirectory(originalDirectory);
|
||||
Directory.Delete(root, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Check(bool condition, string message)
|
||||
{
|
||||
if (!condition)
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../../OpenSim/Framework/OpenSim.Framework.csproj" />
|
||||
<ProjectReference Include="../../../OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj" />
|
||||
<Reference Include="log4net">
|
||||
<HintPath>../../../bin/log4net.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in new issue
Block a user