Skip to content

Commit c5d5c83

Browse files
feat: add dotnet8 support (#587)
* feat: add dotnet8 support * Fix dotnet test, remove collections.Counter --------- Co-authored-by: Mehmet Nuri Deveci <[email protected]>
1 parent 57b74ab commit c5d5c83

File tree

10 files changed

+130
-36
lines changed

10 files changed

+130
-36
lines changed

aws_lambda_builders/validator.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"java21": [ARM64, X86_64],
2626
"go1.x": [ARM64, X86_64],
2727
"dotnet6": [ARM64, X86_64],
28+
"dotnet8": [ARM64, X86_64],
2829
"provided": [ARM64, X86_64],
2930
}
3031

tests/functional/test_actions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_copy_dependencies_action(self, source_folder):
3030
copy_dependencies_action = CopyDependenciesAction(empty_source, test_folder, target)
3131
copy_dependencies_action.execute()
3232

33-
self.assertEqual(os.listdir(test_folder), os.listdir(target))
33+
self.assertEqual(set(os.listdir(test_folder)), set(os.listdir(target)))
3434

3535
def test_must_maintain_symlinks_if_enabled(self):
3636
with tempfile.TemporaryDirectory() as tmpdir:
@@ -116,4 +116,4 @@ def test_move_dependencies_action(self, source_folder):
116116
move_dependencies_action = MoveDependenciesAction(empty_source, test_source, target)
117117
move_dependencies_action.execute()
118118

119-
self.assertEqual(os.listdir(test_folder), os.listdir(target))
119+
self.assertEqual(set(os.listdir(test_folder)), set(os.listdir(target)))

tests/integration/workflows/dotnet_clipackage/test_dotnet.py

+45-29
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import shutil
33
import tempfile
44
import json
5+
from parameterized import parameterized
56

67
try:
78
import pathlib
@@ -25,21 +26,19 @@ def setUp(self):
2526
self.artifacts_dir = tempfile.mkdtemp()
2627
self.scratch_dir = tempfile.mkdtemp()
2728
self.builder = LambdaBuilder(language="dotnet", dependency_manager="cli-package", application_framework=None)
28-
self.runtime = "dotnet6"
2929

3030
def tearDown(self):
3131
shutil.rmtree(self.artifacts_dir)
3232
shutil.rmtree(self.scratch_dir)
3333

34-
def verify_architecture(self, deps_file_name, expected_architecture, version=None):
34+
def verify_architecture(self, deps_file_name, expected_architecture, version):
3535
deps_file = pathlib.Path(self.artifacts_dir, deps_file_name)
3636

3737
if not deps_file.exists():
3838
self.fail("Failed verifying architecture, {} file not found".format(deps_file_name))
3939

4040
with open(str(deps_file)) as f:
4141
deps_json = json.loads(f.read())
42-
version = version or self.runtime[-3:]
4342
target_name = ".NETCoreApp,Version=v{}/{}".format(version, expected_architecture)
4443
target = deps_json.get("runtimeTarget").get("name")
4544

@@ -50,19 +49,24 @@ def verify_execute_permissions(self, entrypoint_file_name):
5049
self.assertTrue(os.access(entrypoint_file_path, os.X_OK))
5150

5251

53-
class TestDotnet6(TestDotnetBase):
52+
class TestDotnet(TestDotnetBase):
5453
"""
55-
Tests for dotnet 6
54+
Tests for dotnet
5655
"""
5756

5857
def setUp(self):
59-
super(TestDotnet6, self).setUp()
60-
self.runtime = "dotnet6"
58+
super(TestDotnet, self).setUp()
6159

62-
def test_with_defaults_file(self):
63-
source_dir = os.path.join(self.TEST_DATA_FOLDER, "WithDefaultsFile6")
60+
@parameterized.expand(
61+
[
62+
("dotnet6", "6.0", "WithDefaultsFile6"),
63+
("dotnet8", "8.0", "WithDefaultsFile8"),
64+
]
65+
)
66+
def test_with_defaults_file(self, runtime, version, test_project):
67+
source_dir = os.path.join(self.TEST_DATA_FOLDER, test_project)
6468

65-
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime=self.runtime)
69+
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime)
6670

6771
expected_files = {
6872
"Amazon.Lambda.Core.dll",
@@ -77,14 +81,18 @@ def test_with_defaults_file(self):
7781
output_files = set(os.listdir(self.artifacts_dir))
7882

7983
self.assertEqual(expected_files, output_files)
80-
self.verify_architecture("WithDefaultsFile.deps.json", "linux-x64", version="6.0")
84+
self.verify_architecture("WithDefaultsFile.deps.json", "linux-x64", version)
8185

82-
def test_with_defaults_file_x86(self):
83-
source_dir = os.path.join(self.TEST_DATA_FOLDER, "WithDefaultsFile6")
86+
@parameterized.expand(
87+
[
88+
("dotnet6", "6.0", "WithDefaultsFile6"),
89+
("dotnet8", "8.0", "WithDefaultsFile8"),
90+
]
91+
)
92+
def test_with_defaults_file_x86(self, runtime, version, test_project):
93+
source_dir = os.path.join(self.TEST_DATA_FOLDER, test_project)
8494

85-
self.builder.build(
86-
source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime=self.runtime, architecture=X86_64
87-
)
95+
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime, architecture=X86_64)
8896

8997
expected_files = {
9098
"Amazon.Lambda.Core.dll",
@@ -99,14 +107,18 @@ def test_with_defaults_file_x86(self):
99107
output_files = set(os.listdir(self.artifacts_dir))
100108

101109
self.assertEqual(expected_files, output_files)
102-
self.verify_architecture("WithDefaultsFile.deps.json", "linux-x64", version="6.0")
110+
self.verify_architecture("WithDefaultsFile.deps.json", "linux-x64", version)
103111

104-
def test_with_defaults_file_arm64(self):
105-
source_dir = os.path.join(self.TEST_DATA_FOLDER, "WithDefaultsFile6")
112+
@parameterized.expand(
113+
[
114+
("dotnet6", "6.0", "WithDefaultsFile6"),
115+
("dotnet8", "8.0", "WithDefaultsFile8"),
116+
]
117+
)
118+
def test_with_defaults_file_arm64(self, runtime, version, test_project):
119+
source_dir = os.path.join(self.TEST_DATA_FOLDER, test_project)
106120

107-
self.builder.build(
108-
source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime=self.runtime, architecture=ARM64
109-
)
121+
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime, architecture=ARM64)
110122

111123
expected_files = {
112124
"Amazon.Lambda.Core.dll",
@@ -121,14 +133,18 @@ def test_with_defaults_file_arm64(self):
121133
output_files = set(os.listdir(self.artifacts_dir))
122134

123135
self.assertEqual(expected_files, output_files)
124-
self.verify_architecture("WithDefaultsFile.deps.json", "linux-arm64", version="6.0")
136+
self.verify_architecture("WithDefaultsFile.deps.json", "linux-arm64", version)
125137

126-
def test_with_custom_runtime(self):
127-
source_dir = os.path.join(self.TEST_DATA_FOLDER, "CustomRuntime6")
138+
@parameterized.expand(
139+
[
140+
("dotnet6", "6.0", "CustomRuntime6"),
141+
("dotnet8", "8.0", "CustomRuntime8"),
142+
]
143+
)
144+
def test_with_custom_runtime(self, runtime, version, test_project):
145+
source_dir = os.path.join(self.TEST_DATA_FOLDER, test_project)
128146

129-
self.builder.build(
130-
source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime=self.runtime, architecture=X86_64
131-
)
147+
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime, architecture=X86_64)
132148

133149
expected_files = {
134150
"Amazon.Lambda.Core.dll",
@@ -144,7 +160,7 @@ def test_with_custom_runtime(self):
144160
output_files = set(os.listdir(self.artifacts_dir))
145161

146162
self.assertEqual(expected_files, output_files)
147-
self.verify_architecture("bootstrap.deps.json", "linux-x64", version="6.0")
163+
self.verify_architecture("bootstrap.deps.json", "linux-x64", version)
148164
# Execute permissions are required for custom runtimes which bootstrap themselves, otherwise `sam local invoke`
149165
# won't have permission to run the file
150166
self.verify_execute_permissions("bootstrap")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<AWSProjectType>Lambda</AWSProjectType>
8+
<AssemblyName>bootstrap</AssemblyName>
9+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
10+
<PublishReadyToRun>true</PublishReadyToRun>
11+
</PropertyGroup>
12+
<ItemGroup>
13+
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.8.2" />
14+
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
15+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.0" />
16+
</ItemGroup>
17+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Amazon.Lambda.Core;
2+
using Amazon.Lambda.RuntimeSupport;
3+
using Amazon.Lambda.Serialization.SystemTextJson;
4+
5+
namespace CustomRuntime6;
6+
7+
public class Function
8+
{
9+
private static async Task Main(string[] args)
10+
{
11+
Func<string, ILambdaContext, string> handler = FunctionHandler;
12+
await LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
13+
.Build()
14+
.RunAsync();
15+
}
16+
17+
public static string FunctionHandler(string input, ILambdaContext context)
18+
{
19+
return input.ToUpper();
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"Information": [
3+
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
4+
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
5+
"dotnet lambda help",
6+
"All the command line options for the Lambda command can be specified in this file."
7+
],
8+
"profile": "",
9+
"region": "",
10+
"configuration": "Release",
11+
"function-runtime": "provided.al2",
12+
"function-memory-size": 256,
13+
"function-timeout": 30,
14+
"function-handler": "bootstrap",
15+
"msbuild-parameters": "--self-contained true"
16+
}

tests/integration/workflows/dotnet_clipackage/testdata/RequireParameters/RequireParameters.cs tests/integration/workflows/dotnet_clipackage/testdata/WithDefaultsFile8/Function.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
99
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
1010

11-
namespace RequireParameters
11+
namespace WithDefaultsFile
1212
{
1313
public class Function
1414
{

tests/integration/workflows/dotnet_clipackage/testdata/RequireParameters/RequireParameters.csproj tests/integration/workflows/dotnet_clipackage/testdata/WithDefaultsFile8/WithDefaultsFile.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFramework>net8.0</TargetFramework>
44
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
55
<AWSProjectType>Lambda</AWSProjectType>
66
</PropertyGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"Information": [
3+
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
4+
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
5+
"dotnet lambda help",
6+
"All the command line options for the Lambda command can be specified in this file."
7+
],
8+
"profile": "",
9+
"region": "",
10+
"configuration": "Release",
11+
"framework": "net8.0",
12+
"function-runtime": "dotnet8",
13+
"function-memory-size": 256,
14+
"function-timeout": 30,
15+
"function-handler": "WithDefaultsFile::WithDefaultsFile.Function::FunctionHandler"
16+
}

tests/unit/workflows/dotnet_clipackage/test_actions.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import platform
55
from concurrent.futures import ThreadPoolExecutor
66
from unittest.mock import patch
7+
from parameterized import parameterized
78

89
from aws_lambda_builders.actions import ActionFailedError
910
from aws_lambda_builders.architecture import ARM64, X86_64
@@ -154,9 +155,15 @@ def test_build_package_arm64(self):
154155
cwd="/source_dir",
155156
)
156157

157-
def test_build_package_arguments(self):
158+
@parameterized.expand(
159+
[
160+
("net6.0"),
161+
("net8.0"),
162+
]
163+
)
164+
def test_build_package_arguments(self, dotnet_version):
158165
mode = "Release"
159-
options = {"--framework": "net6.0"}
166+
options = {"--framework": dotnet_version}
160167
action = RunPackageAction(
161168
self.source_dir, self.subprocess_dotnet, self.artifacts_dir, options, mode, os_utils=self.os_utils
162169
)
@@ -176,7 +183,7 @@ def test_build_package_arguments(self):
176183
"--msbuild-parameters",
177184
"--runtime linux-x64",
178185
"--framework",
179-
"net6.0",
186+
dotnet_version,
180187
],
181188
cwd="/source_dir",
182189
)

0 commit comments

Comments
 (0)