Skip to content

Commit

Permalink
Update dui3/alpha with changes from dev through temp branch (#3444)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanRynne authored May 29, 2024
2 parents 59a9f23 + 0e55bfc commit 7683db1
Show file tree
Hide file tree
Showing 66 changed files with 805 additions and 647 deletions.
30 changes: 16 additions & 14 deletions .circleci/scripts/config-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ workflows:
tags:
only: /^(nuget-core|nugets)\/([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\w{1,10})?$/
post-steps:
- packandpublish
- publish-nugets
context: nuget

commands:
Expand All @@ -52,20 +52,8 @@ commands:
echo 'export VERSION=$(echo $VER.$WORKFLOW_NUM)' >> "$BASH_ENV"
environment:
WORKFLOW_NUM: << pipeline.number >>

packandpublish:
publish-nugets:
steps:
- run:
name: Build nuget packages
command: |
TAG=$(if [ "${CIRCLE_TAG}" ]; then echo $CIRCLE_TAG; else echo "2.0.999"; fi;)
NOPREFIX=$(echo $TAG | sed -e 's/^[a-zA-Z]*\///')
SEMVER=$(echo "$NOPREFIX" | sed -e 's/\/[a-zA-Z-]*//')
VER=$(echo "$SEMVER" | sed -e 's/-.*//')
VERSION=$(echo $VER.$WORKFLOW_NUM)
$HOME/.dotnet/dotnet pack All.sln -p:Version=$SEMVER -p:FileVersion=$VERSION -c Release -p:IsDesktopBuild=false
environment:
WORKFLOW_NUM: << pipeline.number >>
- run:
name: Push nuget packages
command: $HOME/.dotnet/dotnet nuget push "**/*.nupkg" -s https://api.nuget.org/v3/index.json -k $NUGET_APIKEY -n --skip-duplicate
Expand Down Expand Up @@ -115,6 +103,7 @@ jobs: # Each project will have individual jobs for each specific task it has to
name: Install dotnet
command: |
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel sts
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --version 8.0.204
$HOME/.dotnet/dotnet --version
- run:
name: Enforce formatting
Expand All @@ -132,6 +121,17 @@ jobs: # Each project will have individual jobs for each specific task it has to
$HOME/.dotnet/dotnet build SDK.slnf -c Release -p:IsDesktopBuild=false -p:Version=$SEMVER -p:FileVersion=$VERSION
environment:
WORKFLOW_NUM: << pipeline.number >>
- run:
name: Build nuget packages
command: |
TAG=$(if [ "${CIRCLE_TAG}" ]; then echo $CIRCLE_TAG; else echo "2.0.999"; fi;)
NOPREFIX=$(echo $TAG | sed -e 's/^[a-zA-Z]*\///')
SEMVER=$(echo "$NOPREFIX" | sed -e 's/\/[a-zA-Z-]*//')
VER=$(echo "$SEMVER" | sed -e 's/-.*//')
VERSION=$(echo $VER.$WORKFLOW_NUM)
$HOME/.dotnet/dotnet pack All.sln -p:Version=$SEMVER -p:FileVersion=$VERSION -c Release -p:IsDesktopBuild=false
environment:
WORKFLOW_NUM: << pipeline.number >>
- run-tests:
title: Core Unit Tests
project: Core/Tests/Speckle.Core.Tests.Unit/Speckle.Core.Tests.Unit.csproj
Expand All @@ -151,6 +151,7 @@ jobs: # Each project will have individual jobs for each specific task it has to
name: Install dotnet
command: |
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel sts
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --version 8.0.204
$HOME/.dotnet/dotnet --version
- run:
name: Startup the Speckle Server
Expand Down Expand Up @@ -331,6 +332,7 @@ jobs: # Each project will have individual jobs for each specific task it has to
name: Install dotnet
command: |
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel sts
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --version 8.0.204
$HOME/.dotnet/dotnet --version
$HOME/.dotnet/dotnet --list-runtimes
Expand Down
183 changes: 143 additions & 40 deletions All.sln

Large diffs are not rendered by default.

139 changes: 80 additions & 59 deletions Automate/Speckle.Automate.Sdk/AutomationContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics;
using GraphQL;
using Speckle.Automate.Sdk.Schema;
using Speckle.Automate.Sdk.Schema.Triggers;
using Speckle.Core.Api;
using Speckle.Core.Credentials;
using Speckle.Core.Logging;
Expand Down Expand Up @@ -75,9 +76,14 @@ public static async Task<AutomationContext> Initialize(string automationRunData,
/// <exception cref="SpeckleException">Throws if commit object is null.</exception>
public async Task<Base> ReceiveVersion()
{
Commit? commit = await SpeckleClient
.CommitGet(AutomationRunData.ProjectId, AutomationRunData.VersionId)
.ConfigureAwait(false);
// TODO: this is a quick hack to keep implementation consistency. Move to proper receive many versions
if (AutomationRunData.Triggers.First() is not VersionCreationTrigger trigger)
{
throw new SpeckleException("Processed automation run data without any triggers");
}
var versionId = trigger.Payload.VersionId;

Commit? commit = await SpeckleClient.CommitGet(AutomationRunData.ProjectId, versionId).ConfigureAwait(false);
Base? commitRootObject = await Operations
.Receive(commit.referencedObject, _serverTransport, _memoryTransport)
.ConfigureAwait(false);
Expand All @@ -86,9 +92,7 @@ public async Task<Base> ReceiveVersion()
throw new SpeckleException("Commit root object was null");
}

Console.WriteLine(
$"It took {Elapsed.TotalSeconds} seconds to receive the speckle version {AutomationRunData.VersionId}"
);
Console.WriteLine($"It took {Elapsed.TotalSeconds} seconds to receive the speckle version {versionId}");
return commitRootObject;
}

Expand All @@ -103,26 +107,54 @@ public async Task<Base> ReceiveVersion()
/// The reason is to prevent circular run loop in automation. </exception>
public async Task<string> CreateNewVersionInProject(Base rootObject, string modelName, string versionMessage = "")
{
if (modelName == AutomationRunData.BranchName)
{
throw new ArgumentException(
$"The target model: {modelName} cannot match the model that triggered this automation: {AutomationRunData.ModelId}/{AutomationRunData.BranchName}",
nameof(modelName)
);
}

string rootObjectId = await Operations
.Send(rootObject, new List<ITransport> { _serverTransport, _memoryTransport })
.ConfigureAwait(false);

Branch branch = await SpeckleClient.BranchGet(AutomationRunData.ProjectId, modelName).ConfigureAwait(false);

if (branch is null)
{
// Create the branch with the specified name
await SpeckleClient
.BranchCreate(new BranchCreateInput() { streamId = AutomationRunData.ProjectId, name = modelName })
.ConfigureAwait(false);
}
else
{
// Confirm target branch is not the same as source branch
if (branch.id == null)
{
throw new SpeckleException("Cannot use the branch without its id");
}

foreach (var trigger in AutomationRunData.Triggers)
{
switch (trigger)
{
case VersionCreationTrigger versionCreationTrigger:
{
if (versionCreationTrigger.Payload.ModelId == branch.id)
{
throw new SpeckleException(
$$"""
The target model: {{modelName}} cannot match the model
that triggered this automation:
{{versionCreationTrigger.Payload.ModelId}}
"""
);
}
continue;
}
default:
{
// TODO: How should we handle unknown trigger types?
continue;
}
}
}
}

string rootObjectId = await Operations
.Send(rootObject, new List<ITransport> { _serverTransport, _memoryTransport })
.ConfigureAwait(false);

string versionId = await SpeckleClient
.CommitCreate(
new CommitCreateInput
Expand Down Expand Up @@ -154,7 +186,21 @@ public void SetContextView(List<string>? resourceIds = null, bool includeSourceM
List<string> linkResources = new();
if (includeSourceModelVersion)
{
linkResources.Add($@"{AutomationRunData.ModelId}@{AutomationRunData.VersionId}");
foreach (var trigger in AutomationRunData.Triggers)
{
switch (trigger)
{
case VersionCreationTrigger versionCreationTrigger:
{
linkResources.Add($@"{versionCreationTrigger.Payload.ModelId}@{versionCreationTrigger.Payload.VersionId}");
break;
}
default:
{
throw new SpeckleException($"Could not link resource specified by {trigger.TriggerType} trigger");
}
}
}
}

if (resourceIds is not null)
Expand Down Expand Up @@ -189,54 +235,29 @@ public async Task ReportRunStatus()
{
Query =
@"
mutation ReportFunctionRunStatus(
$automationId: String!,
$automationRevisionId: String!,
$automationRunId: String!,
$versionId: String!,
$functionId: String!,
$functionName: String!,
$functionLogo: String,
$runStatus: AutomationRunStatus!
$elapsed: Float!
$resultVersionIds: [String!]!
mutation AutomateFunctionRunStatusReport(
$functionRunId: String!
$status: AutomateRunStatus!
$statusMessage: String
$objectResults: JSONObject
$results: JSONObject
$contextView: String
){
automationMutations {
functionRunStatusReport(input: {
automationId: $automationId
automationRevisionId: $automationRevisionId
automationRunId: $automationRunId
versionId: $versionId
functionRuns: [{
functionId: $functionId,
functionName: $functionName,
functionLogo: $functionLogo,
status: $runStatus,
elapsed: $elapsed,
resultVersionIds: $resultVersionIds,
statusMessage: $statusMessage,
results: $objectResults,
}]
automateFunctionRunStatusReport(input: {
functionRunId: $functionRunId
status: $status
statusMessage: $statusMessage
contextView: $contextView
results: $results
})
}
}
",
Variables = new
{
automationId = AutomationRunData.AutomationId,
automationRevisionId = AutomationRunData.AutomationRevisionId,
automationRunId = AutomationRunData.AutomationRunId,
versionId = AutomationRunData.VersionId,
functionId = AutomationRunData.FunctionId,
functionName = AutomationRunData.FunctionName,
functionLogo = AutomationRunData.FunctionLogo,
runStatus = RunStatus,
functionRunId = AutomationRunData.FunctionRunId,
status = RunStatus,
statusMessage = AutomationResult.StatusMessage,
elapsed = Elapsed.TotalSeconds,
resultVersionIds = AutomationResult.ResultVersions,
objectResults,
contextView = ContextView,
results = objectResults,
}
};
await SpeckleClient.ExecuteGraphQLRequest<Dictionary<string, object>>(request).ConfigureAwait(false);
Expand Down
14 changes: 5 additions & 9 deletions Automate/Speckle.Automate.Sdk/Schema/AutomationRunData.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
using Speckle.Automate.Sdk.Schema.Triggers;

namespace Speckle.Automate.Sdk.Schema;

///<summary>
///Values of the project, model and automation that triggered this function run.
/// Values of the project, model and automation that triggered this function run.
///</summary>
public struct AutomationRunData
{
public string ProjectId { get; set; }
public string ModelId { get; set; }
public string BranchName { get; set; }
public string VersionId { get; set; }
public string SpeckleServerUrl { get; set; }
public string AutomationId { get; set; }
public string AutomationRevisionId { get; set; }
public string AutomationRunId { get; set; }
public string FunctionId { get; set; }
public string FunctionRelease { get; set; }
public string FunctionName { get; set; }
public string? FunctionLogo { get; set; }
public string FunctionRunId { get; set; }
public List<AutomationRunTriggerBase> Triggers { get; set; }
}
2 changes: 1 addition & 1 deletion Automate/Speckle.Automate.Sdk/Schema/ObjectResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace Speckle.Automate.Sdk.Schema;

public struct ObjectResults
{
public readonly string Version => "1.0.0";
public readonly int Version => 1;
public ObjectResultValues Values { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Speckle.Automate.Sdk.Schema.Triggers;

public class AutomationRunTriggerBase
{
public string TriggerType { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Speckle.Automate.Sdk.Schema.Triggers;

/// <summary>
/// Represents a single version creation trigger for the automation run.
/// </summary>
public class VersionCreationTrigger : AutomationRunTriggerBase
{
public VersionCreationTriggerPayload Payload { get; set; }

public VersionCreationTrigger(string modelId, string versionId)
{
TriggerType = "versionCreation";
Payload = new VersionCreationTriggerPayload() { ModelId = modelId, VersionId = versionId };
}
}

/// <summary>
/// Represents the version creation trigger payload.
/// </summary>
public class VersionCreationTriggerPayload
{
public string ModelId { get; set; }
public string VersionId { get; set; }
}
Loading

0 comments on commit 7683db1

Please sign in to comment.