Skip to content

Commit 1366b57

Browse files
committed
add packaging of runtime
1 parent 694d028 commit 1366b57

File tree

2 files changed

+177
-1
lines changed

2 files changed

+177
-1
lines changed

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Amazon.Lambda.TestTool.csproj

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<PackageId>Amazon.Lambda.TestTool</PackageId>
1515
<ToolCommandName>dotnet-lambda-test-tool</ToolCommandName>
1616
<Version>0.0.1-beta.1</Version>
17+
<NoWarn>NU5100</NoWarn>
1718
</PropertyGroup>
1819

1920
<ItemGroup>
@@ -29,8 +30,31 @@
2930
<PackageReference Include="BlazorMonaco" Version="3.2.0" />
3031
</ItemGroup>
3132

33+
<Target Name="GetRuntimeSupportTargetFrameworks">
34+
<Exec Command="dotnet msbuild ..\..\..\..\Libraries\src\Amazon.Lambda.RuntimeSupport\Amazon.Lambda.RuntimeSupport.csproj --getProperty:TargetFrameworks" ConsoleToMSBuild="true">
35+
<Output TaskParameter="ConsoleOutput" PropertyName="RuntimeSupportTargetFrameworks" />
36+
</Exec>
37+
</Target>
38+
39+
<Target Name="CopyRuntimeSupportFiles" DependsOnTargets="GetRuntimeSupportTargetFrameworks" BeforeTargets="_GetPackageFiles">
40+
<ItemGroup>
41+
<TempFrameworks Include="$(RuntimeSupportTargetFrameworks.Split(';'))" />
42+
43+
<TargetFrameworks Include="@(TempFrameworks)"
44+
Condition="'%(Identity)' != 'netstandard2.0'" />
45+
</ItemGroup>
46+
47+
<Exec Command="dotnet publish &quot;$(MSBuildThisFileDirectory)..\..\..\..\Libraries\src\Amazon.Lambda.RuntimeSupport\Amazon.Lambda.RuntimeSupport.csproj&quot; -c $(Configuration) -f %(TargetFrameworks.Identity) /p:ExecutableOutputType=true" />
48+
49+
<ItemGroup>
50+
<None Include="$(MSBuildThisFileDirectory)..\..\..\..\Libraries\src\Amazon.Lambda.RuntimeSupport\bin\$(Configuration)\%(TargetFrameworks.Identity)\publish\**\*.*">
51+
<Pack>true</Pack>
52+
<PackagePath>content\Amazon.Lambda.RuntimeSupport\%(TargetFrameworks.Identity)</PackagePath>
53+
</None>
54+
</ItemGroup>
55+
</Target>
56+
3257
<ItemGroup>
3358
<EmbeddedResource Include="Resources\**" />
3459
</ItemGroup>
35-
3660
</Project>
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.IO.Compression;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using Xunit;
8+
using Xunit.Abstractions;
9+
10+
namespace Amazon.Lambda.TestTool.UnitTests;
11+
12+
public class PackagingTests
13+
{
14+
private readonly ITestOutputHelper _output;
15+
private readonly string[] _expectedFrameworks;
16+
17+
public PackagingTests(ITestOutputHelper output)
18+
{
19+
_output = output;
20+
_expectedFrameworks = GetRuntimeSupportTargetFrameworks()
21+
.Split([';'], StringSplitOptions.RemoveEmptyEntries)
22+
.Where(f => f != "netstandard2.0")
23+
.ToArray();
24+
}
25+
26+
private string GetRuntimeSupportTargetFrameworks()
27+
{
28+
var solutionRoot = FindSolutionRoot();
29+
var runtimeSupportPath = Path.Combine(solutionRoot, "Libraries", "src", "Amazon.Lambda.RuntimeSupport", "Amazon.Lambda.RuntimeSupport.csproj");
30+
31+
var process = new Process
32+
{
33+
StartInfo = new ProcessStartInfo
34+
{
35+
FileName = "dotnet",
36+
Arguments = $"msbuild {runtimeSupportPath} --getProperty:TargetFrameworks",
37+
RedirectStandardOutput = true,
38+
RedirectStandardError = true,
39+
UseShellExecute = false,
40+
CreateNoWindow = true,
41+
}
42+
};
43+
44+
process.Start();
45+
var output = process.StandardOutput.ReadToEnd();
46+
var error = process.StandardError.ReadToEnd();
47+
process.WaitForExit();
48+
49+
if (process.ExitCode != 0)
50+
{
51+
throw new Exception($"Failed to get TargetFrameworks: {error}");
52+
}
53+
54+
return output.Trim();
55+
}
56+
57+
[Fact]
58+
public void VerifyPackageContentsHasRuntimeSupport()
59+
{
60+
var solutionRoot = FindSolutionRoot();
61+
var projectPath = Path.Combine(solutionRoot, "Tools", "LambdaTestTool-v2", "src", "Amazon.Lambda.TestTool", "Amazon.Lambda.TestTool.csproj");
62+
63+
_output.WriteLine("\nPacking TestTool...");
64+
var packProcess = new Process
65+
{
66+
StartInfo = new ProcessStartInfo
67+
{
68+
FileName = "dotnet",
69+
Arguments = $"pack {projectPath} -c Release",
70+
RedirectStandardOutput = true,
71+
RedirectStandardError = true,
72+
UseShellExecute = false,
73+
CreateNoWindow = true,
74+
}
75+
};
76+
77+
packProcess.Start();
78+
string packOutput = packProcess.StandardOutput.ReadToEnd();
79+
string packError = packProcess.StandardError.ReadToEnd();
80+
packProcess.WaitForExit();
81+
82+
_output.WriteLine("Pack Output:");
83+
_output.WriteLine(packOutput);
84+
if (!string.IsNullOrEmpty(packError))
85+
{
86+
_output.WriteLine("Pack Errors:");
87+
_output.WriteLine(packError);
88+
}
89+
90+
Assert.Equal(0, packProcess.ExitCode);
91+
92+
var packageDir = Path.Combine(Path.GetDirectoryName(projectPath), "bin", "Release");
93+
_output.WriteLine($"Looking for package in: {packageDir}");
94+
95+
var packageFiles = Directory.GetFiles(packageDir, "*.nupkg", SearchOption.AllDirectories);
96+
Assert.True(packageFiles.Length > 0, $"No .nupkg files found in {packageDir}");
97+
98+
var packagePath = packageFiles[0];
99+
_output.WriteLine($"Found package: {packagePath}");
100+
101+
using var archive = ZipFile.OpenRead(packagePath);
102+
// Verify each framework has its required files
103+
foreach (var framework in _expectedFrameworks)
104+
{
105+
_output.WriteLine($"\nChecking framework: {framework}");
106+
107+
// Get all files for this framework
108+
var frameworkFiles = archive.Entries
109+
.Where(e => e.FullName.StartsWith($"content/Amazon.Lambda.RuntimeSupport/{framework}/"))
110+
.Select(e => e.FullName)
111+
.ToList();
112+
113+
// Verify essential files exist
114+
var essentialFiles = new[]
115+
{
116+
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.Core.dll",
117+
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.dll",
118+
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.deps.json",
119+
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.runtimeconfig.json"
120+
};
121+
122+
var missingFiles = essentialFiles.Where(f => !frameworkFiles.Contains(f)).ToList();
123+
124+
if (missingFiles.Any())
125+
{
126+
Assert.Fail($"The following essential files are missing for {framework}:\n" +
127+
string.Join("\n", missingFiles));
128+
}
129+
130+
_output.WriteLine($"Files found for {framework}:");
131+
foreach (var file in frameworkFiles)
132+
{
133+
_output.WriteLine($" {file}");
134+
}
135+
}
136+
}
137+
138+
private string FindSolutionRoot()
139+
{
140+
string currentDirectory = Directory.GetCurrentDirectory();
141+
while (currentDirectory != null)
142+
{
143+
// Look for the aws-lambda-dotnet directory specifically
144+
if (Path.GetFileName(currentDirectory) == "aws-lambda-dotnet")
145+
{
146+
return currentDirectory;
147+
}
148+
currentDirectory = Directory.GetParent(currentDirectory)?.FullName;
149+
}
150+
throw new Exception("Could not find the aws-lambda-dotnet root directory.");
151+
}
152+
}

0 commit comments

Comments
 (0)