4 Commits

Author SHA1 Message Date
Claire Kuang f2cb5c30be Update AutomateFunction.cs
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2024-01-31 13:54:40 +00:00
Claire Kuang 4ec42cde84 server and remote transport fixes
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2024-01-31 12:59:57 +00:00
Claire Kuang 86e4759531 updates to use 2.18 prerelease nugets
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2024-01-31 11:54:23 +00:00
Claire Kuang e3806f3fb4 marked tolerance as required input
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2024-01-31 11:29:00 +00:00
3 changed files with 44 additions and 25 deletions
@@ -2,6 +2,7 @@ using Objects;
using Speckle.Automate.Sdk; using Speckle.Automate.Sdk;
using Speckle.Automate.Sdk.Schema; using Speckle.Automate.Sdk.Schema;
using Speckle.Core.Api; using Speckle.Core.Api;
using Speckle.Core.Credentials;
using Speckle.Core.Models; using Speckle.Core.Models;
using Speckle.Core.Models.Extensions; using Speckle.Core.Models.Extensions;
using Speckle.Core.Transports; using Speckle.Core.Transports;
@@ -37,6 +38,8 @@ static class AutomateFunction
throw new Exception("Release branch has no commits"); throw new Exception("Release branch has no commits");
} }
var tolerance = functionInputs.Tolerance;
Console.WriteLine($"Comparing {testBranchName} against {releaseBranchName}"); Console.WriteLine($"Comparing {testBranchName} against {releaseBranchName}");
// get the test and release commits // get the test and release commits
@@ -44,19 +47,25 @@ static class AutomateFunction
Base? testingCommitObject = await automationContext.ReceiveVersion(); Base? testingCommitObject = await automationContext.ReceiveVersion();
Console.WriteLine("Received test version: " + testingCommitObject); Console.WriteLine("Received test version: " + testingCommitObject);
Console.WriteLine("Receiving release version"); Console.WriteLine("Receiving release version");
using ServerTransport transport = ServerTransport serverTransport = new ServerTransport(
new( automationContext.SpeckleClient.Account,
automationContext.SpeckleClient.Account, automationContext.AutomationRunData.ProjectId
automationContext.AutomationRunData.ProjectId );
);
Base? releaseCommitObject = await Operations 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); .ConfigureAwait(continueOnCapturedContext: false);
if (releaseCommitObject == null) if (releaseCommitObject == null)
{ {
throw new Exception("Commit root object was null"); throw new Exception("Commit root object was null");
} }
Console.WriteLine("Received release version: " + releaseCommitObject); Console.WriteLine("Received release version: " + releaseCommitObject);
// flatten both commits // flatten both commits
@@ -65,7 +74,10 @@ static class AutomateFunction
var releaseCommitObjectsDict = new Dictionary<string, Base>(); var releaseCommitObjectsDict = new Dictionary<string, Base>();
foreach (var releaseObject in releaseCommitObjects) foreach (var releaseObject in releaseCommitObjects)
{ {
if (!releaseCommitObjectsDict.ContainsKey(releaseObject.applicationId)) if (
releaseObject.applicationId != null
&& !releaseCommitObjectsDict.ContainsKey(releaseObject.applicationId)
)
{ {
releaseCommitObjectsDict.Add(releaseObject.applicationId, releaseObject); releaseCommitObjectsDict.Add(releaseObject.applicationId, releaseObject);
} }
@@ -82,7 +94,10 @@ static class AutomateFunction
int unchangedCount = 0; int unchangedCount = 0;
foreach (Base testObject in testCommitObjects) foreach (Base testObject in testCommitObjects)
{ {
if (releaseCommitObjectsDict.ContainsKey(testObject.applicationId)) if (
testObject.applicationId != null
&& releaseCommitObjectsDict.ContainsKey(testObject.applicationId)
)
{ {
Base releaseObject = releaseCommitObjectsDict[testObject.applicationId]; Base releaseObject = releaseCommitObjectsDict[testObject.applicationId];
@@ -96,28 +111,27 @@ static class AutomateFunction
{ {
modifiedCount++; modifiedCount++;
var diffDictionary = new Dictionary<string, string>(); var diffDictionary = new Dictionary<string, string>();
Dictionary<string, object> releaseObjectPropDict = releaseObject.GetMembers(); Dictionary<string, object?> releaseObjectPropDict =
Dictionary<string, object> testObjectPropDict = testObject.GetMembers(); releaseObject.GetMembers();
Dictionary<string, object?> testObjectPropDict = testObject.GetMembers();
foreach (var entry in testObjectPropDict) foreach (var entry in testObjectPropDict)
{ {
if (releaseObjectPropDict.ContainsKey(entry.Key)) if (releaseObjectPropDict.ContainsKey(entry.Key))
{ {
bool changed = false;
try try
{ {
changed = entry.Value != releaseObjectPropDict[entry.Key]; bool changed = !Equals(entry.Value, releaseObjectPropDict[entry.Key]);
} if (changed)
catch { }
if (changed)
{
string diff =
$"Property ({entry.Key}) changed from ({releaseObjectPropDict[entry.Key]}) to ({entry.Value})";
if (!diffDictionary.ContainsKey(entry.Key))
{ {
diffDictionary.Add(entry.Key, diff); string diff =
$"Property ({entry.Key}) changed from ({releaseObjectPropDict[entry.Key]}) to ({entry.Value})";
if (!diffDictionary.ContainsKey(entry.Key))
{
diffDictionary.Add(entry.Key, diff);
}
} }
} }
catch { }
releaseObjectPropDict.Remove(entry.Key); releaseObjectPropDict.Remove(entry.Key);
} }
else else
@@ -190,4 +204,9 @@ static class AutomateFunction
); );
} }
} }
public static bool Equals<T>(T a, T b)
{
return EqualityComparer<T>.Default.Equals(a, b);
}
} }
@@ -7,7 +7,7 @@ using System.ComponentModel.DataAnnotations;
/// are valid and match the required schema. /// are valid and match the required schema.
struct FunctionInputs struct FunctionInputs
{ {
//[Required] [Required]
public double Tolerance; public double Tolerance;
//public string Exclusions; //public string Exclusions;
@@ -8,7 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Speckle.Automate.Sdk" Version="2.17.0-automate3" /> <PackageReference Include="Speckle.Automate.Sdk" Version="2.18.0-fileInput" />
<PackageReference Include="Speckle.Objects" Version="2.17.0-automate3" /> <PackageReference Include="Speckle.Objects" Version="2.18.0-fileInput" />
</ItemGroup> </ItemGroup>
</Project> </Project>