Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ed6ab2f69 | |||
| 470b3d93de | |||
| b9059e1b85 | |||
| 3694e5703c | |||
| 80189e2414 | |||
| 213221e7d5 | |||
| f2cb5c30be | |||
| 4ec42cde84 |
@@ -2,6 +2,7 @@ using Objects;
|
||||
using Speckle.Automate.Sdk;
|
||||
using Speckle.Automate.Sdk.Schema;
|
||||
using Speckle.Core.Api;
|
||||
using Speckle.Core.Credentials;
|
||||
using Speckle.Core.Models;
|
||||
using Speckle.Core.Models.Extensions;
|
||||
using Speckle.Core.Transports;
|
||||
@@ -46,19 +47,25 @@ static class AutomateFunction
|
||||
Base? testingCommitObject = await automationContext.ReceiveVersion();
|
||||
Console.WriteLine("Received test version: " + testingCommitObject);
|
||||
Console.WriteLine("Receiving release version");
|
||||
using ServerTransport transport =
|
||||
new(
|
||||
automationContext.SpeckleClient.Account,
|
||||
automationContext.AutomationRunData.ProjectId
|
||||
);
|
||||
ServerTransport serverTransport = new ServerTransport(
|
||||
automationContext.SpeckleClient.Account,
|
||||
automationContext.AutomationRunData.ProjectId
|
||||
);
|
||||
Base? releaseCommitObject = await Operations
|
||||
.Receive(releaseCommit.referencedObject, transport)
|
||||
.Receive(
|
||||
(
|
||||
await automationContext.SpeckleClient
|
||||
.CommitGet(automationContext.AutomationRunData.ProjectId, releaseCommit.id)
|
||||
.ConfigureAwait(continueOnCapturedContext: false)
|
||||
).referencedObject,
|
||||
serverTransport,
|
||||
new MemoryTransport()
|
||||
)
|
||||
.ConfigureAwait(continueOnCapturedContext: false);
|
||||
if (releaseCommitObject == null)
|
||||
{
|
||||
throw new Exception("Commit root object was null");
|
||||
}
|
||||
|
||||
Console.WriteLine("Received release version: " + releaseCommitObject);
|
||||
|
||||
// flatten both commits
|
||||
@@ -67,7 +74,10 @@ static class AutomateFunction
|
||||
var releaseCommitObjectsDict = new Dictionary<string, Base>();
|
||||
foreach (var releaseObject in releaseCommitObjects)
|
||||
{
|
||||
if (!releaseCommitObjectsDict.ContainsKey(releaseObject.applicationId))
|
||||
if (
|
||||
releaseObject.applicationId != null
|
||||
&& !releaseCommitObjectsDict.ContainsKey(releaseObject.applicationId)
|
||||
)
|
||||
{
|
||||
releaseCommitObjectsDict.Add(releaseObject.applicationId, releaseObject);
|
||||
}
|
||||
@@ -79,12 +89,15 @@ static class AutomateFunction
|
||||
Console.WriteLine($"Found {testCommitObjects.Count()} objects in release version");
|
||||
|
||||
// compare objects
|
||||
int addedCount = 0;
|
||||
int modifiedCount = 0;
|
||||
int unchangedCount = 0;
|
||||
var addedList = new List<Tuple<string, string>>();
|
||||
var modifiedList = new List<Tuple<string, string, string>>();
|
||||
foreach (Base testObject in testCommitObjects)
|
||||
{
|
||||
if (releaseCommitObjectsDict.ContainsKey(testObject.applicationId))
|
||||
if (
|
||||
testObject.applicationId != null
|
||||
&& releaseCommitObjectsDict.ContainsKey(testObject.applicationId)
|
||||
)
|
||||
{
|
||||
Base releaseObject = releaseCommitObjectsDict[testObject.applicationId];
|
||||
|
||||
@@ -96,30 +109,39 @@ static class AutomateFunction
|
||||
// if ids are different, find property differences
|
||||
else
|
||||
{
|
||||
modifiedCount++;
|
||||
var diffDictionary = new Dictionary<string, string>();
|
||||
Dictionary<string, object> releaseObjectPropDict = releaseObject.GetMembers();
|
||||
Dictionary<string, object> testObjectPropDict = testObject.GetMembers();
|
||||
Dictionary<string, object?> releaseObjectPropDict =
|
||||
releaseObject.GetMembers();
|
||||
Dictionary<string, object?> testObjectPropDict = testObject.GetMembers();
|
||||
foreach (var entry in testObjectPropDict)
|
||||
{
|
||||
if (releaseObjectPropDict.ContainsKey(entry.Key))
|
||||
{
|
||||
bool changed = false;
|
||||
try
|
||||
{
|
||||
changed = entry.Value != releaseObjectPropDict[entry.Key];
|
||||
}
|
||||
catch { }
|
||||
if (changed)
|
||||
{
|
||||
string diff =
|
||||
$"Property ({entry.Key}) changed from ({releaseObjectPropDict[entry.Key]}) to ({entry.Value})";
|
||||
if (!diffDictionary.ContainsKey(entry.Key))
|
||||
bool changed = !Equals(entry.Value, releaseObjectPropDict[entry.Key]);
|
||||
if (changed)
|
||||
{
|
||||
diffDictionary.Add(entry.Key, diff);
|
||||
object? releaseValue = releaseObjectPropDict[entry.Key];
|
||||
object? testValue = entry.Value;
|
||||
string diff = $"Property ({entry.Key}) changed";
|
||||
if (
|
||||
releaseValue is not null
|
||||
&& testValue is not null
|
||||
&& !releaseValue.GetType().Equals(testValue.GetType())
|
||||
)
|
||||
{
|
||||
diff +=
|
||||
$" from ({releaseObjectPropDict[entry.Key]}) to ({entry.Value})";
|
||||
}
|
||||
|
||||
if (!diffDictionary.ContainsKey(entry.Key))
|
||||
{
|
||||
diffDictionary.Add(entry.Key, diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch { }
|
||||
releaseObjectPropDict.Remove(entry.Key);
|
||||
}
|
||||
else
|
||||
@@ -146,14 +168,17 @@ static class AutomateFunction
|
||||
var sb = new System.Text.StringBuilder();
|
||||
foreach (var entry in diffDictionary)
|
||||
{
|
||||
sb.AppendLine($"{entry.Key}: {entry.Value}");
|
||||
sb.AppendLine($"{entry.Key}: {entry.Value}. ");
|
||||
}
|
||||
|
||||
automationContext.AttachWarningToObjects(
|
||||
MODIFIED,
|
||||
new List<string>() { testObject.id },
|
||||
sb.ToString()
|
||||
modifiedList.Add(
|
||||
new Tuple<string, string, string>(
|
||||
testObject.id,
|
||||
testObject.speckle_type,
|
||||
sb.ToString()
|
||||
)
|
||||
);
|
||||
//automationContext.AttachWarningToObjects( MODIFIED, new List<string>() { testObject.id }, sb.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,35 +186,97 @@ static class AutomateFunction
|
||||
}
|
||||
else
|
||||
{
|
||||
addedCount++;
|
||||
automationContext.AttachInfoToObjects(
|
||||
ADDED,
|
||||
new List<string>() { testObject.id }
|
||||
);
|
||||
// we're skipping objects without an applicationId for now, since we're doing so in the release commit
|
||||
if (!string.IsNullOrEmpty(testObject.applicationId))
|
||||
{
|
||||
//automationContext.AttachInfoToObjects(ADDED, new List<string>() { testObject.id });
|
||||
addedList.Add(
|
||||
new Tuple<string, string>(testObject.id, testObject.speckle_type)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if there are any remaining release commit objects, this indicates missing objects in the test run.
|
||||
// mark run as failed and list missing object details.
|
||||
if (releaseCommitObjectsDict.Keys.Count > 0)
|
||||
var deletedList = new List<Tuple<string, string>>();
|
||||
foreach (var entry in releaseCommitObjectsDict)
|
||||
{
|
||||
deletedList.Add(new Tuple<string, string>(entry.Key, entry.Value.speckle_type));
|
||||
}
|
||||
|
||||
// mark run failed if there are any added, modified, or deleted objects and report
|
||||
if (addedList.Count + deletedList.Count + modifiedList.Count > 0)
|
||||
{
|
||||
automationContext.MarkRunFailed(
|
||||
$"Missing {releaseCommitObjectsDict.Keys.Count} objects compared to the release commit."
|
||||
$"Run failed due to {addedList.Count} ADDED, {modifiedList.Count} MODIFIED, and {deletedList.Count} DELETED objects compared to the release commit ({unchangedCount} objects were unchanged)."
|
||||
);
|
||||
|
||||
foreach (var missingObject in releaseCommitObjectsDict)
|
||||
{
|
||||
Console.WriteLine(
|
||||
$"Missing object info: id( {missingObject.Value.id} ), applicationId( {missingObject.Key} ), type( {missingObject.Value.speckle_type} )"
|
||||
);
|
||||
}
|
||||
addedList.ForEach(
|
||||
o => Console.WriteLine($"ADDED object: id( {o.Item1} ), type( {o.Item2} )")
|
||||
);
|
||||
deletedList.ForEach(
|
||||
o => Console.WriteLine($"DELETED object: id( {o.Item1} ), type( {o.Item2} )")
|
||||
);
|
||||
modifiedList.ForEach(
|
||||
o =>
|
||||
Console.WriteLine(
|
||||
$"MODIFIED object: id( {o.Item1} ), type( {o.Item2} ), changed props:( {o.Item3} )"
|
||||
)
|
||||
);
|
||||
|
||||
automationContext.AttachWarningToObjects(
|
||||
MODIFIED,
|
||||
modifiedList.Select(o => o.Item1).ToList()
|
||||
);
|
||||
}
|
||||
// mark run as succeeded, noting any changed objects and added objects
|
||||
else
|
||||
{
|
||||
automationContext.MarkRunSuccess(
|
||||
$"Run passed with {addedCount} new objects, {modifiedCount} objects, and {unchangedCount} unchanged objects."
|
||||
$"Run passed with {unchangedCount} unchanged objects."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Equals<T>(T a, T b)
|
||||
{
|
||||
switch (a)
|
||||
{
|
||||
case Base o:
|
||||
return b is Base bBase ? o.id == bBase.id : false;
|
||||
case List<object> aList:
|
||||
if (b is List<object> bList && aList.Count == bList.Count)
|
||||
{
|
||||
for (int i = 0; i < aList.Count; i++)
|
||||
{
|
||||
if (!Equals(aList[i], bList[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case Dictionary<string, object> aDictionary:
|
||||
if (
|
||||
b is Dictionary<string, object> bDictionary
|
||||
&& aDictionary.Count == bDictionary.Count
|
||||
)
|
||||
{
|
||||
foreach (var entry in aDictionary)
|
||||
{
|
||||
if (
|
||||
!bDictionary.ContainsKey(entry.Key)
|
||||
|| !Equals(entry.Value, bDictionary[entry.Key])
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return EqualityComparer<T>.Default.Equals(a, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user