7 Commits

Author SHA1 Message Date
Jedd Morgan 49973ac7f4 Bump automate sdk 2025-06-04 11:16:45 +01:00
Jedd Morgan b697e3c964 bump automate compose 2025-05-30 15:32:57 +01:00
Jedd Morgan 449c4f2f5e Nowarn NETSDK1206 2025-05-30 13:42:22 +01:00
Jedd Morgan 0b30eb700a Use nuget 2025-05-30 13:39:39 +01:00
Jedd Morgan e5b5244bc8 Updated CI 2025-05-30 13:22:53 +01:00
Jedd Morgan 8b73f0c37e comments 2025-05-28 23:39:09 +01:00
Jedd Morgan 062e08b1b2 First pass 2025-05-28 23:37:47 +01:00
11 changed files with 110 additions and 52 deletions
@@ -3,7 +3,7 @@ on:
workflow_dispatch:
push:
tags:
- '*'
- "*"
jobs:
publish-automate-function-version: # make sure the action works on a clean machine without building
@@ -11,11 +11,11 @@ jobs:
FUNCTION_SCHEMA_FILE_NAME: functionSchema.json
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.6
- uses: actions/checkout@v4
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4.0.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.x
dotnet-version: 8.x.x
- name: Restore dependencies
run: dotnet restore
- name: Extract functionInputSchema
@@ -26,7 +26,7 @@ jobs:
dotnet run generate-schema ${HOME}/functionSchema.json
cat ${HOME}/functionSchema.json
- name: Speckle Automate Function - Build and Publish
uses: specklesystems/speckle-automate-github-composite-action@0.8.1
uses: specklesystems/speckle-automate-github-composite-action@0.9.0
with:
speckle_function_command: "dotnet SpeckleAutomateDotnetExample.dll"
speckle_automate_url: ${{ env.SPECKLE_AUTOMATE_URL || vars.SPECKLE_AUTOMATE_URL || 'https://automate.speckle.dev' }}
+19
View File
@@ -0,0 +1,19 @@
name: "Test Building"
on:
pull_request:
jobs:
build-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x.x
- name: Restore dependencies
run: dotnet restore
- name: Build
working-directory: "SpeckleAutomateDotnetExample"
run: |
dotnet build -warnaserror
+4 -3
View File
@@ -33,7 +33,7 @@ This repository contains an example function that is compatible with Speckle Aut
## Getting started
This is essentially a template function, designed to serve as a starting point for creating your own function. The function targets dotnet 7.0 and uses the Speckle.Automate.SDK NuGet package, as well as the Objects Kit.
This is essentially a template function, designed to serve as a starting point for creating your own function. The function targets dotnet 8.0 and uses the Speckle.Automate.SDK NuGet package.
At its core every Speckle Automate function is a CLI application with a specific, standardized set of available commands and arguments ([see below](#anatomy-of-a-function)). Each automate function is then built into a Docker image and published onto Speckle Automate.
@@ -62,13 +62,14 @@ These arguments are automatically provided by the automate platform every time a
### Function Boilerplate (`Program.cs`)
In this file, you'll find a call to `AutomationRunner.Main<TInput>`, which serves as your function's SDK entry point. This method handles argument parsing and accepts:
This Program.cs file is the entry point to your CLI app.
It contains boilerplate to setup the Automate SDK services, Resolve your function, and run it via the call to `IAutomationRunner.Main<TInput>`. This method handles argument parsing and accepts:
- `args` -> the arguments provided by Speckle Automate, and
- `Func<AutomationContext, TInput>` -> Your custom function that gets executed when the automation is triggered.
> [!NOTE]
> If your function requires no inputs, there is also `AutomationRunner.Main` (non-generic) which takes in a `Func<AutomationContext>` instead.
> If your function requires no inputs, there is also `IAutomationRunner.Main` (non-generic) which takes in a `Func<AutomationContext>` instead.
This sets up a CLI application with two commands:
@@ -1,16 +1,14 @@
using Objects;
using Speckle.Automate.Sdk;
using Speckle.Core.Models.Extensions;
using Speckle.Sdk.Models.Extensions;
public static class AutomateFunction
public class AutomateFunction
{
public static async Task Run(
AutomationContext automationContext,
public async Task Run(
IAutomationContext automationContext,
FunctionInputs functionInputs
)
{
Console.WriteLine("Starting execution");
_ = typeof(ObjectsKit).Assembly; // INFO: Force objects kit to initialize
Console.WriteLine("Receiving version");
var commitObject = await automationContext.ReceiveVersion();
@@ -23,8 +21,11 @@ public static class AutomateFunction
Console.WriteLine($"Counted {count} objects");
if (count < functionInputs.SpeckleTypeTargetCount) {
automationContext.MarkRunFailed($"Counted {count} objects where {functionInputs.SpeckleTypeTargetCount} were expected");
if (count < functionInputs.SpeckleTypeTargetCount)
{
automationContext.MarkRunFailed(
$"Counted {count} objects where {functionInputs.SpeckleTypeTargetCount} were expected"
);
return;
}
@@ -1,19 +1,19 @@
using Speckle.Automate.Sdk.DataAnnotations;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Speckle.Automate.Sdk.DataAnnotations;
/// <summary>
/// This class describes the user specified variables that the function wants to work with.
/// </summary>
/// This class is used to generate a JSON Schema to ensure that the user provided values
/// are valid and match the required schema.
public struct FunctionInputs
public readonly struct FunctionInputs
{
/// <summary>
/// The object type to count instances of in the given model version.
/// </summary>
[Required]
public string SpeckleTypeToCount;
public string SpeckleTypeToCount { get; init; }
/// <summary>
/// The total number of the specified type expected.
@@ -21,12 +21,12 @@ public struct FunctionInputs
[DefaultValue(10)]
[Range(1, 100)]
[Required]
public int SpeckleTypeTargetCount;
public int SpeckleTypeTargetCount { get; init; }
/// <summary>
/// An arbitrary example of using a secret input value.
/// </summary>
[Required]
[Secret]
public string ExternalServiceKey;
public string ExternalServiceKey { get; init; }
}
+12 -4
View File
@@ -1,6 +1,14 @@
using Speckle.Automate.Sdk;
using Microsoft.Extensions.DependencyInjection;
using Speckle.Automate.Sdk;
//Boilerplate to setup Automate SDK
var serviceCollection = new ServiceCollection();
serviceCollection.AddAutomateSdk();
serviceCollection.AddSingleton<AutomateFunction>();
await using var container = serviceCollection.BuildServiceProvider();
var runner = container.GetRequiredService<IAutomationRunner>();
var function = container.GetRequiredService<AutomateFunction>();
// WARNING do not delete this call, this is the actual execution of your function
return await AutomationRunner
.Main<FunctionInputs>(args, AutomateFunction.Run)
.ConfigureAwait(false);
return await runner.Main<FunctionInputs>(args, function.Run);
@@ -2,14 +2,15 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);NETSDK1206</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Speckle.Automate.Sdk" Version="2.21.0" />
<PackageReference Include="Speckle.Objects" Version="2.21.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Speckle.Automate.Sdk" Version="3.4.0-alpha.15" />
</ItemGroup>
</Project>
+24 -16
View File
@@ -1,27 +1,35 @@
namespace TestAutomateFunction;
using Microsoft.Extensions.DependencyInjection;
using Speckle.Automate.Sdk;
using Speckle.Automate.Sdk.Test;
using Speckle.Core.Api;
using Speckle.Core.Api.GraphQL.Models;
using Speckle.Core.Credentials;
using Speckle.Sdk.Api;
using Speckle.Sdk.Api.GraphQL.Models;
using Speckle.Sdk.Credentials;
namespace TestAutomateFunction;
[TestFixture]
public sealed class AutomationContextTest : IDisposable
{
private Client client;
private Account account;
private IClient _client;
private Account _account;
private IAutomationRunner _runner;
private AutomateFunction _function;
[OneTimeSetUp]
public void Setup()
{
account = new Account
var serviceProvider = ServiceRegistration.GetServiceProvider();
_account = new Account
{
token = TestAutomateEnvironment.GetSpeckleToken(),
serverInfo = new ServerInfo { url = TestAutomateEnvironment.GetSpeckleServerUrl().ToString() }
serverInfo = new ServerInfo
{
url = TestAutomateEnvironment.GetSpeckleServerUrl().ToString()
}
};
client = new Client(account);
_client = serviceProvider.GetRequiredService<IClientFactory>().Create(_account);
_runner = serviceProvider.GetRequiredService<IAutomationRunner>();
_function = serviceProvider.GetRequiredService<AutomateFunction>();
}
[Test]
@@ -33,11 +41,11 @@ public sealed class AutomationContextTest : IDisposable
SpeckleTypeTargetCount = 1
};
var automationRunData = await TestAutomateUtils.CreateTestRun(client);
var automationContext = await AutomationRunner.RunFunction(
AutomateFunction.Run,
var automationRunData = await TestAutomateUtils.CreateTestRun(_client);
var automationContext = await _runner.RunFunction(
_function.Run,
automationRunData,
account.token,
_account.token,
inputs
);
@@ -46,7 +54,7 @@ public sealed class AutomationContextTest : IDisposable
public void Dispose()
{
client.Dispose();
_client.Dispose();
TestAutomateEnvironment.Clear();
}
}
@@ -0,0 +1,15 @@
using Microsoft.Extensions.DependencyInjection;
using Speckle.Automate.Sdk;
namespace TestAutomateFunction;
public static class ServiceRegistration
{
public static IServiceProvider GetServiceProvider()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddAutomateSdk();
serviceCollection.AddSingleton<AutomateFunction>();
return serviceCollection.BuildServiceProvider();
}
}
@@ -1,19 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2"/>
<PackageReference Include="NUnit" Version="3.13.3"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/>
<PackageReference Include="NUnit.Analyzers" Version="3.3.0"/>
<PackageReference Include="coverlet.collector" Version="3.1.2"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0"/>
<PackageReference Include="NUnit.Analyzers" Version="4.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
+1 -1
View File
@@ -1 +1 @@
global using NUnit.Framework;
global using NUnit.Framework;