Skip to content

Commit

Permalink
Move TentacleScriptDecoratorBuilder and friends into new common proje…
Browse files Browse the repository at this point in the history
…ct (#918)
  • Loading branch information
APErebus committed May 3, 2024
1 parent 906c4d1 commit fc17d76
Show file tree
Hide file tree
Showing 50 changed files with 161 additions and 85 deletions.
2 changes: 1 addition & 1 deletion build/Build.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void RunIntegrationTests(string testFramework, string testRuntime, string filter
// have to shunt them all around the place.
// By doing things this way, we can have a seamless experience between local and remote builds.
var octopusTentacleTestsDirectory = BuildDirectory / "Octopus.Tentacle.Tests.Integration" / testFramework / testRuntime;
var testAssembliesPath = octopusTentacleTestsDirectory.GlobFiles("*.Tests*.dll");
var testAssembliesPath = octopusTentacleTestsDirectory.GlobFiles("*.Tests.Integration.dll");

try
{
Expand Down
23 changes: 18 additions & 5 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public Build()
[Parameter(Name = "signing_certificate_path")] public static string SigningCertificatePath = RootDirectory / "certificates" / "OctopusDevelopment.pfx";
[Secret] [Parameter(Name = "signing_certificate_password")] public static string SigningCertificatePassword = "Password01!";

[Parameter(Name = "RuntimeId")]
public string? SpecificRuntimeId;
[Parameter(Name = "RuntimeId")] public string? SpecificRuntimeId;

readonly AbsolutePath SourceDirectory = RootDirectory / "source";
readonly AbsolutePath ArtifactsDirectory = RootDirectory / "_artifacts";
Expand Down Expand Up @@ -154,7 +153,7 @@ public Build()
using var productWxsFile = UpdateMsiProductVersion();
var runtimeIds = RuntimeIds.Where(x => x.StartsWith("win"));
foreach (var runtimeId in runtimeIds)
{
switch (runtimeId)
Expand Down Expand Up @@ -193,7 +192,13 @@ public Build()
var windowsOnlyBuiltFileSpec = BuildDirectory.GlobDirectories("**/win*/**");
var filesToSign = windowsOnlyBuiltFileSpec
.SelectMany(x => x.GlobFiles("**/Octo*.exe", "**/Octo*.dll", "**/Tentacle.exe", "**/Tentacle.dll", "**/Halibut.dll", "**/Nuget.*.dll", "**/Nevermore.dll", "**/*.ps1"))
.SelectMany(x => x.GlobFiles("**/Octo*.exe", "**/Octo*.dll", "**/Tentacle.exe", "**/Tentacle.dll", "**/Halibut.dll", "**/Nuget.*.dll", "**/*.ps1"))
//We don't need to sign the Test project dlls's as they are only used internally
.Where(x =>
{
var path = x.ToString();
return !path.Contains("Tests") && !path.Contains("CommonTestUtils");
})
.Where(file => !Signing.HasAuthenticodeSignature(file))
.ToArray();
Expand Down Expand Up @@ -320,9 +325,17 @@ void RunBuildFor(string framework, string runtimeId)
.SetProject(SourceDirectory / "Tentacle.sln")
.SetConfiguration(configuration)
.SetFramework(framework)
//.SetSelfContained(true)
.SetRuntime(runtimeId)
.EnableNoRestore()
.SetVersion(FullSemVer));
.SetVersion(FullSemVer)
.SetProcessArgumentConfigurator(args =>
{
// There is a race condition in dotnet publish where building the entire solution
// can cause locking issues depending on multiple CPUs. The solution is to not run builds in parallel
// https://github.com/dotnet/sdk/issues/9585
return args.Add("-maxcpucount:1");
}));
}

// We need to use tar directly, because .NET utilities aren't able to preserve the file permissions
Expand Down
1 change: 1 addition & 0 deletions source/Octopus.Tentacle.Client/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
[assembly: InternalsVisibleTo("Octopus.Tentacle.Tests")]
[assembly: InternalsVisibleTo("Octopus.Tentacle.Client.Tests")]
[assembly: InternalsVisibleTo("Octopus.Tentacle.Tests.Integration")]
[assembly: InternalsVisibleTo("Octopus.Tentacle.Tests.Integration.Common")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Octopus.Tentacle.CommonTestUtils;
using Octopus.Tentacle.Contracts.Observability;
using Octopus.Tentacle.Kubernetes.Tests.Integration.Setup;
using Octopus.Tentacle.Kubernetes.Tests.Integration.Support.Logging;
using Octopus.Tentacle.Tests.Integration.Common.Logging;

namespace Octopus.Tentacle.Kubernetes.Tests.Integration;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Octopus.Tentacle.CommonTestUtils;
using Octopus.Tentacle.Kubernetes.Tests.Integration.Support.Logging;
using Octopus.Tentacle.Tests.Integration.Common.Logging;

namespace Octopus.Tentacle.Kubernetes.Tests.Integration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Octopus.Tentacle.Client\Octopus.Tentacle.Client.csproj" />
<ProjectReference Include="..\Octopus.Tentacle.CommonTestUtils\Octopus.Tentacle.CommonTestUtils.csproj" />
<ProjectReference Include="..\Octopus.Tentacle.Tests.Integration.Common\Octopus.Tentacle.Tests.Integration.Common.csproj" />
<ProjectReference Include="..\Octopus.Tentacle\Octopus.Tentacle.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Octopus.Tentacle.Tests.Integration")]
[assembly: InternalsVisibleTo("Octopus.Tentacle.Kubernetes.Tests.Integration")]
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Threading.Tasks;
using Halibut.ServiceModel;
using Octopus.Tentacle.Contracts.Capabilities;
using Octopus.Tentacle.Contracts.ClientServices;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators
{
public class CapabilitiesServiceV2DecoratorBuilder
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using Octopus.Tentacle.Client;
using Octopus.Tentacle.Contracts.ClientServices;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators
{
public class CombiningTentacleServiceDecoratorFactory : ITentacleServiceDecoratorFactory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using System.Threading.Tasks;
using Halibut;
using Halibut.ServiceModel;
using Octopus.Tentacle.Contracts;
using Octopus.Tentacle.Contracts.ClientServices;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators
{
public class FileTransferServiceDecoratorBuilder
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Reflection;
using System.Threading.Tasks;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators.Proxies
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators.Proxies
{
public delegate Task PreMethodInvocationHook<in TService, in TRequest>(TService service, TRequest request);
public delegate Task PostMethodInvocationHook<in TService, in TResponse>(TService service, TResponse response);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using Octopus.Tentacle.Tests.Integration.Common.Logging;
using Serilog;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators.Proxies
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators.Proxies
{
public class MethodLoggingProxyDecorator : ServiceProxy
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Reflection;
using System.Threading.Tasks;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators.Proxies
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators.Proxies
{
public class MethodUsageProxyDecorator : ServiceProxy
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Reflection;
using System.Threading;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators.Proxies
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators.Proxies
{
public class MethodUsages : IRecordedMethodUsages
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators.Proxies
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators.Proxies
{
public static class RecordMethodUsagesExtensionMethods
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators.Proxies
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators.Proxies
{
public abstract class ServiceProxy : DispatchProxyAsync
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using System.Threading.Tasks;
using Halibut.ServiceModel;
using Halibut.Transport.Protocol;
using Octopus.Tentacle.Contracts;
using Octopus.Tentacle.Contracts.ClientServices;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators
{
public class ScriptServiceDecoratorBuilder
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Threading.Tasks;
using Halibut.ServiceModel;
using Octopus.Tentacle.Contracts.ClientServices;
using Octopus.Tentacle.Contracts.ScriptServiceV2;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators
{
public class ScriptServiceV2DecoratorBuilder
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Threading.Tasks;
using Halibut.ServiceModel;
using Octopus.Tentacle.Contracts.ClientServices;
using Octopus.Tentacle.Contracts.KubernetesScriptServiceV1Alpha;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators
{
public class KubernetesScriptServiceV1AlphaDecoratorBuilder
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using Octopus.Tentacle.Client;
using Octopus.Tentacle.Contracts.ClientServices;
using Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators.Proxies;
using Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators.Proxies;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators
{
public delegate T Decorator<T>(T service);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators.Proxies;

namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators
{
public static class TentacleServiceDecoratorBuilderExtensions
{
public static TentacleServiceDecoratorBuilder RecordMethodUsages<TService>(this TentacleServiceDecoratorBuilder builder, out IRecordedMethodUsages recordedUsages)
where TService : class
{
var localMethodUsages = new MethodUsages();
recordedUsages = localMethodUsages;

return builder.RegisterProxyDecorator<TService>(service => MethodUsageProxyDecorator.Create(service, localMethodUsages));
}

public static TentacleServiceDecoratorBuilder HookServiceMethod<TService>(this TentacleServiceDecoratorBuilder builder, string methodName, PreMethodInvocationHook<TService, object> preInvocation) where TService : class
//if we aren't hooking the post invocation, we don't care about the response type
=> HookServiceMethod<TService, object, object>(builder, methodName, preInvocation, null);

public static TentacleServiceDecoratorBuilder HookServiceMethod<TService, TRequest>(this TentacleServiceDecoratorBuilder builder, string methodName, PreMethodInvocationHook<TService, TRequest> preInvocation) where TService : class
//if we aren't hooking the post invocation, we don't care about the response type
=> HookServiceMethod<TService, TRequest, object>(builder, methodName, preInvocation, null);

public static TentacleServiceDecoratorBuilder HookServiceMethod<TService, TRequest, TResponse>(this TentacleServiceDecoratorBuilder builder, string methodName, PreMethodInvocationHook<TService, TRequest>? preInvocation, PostMethodInvocationHook<TService, TResponse>? postInvocation) where TService : class
=> builder.RegisterProxyDecorator<TService>(service => MethodInvocationHookProxyDecorator<TService, TRequest, TResponse>.Create(service, methodName, preInvocation, postInvocation));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Octopus.Tentacle.Contracts.ClientServices;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators
{
public class UniversalScriptServiceDecorator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators
namespace Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators
{
public class UniversalScriptServiceDecoratorBuilder
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;
using System.Collections.Concurrent;
using System.Security.Cryptography;
using System.Text;
using NUnit.Framework;
using Octopus.Tentacle.CommonTestUtils;
using Octopus.Tentacle.Util;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting.Display;

namespace Octopus.Tentacle.Kubernetes.Tests.Integration.Support.Logging
namespace Octopus.Tentacle.Tests.Integration.Common.Logging
{
public class SerilogLoggerBuilder
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Halibut.Diagnostics;
using System;
using Halibut.Diagnostics;
using Halibut.Diagnostics.LogWriters;
using Halibut.Logging;
using Serilog.Events;
using LogEvent = Halibut.Diagnostics.LogEvent;

namespace Octopus.Tentacle.Kubernetes.Tests.Integration.Support.Logging;
namespace Octopus.Tentacle.Tests.Integration.Common.Logging;

public class TestContextConnectionLog : ILog, ILogWriter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Halibut.Diagnostics.LogCreators;
using System;
using Halibut.Diagnostics;
using Halibut.Diagnostics.LogCreators;
using Halibut.Logging;

namespace Octopus.Tentacle.Kubernetes.Tests.Integration.Support.Logging;
namespace Octopus.Tentacle.Tests.Integration.Common.Logging;

public class TestContextLogCreator : ICreateNewILog
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Collections.Concurrent;
using System;
using System.Collections.Concurrent;
using Halibut;
using Halibut.Diagnostics;
using Halibut.Logging;

namespace Octopus.Tentacle.Kubernetes.Tests.Integration.Support.Logging;
namespace Octopus.Tentacle.Tests.Integration.Common.Logging;

public class TestContextLogFactory : ILogFactory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Text;
using System;
using System.Text;
using System.Threading.Channels;

namespace Octopus.Tentacle.Kubernetes.Tests.Integration.Support.Logging;
namespace Octopus.Tentacle.Tests.Integration.Common.Logging;

public class TraceLogFileLogger : IAsyncDisposable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>Octopus.Tentacle.Tests.Integration.Common</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputPath>bin</OutputPath>
<PublishDir>../../_build/$(AssemblyName)/$(TargetFramework)/$(RuntimeIdentifier)</PublishDir>
<IsPackable>false</IsPackable>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64;osx-arm64;linux-arm64;linux-arm;linux-musl-x64</RuntimeIdentifiers>
</PropertyGroup>

<ItemGroup>
<Folder Include="Builders\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Octopus.Tentacle.Client\Octopus.Tentacle.Client.csproj" />
<ProjectReference Include="..\Octopus.Tentacle.CommonTestUtils\Octopus.Tentacle.CommonTestUtils.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit fc17d76

Please sign in to comment.