Adds git revision information to logs for testing framework status

This commit is contained in:
benbierens 2023-11-13 11:56:02 +01:00
parent 412a4d3c7a
commit 0f9e01e393
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
7 changed files with 65 additions and 7 deletions

View File

@ -1,4 +1,5 @@
using DistTestCore.Logs;
using DistTestCore;
using DistTestCore.Logs;
using Logging;
using Newtonsoft.Json;
using Utils;
@ -43,6 +44,7 @@ namespace ContinuousTests
var taskFactory = new TaskFactory();
overviewLog.Log("Startup checks passed. Configuration:");
overviewLog.Log(JsonConvert.SerializeObject(config, Formatting.Indented));
overviewLog.Log("Test framework revision: " + GitInfo.GetStatus());
overviewLog.Log("Continuous tests starting...");
overviewLog.Log("");
var allTests = testFactory.CreateTests();

View File

@ -187,12 +187,11 @@ namespace ContinuousTests
private Dictionary<string, string> CreateStatusLogData(DateTime testStart, string message)
{
return new Dictionary<string, string>
{
{ "teststart", testStart.ToString("o") },
{ "testname", testName },
{ "message", message }
};
var result = entryPoint.GetPluginMetadata();
result.Add("teststart", testStart.ToString("o"));
result.Add("testname", testName);
result.Add("message", message);
return result;
}
private string GetCombinedExceptionsMessage(Exception[] exceptions)

View File

@ -58,6 +58,7 @@ namespace DistTestCore
throw;
}
fixtureLog.Log("Test framework revision: " + GitInfo.GetStatus());
fixtureLog.Log("Global setup cleanup successful");
}

View File

@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.28.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />

View File

@ -0,0 +1,53 @@
using KubernetesWorkflow;
using LibGit2Sharp;
using System.Reflection;
namespace DistTestCore
{
public static class GitInfo
{
private static string? status = null;
public static string GetStatus()
{
if (status == null) status = DetermineStatus();
return status;
}
private static string DetermineStatus()
{
var path = FindGitPath();
if (path == null) return "unknown";
using var repo = new Repository(path);
var isModified = repo.RetrieveStatus().Any(IsModified);
var sha = repo.Head.Tip.Sha.Substring(0, 7);
return K8sNameUtils.Format(sha + (isModified ? "_modified" : "_clean"));
}
private static bool IsModified(StatusEntry e)
{
return e.State == FileStatus.ModifiedInIndex ||
e.State == FileStatus.NewInIndex ||
e.State == FileStatus.RenamedInIndex ||
e.State == FileStatus.DeletedFromIndex ||
e.State == FileStatus.ModifiedInWorkdir ||
e.State == FileStatus.NewInWorkdir ||
e.State == FileStatus.RenamedInWorkdir ||
e.State == FileStatus.DeletedFromWorkdir;
}
private static string? FindGitPath()
{
var path = Repository.Discover(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
if (!string.IsNullOrEmpty(path)) return path;
path = Repository.Discover(Directory.GetCurrentDirectory());
if (!string.IsNullOrEmpty(path)) return path;
return null;
}
}
}

View File

@ -34,6 +34,7 @@ namespace DistTestCore.Logs
data.Add("testid", NameUtils.GetTestId());
data.Add("testtype", testType);
data.Add("testduration", testDuration);
data.Add("testframeworkrevision", GitInfo.GetStatus());
Write(data);
}

View File

@ -82,6 +82,7 @@ namespace DistTestCore
recipe.PodLabels.Add("category", NameUtils.GetCategoryName());
recipe.PodLabels.Add("fixturename", NameUtils.GetRawFixtureName());
recipe.PodLabels.Add("testname", NameUtils.GetTestMethodName());
recipe.PodLabels.Add("testframeworkrevision", GitInfo.GetStatus());
foreach (var pair in metadata)
{