diff --git a/Tests/CodexContinuousTests/ContinuousTestRunner.cs b/Tests/CodexContinuousTests/ContinuousTestRunner.cs index e1808d9..1816960 100644 --- a/Tests/CodexContinuousTests/ContinuousTestRunner.cs +++ b/Tests/CodexContinuousTests/ContinuousTestRunner.cs @@ -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(); diff --git a/Tests/CodexContinuousTests/SingleTestRun.cs b/Tests/CodexContinuousTests/SingleTestRun.cs index 24b47a7..033e9c9 100644 --- a/Tests/CodexContinuousTests/SingleTestRun.cs +++ b/Tests/CodexContinuousTests/SingleTestRun.cs @@ -187,12 +187,11 @@ namespace ContinuousTests private Dictionary CreateStatusLogData(DateTime testStart, string message) { - return new Dictionary - { - { "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) diff --git a/Tests/DistTestCore/DistTest.cs b/Tests/DistTestCore/DistTest.cs index 0cfdbe5..74898d5 100644 --- a/Tests/DistTestCore/DistTest.cs +++ b/Tests/DistTestCore/DistTest.cs @@ -58,6 +58,7 @@ namespace DistTestCore throw; } + fixtureLog.Log("Test framework revision: " + GitInfo.GetStatus()); fixtureLog.Log("Global setup cleanup successful"); } diff --git a/Tests/DistTestCore/DistTestCore.csproj b/Tests/DistTestCore/DistTestCore.csproj index 91d1fd0..d86168f 100644 --- a/Tests/DistTestCore/DistTestCore.csproj +++ b/Tests/DistTestCore/DistTestCore.csproj @@ -8,6 +8,7 @@ + diff --git a/Tests/DistTestCore/GitInfo.cs b/Tests/DistTestCore/GitInfo.cs new file mode 100644 index 0000000..51f8bbf --- /dev/null +++ b/Tests/DistTestCore/GitInfo.cs @@ -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; + } + } +} diff --git a/Tests/DistTestCore/Logs/StatusLog.cs b/Tests/DistTestCore/Logs/StatusLog.cs index 0bb82f9..8c097ad 100644 --- a/Tests/DistTestCore/Logs/StatusLog.cs +++ b/Tests/DistTestCore/Logs/StatusLog.cs @@ -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); } diff --git a/Tests/DistTestCore/TestLifecycle.cs b/Tests/DistTestCore/TestLifecycle.cs index 896ab66..b386343 100644 --- a/Tests/DistTestCore/TestLifecycle.cs +++ b/Tests/DistTestCore/TestLifecycle.cs @@ -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) {