From 00ddf5ffd8a0443920f51d0c2b821c7c3d933487 Mon Sep 17 00:00:00 2001 From: Surgupta Date: Tue, 24 Sep 2024 13:46:31 -0700 Subject: [PATCH 01/16] vlaidation changes --- .../Actions/HostActions/StartHostAction.cs | 9 +++-- .../E2E/StartTests.cs | 40 ++++++++++++++----- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs b/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs index 5e31d9023..9ea4f1b66 100644 --- a/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs +++ b/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs @@ -494,8 +494,7 @@ private async Task ShouldExitAfterDeterminingHostRuntime(bool isVerbose) if (!string.Equals(HostRuntime, "default", StringComparison.OrdinalIgnoreCase)) { - var isNet8InProcSpecified = string.Equals(HostRuntime, DotnetConstants.InProc8HostRuntime, StringComparison.OrdinalIgnoreCase); - StartHostAsChildProcess(isNet8InProcSpecified); + PrintMessageForInProcSdk(); return true; } } @@ -514,7 +513,7 @@ private async Task ShouldExitAfterDeterminingHostRuntime(bool isVerbose) PrintVerboseForHostSelection(isVerbose, DotnetConstants.InProc6HostRuntime); } - StartHostAsChildProcess(shouldNet8InProcBeLaunched); + PrintMessageForInProcSdk(); return true; } @@ -571,6 +570,10 @@ private async Task ValidateHostRuntime(bool isInProc, bool isVerbose) throw new CliException($"Invalid host runtime '{HostRuntime}'. Valid values are 'default', '{DotnetConstants.InProc8HostRuntime}', '{DotnetConstants.InProc6HostRuntime}'."); } + private void PrintMessageForInProcSdk() + { + Console.WriteLine($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}. Please update to the latest version. For more information, see: {DotnetConstants.InProcFunctionsDocsLink}"); + } private void PrintVerboseForHostSelection(bool isVerbose, string hostRuntime) { if (isVerbose) diff --git a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs index 8e8dfa14b..a08fba219 100644 --- a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs +++ b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs @@ -401,15 +401,19 @@ await CliTester.Run(new RunConfiguration "start --port 7073 --verbose" }, ExpectExit = true, - ErrorContains = ["Failed to locate the inproc8 model host"], Test = async (workingDir, p) => { using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { await Task.Delay(TimeSpan.FromSeconds(2)); } + + if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) + { + testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); + } }, - CommandTimeout = TimeSpan.FromSeconds(300), + CommandTimeout = TimeSpan.FromSeconds(900), }, _output); } @@ -425,15 +429,19 @@ await CliTester.Run(new RunConfiguration "start --port 7076 --verbose --runtime inproc8" }, ExpectExit = true, - ErrorContains = ["Failed to locate the inproc8 model host"], Test = async (workingDir, p) => { using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7076") }) { await Task.Delay(TimeSpan.FromSeconds(2)); } + + if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) + { + testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); + } }, - CommandTimeout = TimeSpan.FromSeconds(300), + CommandTimeout = TimeSpan.FromSeconds(900), }, _output); } @@ -449,15 +457,19 @@ await CliTester.Run(new RunConfiguration "start --port 7073 --verbose" }, ExpectExit = false, - ErrorContains = ["Failed to locate the inproc6 model host at"], Test = async (workingDir, p) => { using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { await Task.Delay(TimeSpan.FromSeconds(2)); } + + if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) + { + testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); + } }, - CommandTimeout = TimeSpan.FromSeconds(300), + CommandTimeout = TimeSpan.FromSeconds(900), }, _output); } @@ -473,15 +485,19 @@ await CliTester.Run(new RunConfiguration "start --port 7073 --verbose --runtime inproc6" }, ExpectExit = false, - ErrorContains = ["Failed to locate the inproc6 model host at"], Test = async (workingDir, p) => { using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { await Task.Delay(TimeSpan.FromSeconds(2)); } + + if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) + { + testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); + } }, - CommandTimeout = TimeSpan.FromSeconds(100), + CommandTimeout = TimeSpan.FromSeconds(900), }, _output); } @@ -689,15 +705,19 @@ await CliTester.Run(new RunConfiguration "start --port 7073 --verbose --runtime inproc6" }, ExpectExit = false, - ErrorContains = ["Failed to locate the inproc6 model host at"], Test = async (workingDir, p) => { using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { await Task.Delay(TimeSpan.FromSeconds(2)); } + + if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) + { + testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); + } }, - CommandTimeout = TimeSpan.FromSeconds(100), + CommandTimeout = TimeSpan.FromSeconds(900), }, _output); } From 53023cc8207040919ee9c3f3a52be05209dca7c6 Mon Sep 17 00:00:00 2001 From: Surgupta Date: Tue, 24 Sep 2024 23:24:19 -0700 Subject: [PATCH 02/16] Test fix --- .../E2E/StartTests.cs | 41 +++---------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs index a08fba219..362364c1d 100644 --- a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs +++ b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs @@ -413,7 +413,7 @@ await CliTester.Run(new RunConfiguration testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); } }, - CommandTimeout = TimeSpan.FromSeconds(900), + CommandTimeout = TimeSpan.FromSeconds(300), }, _output); } @@ -441,7 +441,7 @@ await CliTester.Run(new RunConfiguration testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); } }, - CommandTimeout = TimeSpan.FromSeconds(900), + CommandTimeout = TimeSpan.FromSeconds(300), }, _output); } @@ -461,7 +461,7 @@ await CliTester.Run(new RunConfiguration { using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { - await Task.Delay(TimeSpan.FromSeconds(2)); + await Task.Delay(TimeSpan.FromSeconds(10)); } if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) @@ -469,7 +469,7 @@ await CliTester.Run(new RunConfiguration testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); } }, - CommandTimeout = TimeSpan.FromSeconds(900), + CommandTimeout = TimeSpan.FromSeconds(300), }, _output); } @@ -489,7 +489,7 @@ await CliTester.Run(new RunConfiguration { using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { - await Task.Delay(TimeSpan.FromSeconds(2)); + await Task.Delay(TimeSpan.FromSeconds(10)); } if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) @@ -497,7 +497,7 @@ await CliTester.Run(new RunConfiguration testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); } }, - CommandTimeout = TimeSpan.FromSeconds(900), + CommandTimeout = TimeSpan.FromSeconds(300), }, _output); } @@ -693,35 +693,6 @@ await CliTester.Run(new RunConfiguration }, _output); } - [Fact] - public async Task start_dotnet_isolated_inproc_with_specifying_runtime() - { - await CliTester.Run(new RunConfiguration - { - Commands = new[] - { - "init . --worker-runtime dotnet --target-framework net6.0", - "new --template Httptrigger --name HttpTrigger", - "start --port 7073 --verbose --runtime inproc6" - }, - ExpectExit = false, - Test = async (workingDir, p) => - { - using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) - { - await Task.Delay(TimeSpan.FromSeconds(2)); - } - - if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) - { - testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); - } - }, - CommandTimeout = TimeSpan.FromSeconds(900), - }, _output); - } - - [Fact] public async Task start_dotnet_isolated_csharp_with_oop_host_with_runtime_specified() { From a3450b096e29556cb06a4f63da0a0b14325b5555 Mon Sep 17 00:00:00 2001 From: Surgupta Date: Wed, 25 Sep 2024 09:53:09 -0700 Subject: [PATCH 03/16] Tests update --- test/Azure.Functions.Cli.Tests/E2E/StartTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs index 362364c1d..7b8e58d59 100644 --- a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs +++ b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs @@ -461,7 +461,7 @@ await CliTester.Run(new RunConfiguration { using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { - await Task.Delay(TimeSpan.FromSeconds(10)); + await Task.Delay(TimeSpan.FromSeconds(5)); } if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) @@ -489,7 +489,7 @@ await CliTester.Run(new RunConfiguration { using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { - await Task.Delay(TimeSpan.FromSeconds(10)); + await Task.Delay(TimeSpan.FromSeconds(5)); } if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) From 3d42b30092c40fe3a7c8ce276f4cdcd9dcf8a9cf Mon Sep 17 00:00:00 2001 From: Surgupta Date: Wed, 25 Sep 2024 15:12:30 -0700 Subject: [PATCH 04/16] Adding constants --- src/Azure.Functions.Cli/Common/DotnetConstants.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Azure.Functions.Cli/Common/DotnetConstants.cs b/src/Azure.Functions.Cli/Common/DotnetConstants.cs index 8575ee976..5b59fbc45 100644 --- a/src/Azure.Functions.Cli/Common/DotnetConstants.cs +++ b/src/Azure.Functions.Cli/Common/DotnetConstants.cs @@ -14,5 +14,8 @@ internal static class DotnetConstants public const string InProc6DirectoryName = "in-proc6"; public const string InProc8HostRuntime = "inproc8"; public const string InProc6HostRuntime = "inproc6"; + public const string InProcFunctionsSdk = "Microsoft.NET.Sdk.Functions"; + public const string InProcFunctionsMinSdkVersion = "4.5.0"; + public const string InProcFunctionsDocsLink = "https://aka.ms/functions-core-tools-in-proc-sdk-requirement"; } } From 2c82475d8df2fffdd15a24f680884a939f772aff Mon Sep 17 00:00:00 2001 From: Surgupta Date: Thu, 26 Sep 2024 18:01:35 -0700 Subject: [PATCH 05/16] Changes that checks for minified version --- .../Actions/HostActions/StartHostAction.cs | 24 +++++++++++++--- .../ArtifactsConfigurationBuilder.cs | 18 ++++++++++++ .../Azure.Functions.Cli.csproj | 3 ++ src/Azure.Functions.Cli/Common/Constants.cs | 2 ++ src/Azure.Functions.Cli/Common/Utilities.cs | 28 +++++++++++++++++++ src/Azure.Functions.Cli/artifactsconfig.json | 3 ++ 6 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs create mode 100644 src/Azure.Functions.Cli/artifactsconfig.json diff --git a/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs b/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs index 9ea4f1b66..e8bb3b90c 100644 --- a/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs +++ b/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs @@ -494,7 +494,16 @@ private async Task ShouldExitAfterDeterminingHostRuntime(bool isVerbose) if (!string.Equals(HostRuntime, "default", StringComparison.OrdinalIgnoreCase)) { - PrintMessageForInProcSdk(); + if (Utilities.IsMinifiedVersion()) + { + ThrowIfInProc(); + } + else + { + var isNet8InProcSpecified = string.Equals(HostRuntime, DotnetConstants.InProc8HostRuntime, StringComparison.OrdinalIgnoreCase); + StartHostAsChildProcess(isNet8InProcSpecified); + } + return true; } } @@ -513,7 +522,14 @@ private async Task ShouldExitAfterDeterminingHostRuntime(bool isVerbose) PrintVerboseForHostSelection(isVerbose, DotnetConstants.InProc6HostRuntime); } - PrintMessageForInProcSdk(); + if (Utilities.IsMinifiedVersion()) + { + ThrowIfInProc(); + } + else + { + StartHostAsChildProcess(shouldNet8InProcBeLaunched); + } return true; } @@ -570,9 +586,9 @@ private async Task ValidateHostRuntime(bool isInProc, bool isVerbose) throw new CliException($"Invalid host runtime '{HostRuntime}'. Valid values are 'default', '{DotnetConstants.InProc8HostRuntime}', '{DotnetConstants.InProc6HostRuntime}'."); } - private void PrintMessageForInProcSdk() + private void ThrowIfInProc() { - Console.WriteLine($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}. Please update to the latest version. For more information, see: {DotnetConstants.InProcFunctionsDocsLink}"); + throw new CliException($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}. Please update to the latest version. For more information, see: {DotnetConstants.InProcFunctionsDocsLink}"); } private void PrintVerboseForHostSelection(bool isVerbose, string hostRuntime) { diff --git a/src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs b/src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs new file mode 100644 index 000000000..c8a10110d --- /dev/null +++ b/src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs @@ -0,0 +1,18 @@ +using Microsoft.Azure.WebJobs.Script; +using Microsoft.Extensions.Configuration; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Azure.Functions.Cli +{ + internal class ArtifactsConfigurationBuilder : IConfigureBuilder + { + public void Configure(IConfigurationBuilder builder) + { + builder.AddJsonFile("artifactsconfig.json", optional: true); + } + } +} diff --git a/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj b/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj index 6eac661ac..746ad4d7f 100644 --- a/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj +++ b/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj @@ -269,6 +269,9 @@ tools\python\packapp\__main__.py Always + + Always + diff --git a/src/Azure.Functions.Cli/Common/Constants.cs b/src/Azure.Functions.Cli/Common/Constants.cs index 47b7be41c..c2828cbfe 100644 --- a/src/Azure.Functions.Cli/Common/Constants.cs +++ b/src/Azure.Functions.Cli/Common/Constants.cs @@ -26,6 +26,8 @@ internal static class Constants public const string HostJsonFileName = "host.json"; public const string PackageJsonFileName = "package.json"; public const string ProxiesJsonFileName = "proxies.json"; + public const string ArtifactsConfigFileName = "artifactsconfig.json"; + public const string MinifiedVersionConfigSectionName = "minifiedVersion"; public const string ExtensionsCsProjFile = "extensions.csproj"; public const string DefaultVEnvName = "worker_env"; public const string ExternalPythonPackages = ".python_packages"; diff --git a/src/Azure.Functions.Cli/Common/Utilities.cs b/src/Azure.Functions.Cli/Common/Utilities.cs index 8dfe174be..4694ab677 100644 --- a/src/Azure.Functions.Cli/Common/Utilities.cs +++ b/src/Azure.Functions.Cli/Common/Utilities.cs @@ -263,5 +263,33 @@ internal static IConfigurationRoot BuildHostJsonConfigutation(ScriptApplicationH var configuration = builder.Build(); return configuration; } + + internal static bool IsMinifiedVersion() + { + var config = BuildArtifactsConfiguration(); + + try + { + var section = config.GetSection(Constants.MinifiedVersionConfigSectionName); + + if (section.Exists()) + { + string value = section.Value; + return bool.TryParse(value, out bool isValue) && isValue; + } + } + catch { } + return false; + } + + internal static IConfigurationRoot BuildArtifactsConfiguration() + { + var configureBuilder = new ArtifactsConfigurationBuilder(); + var configurationBuilder = new ConfigurationBuilder(); + configureBuilder.Configure(configurationBuilder); + var root = configurationBuilder.Build(); + return root; + } + } } diff --git a/src/Azure.Functions.Cli/artifactsconfig.json b/src/Azure.Functions.Cli/artifactsconfig.json new file mode 100644 index 000000000..d41294a32 --- /dev/null +++ b/src/Azure.Functions.Cli/artifactsconfig.json @@ -0,0 +1,3 @@ +{ + "minifiedVersion" : true +} \ No newline at end of file From 60bfb34e927a46b9d55fc10b9ad10eee00d06cb3 Mon Sep 17 00:00:00 2001 From: Surgupta Date: Thu, 26 Sep 2024 18:18:58 -0700 Subject: [PATCH 06/16] Tests update --- .../E2E/StartTests.cs | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs index 7b8e58d59..98ab66371 100644 --- a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs +++ b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs @@ -401,17 +401,13 @@ await CliTester.Run(new RunConfiguration "start --port 7073 --verbose" }, ExpectExit = true, + ErrorContains = ["Failed to locate the inproc8 model host"], Test = async (workingDir, p) => { using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { await Task.Delay(TimeSpan.FromSeconds(2)); } - - if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) - { - testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); - } }, CommandTimeout = TimeSpan.FromSeconds(300), }, _output); @@ -429,24 +425,22 @@ await CliTester.Run(new RunConfiguration "start --port 7076 --verbose --runtime inproc8" }, ExpectExit = true, + ErrorContains = ["Failed to locate the inproc8 model host"], Test = async (workingDir, p) => { using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7076") }) { await Task.Delay(TimeSpan.FromSeconds(2)); } - - if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) - { - testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); - } }, CommandTimeout = TimeSpan.FromSeconds(300), }, _output); } - [Fact] - public async Task start_dotnet6_inproc_without_specifying_runtime() + [Theory] + [InlineData(true, $"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}.")] + [InlineData(false, "Failed to locate the inproc6 model host at")] + public async Task start_dotnet6_inproc_without_specifying_runtime(bool value, string message) { await CliTester.Run(new RunConfiguration { @@ -457,24 +451,26 @@ await CliTester.Run(new RunConfiguration "start --port 7073 --verbose" }, ExpectExit = false, + ErrorContains = [message], Test = async (workingDir, p) => { + var filePath = Path.Combine(workingDir, "artifactsconfig.json"); + string artifactsconfigContent = "{\"minifiedVersion\": " + value + "}}"; + await File.WriteAllTextAsync(filePath, artifactsconfigContent); + using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { await Task.Delay(TimeSpan.FromSeconds(5)); } - - if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) - { - testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); - } }, CommandTimeout = TimeSpan.FromSeconds(300), }, _output); } - [Fact] - public async Task start_dotnet6_inproc_with_specifying_runtime() + [Theory] + [InlineData(true, $"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}.")] + [InlineData(false, "Failed to locate the inproc6 model host at")] + public async Task start_dotnet6_inproc_with_specifying_runtime(bool value, string message) { await CliTester.Run(new RunConfiguration { @@ -485,17 +481,17 @@ await CliTester.Run(new RunConfiguration "start --port 7073 --verbose --runtime inproc6" }, ExpectExit = false, + ErrorContains = [message], Test = async (workingDir, p) => { + var filePath = Path.Combine(workingDir, "artifactsconfig.json"); + string artifactsconfigContent = "{\"minifiedVersion\": "+value+"}}"; + await File.WriteAllTextAsync(filePath, artifactsconfigContent); + using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { await Task.Delay(TimeSpan.FromSeconds(5)); } - - if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper) - { - testOutputHelper.Output.Should().Contain($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}."); - } }, CommandTimeout = TimeSpan.FromSeconds(300), }, _output); From a20f805d3bfba41c3c6937f0dfc057b3dcf91b65 Mon Sep 17 00:00:00 2001 From: Surgupta Date: Thu, 26 Sep 2024 18:01:35 -0700 Subject: [PATCH 07/16] Changes that checks for minified version From cfb698d9bceba3925f8ed15757623a8320caa685 Mon Sep 17 00:00:00 2001 From: Surgupta Date: Fri, 27 Sep 2024 12:55:47 -0700 Subject: [PATCH 08/16] Tests update --- .../E2E/StartTests.cs | 26 +++++-------------- .../UtilitiesTests.cs | 16 ++++++++++++ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs index 98ab66371..510b9e0ae 100644 --- a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs +++ b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs @@ -437,10 +437,8 @@ await CliTester.Run(new RunConfiguration }, _output); } - [Theory] - [InlineData(true, $"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}.")] - [InlineData(false, "Failed to locate the inproc6 model host at")] - public async Task start_dotnet6_inproc_without_specifying_runtime(bool value, string message) + [Fact] + public async Task start_dotnet6_inproc_without_specifying_runtime() { await CliTester.Run(new RunConfiguration { @@ -451,13 +449,9 @@ await CliTester.Run(new RunConfiguration "start --port 7073 --verbose" }, ExpectExit = false, - ErrorContains = [message], + ErrorContains = ["Failed to locate the inproc6 model host at"], Test = async (workingDir, p) => { - var filePath = Path.Combine(workingDir, "artifactsconfig.json"); - string artifactsconfigContent = "{\"minifiedVersion\": " + value + "}}"; - await File.WriteAllTextAsync(filePath, artifactsconfigContent); - using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { await Task.Delay(TimeSpan.FromSeconds(5)); @@ -467,10 +461,8 @@ await CliTester.Run(new RunConfiguration }, _output); } - [Theory] - [InlineData(true, $"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}.")] - [InlineData(false, "Failed to locate the inproc6 model host at")] - public async Task start_dotnet6_inproc_with_specifying_runtime(bool value, string message) + [Fact] + public async Task start_dotnet6_inproc_with_specifying_runtime() { await CliTester.Run(new RunConfiguration { @@ -481,13 +473,10 @@ await CliTester.Run(new RunConfiguration "start --port 7073 --verbose --runtime inproc6" }, ExpectExit = false, - ErrorContains = [message], + ErrorContains = ["Failed to locate the inproc6 model host at"], Test = async (workingDir, p) => { - var filePath = Path.Combine(workingDir, "artifactsconfig.json"); - string artifactsconfigContent = "{\"minifiedVersion\": "+value+"}}"; - await File.WriteAllTextAsync(filePath, artifactsconfigContent); - + using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { await Task.Delay(TimeSpan.FromSeconds(5)); @@ -496,7 +485,6 @@ await CliTester.Run(new RunConfiguration CommandTimeout = TimeSpan.FromSeconds(300), }, _output); } - [Fact] public async Task dont_start_inproc6_specified_runtime_for_dotnet_isolated() { diff --git a/test/Azure.Functions.Cli.Tests/UtilitiesTests.cs b/test/Azure.Functions.Cli.Tests/UtilitiesTests.cs index 098cdfd09..d64fdbb41 100644 --- a/test/Azure.Functions.Cli.Tests/UtilitiesTests.cs +++ b/test/Azure.Functions.Cli.Tests/UtilitiesTests.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using System.Collections.Generic; +using System.IO; using Xunit; namespace Azure.Functions.Cli.Tests @@ -60,5 +61,20 @@ public void IsSystemLogCategory_Test(string inputCategory, bool expected) { Assert.Equal(expected, Utilities.IsSystemLogCategory(inputCategory)); } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void Test_IsMinifiedVersion(bool expected) + { + var filePath = Path.Combine("artifactsconfig.json"); + string artifactsJsonContent = "{\"minifiedVersion\": " + expected.ToString().ToLower() + "}"; + File.WriteAllTextAsync(filePath, artifactsJsonContent).GetAwaiter().GetResult(); + + bool output = Utilities.IsMinifiedVersion(); + + File.Delete(filePath); + Assert.Equal(expected, output); + } } } From 3fe9289921391785022d076ea3acc3cb84b60d71 Mon Sep 17 00:00:00 2001 From: Surgupta Date: Fri, 27 Sep 2024 12:59:16 -0700 Subject: [PATCH 09/16] Add filename in constants --- src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs b/src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs index c8a10110d..e97209230 100644 --- a/src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs +++ b/src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs @@ -1,4 +1,5 @@ -using Microsoft.Azure.WebJobs.Script; +using Azure.Functions.Cli.Common; +using Microsoft.Azure.WebJobs.Script; using Microsoft.Extensions.Configuration; using System; using System.Collections.Generic; @@ -12,7 +13,7 @@ internal class ArtifactsConfigurationBuilder : IConfigureBuilder Date: Fri, 27 Sep 2024 13:00:22 -0700 Subject: [PATCH 10/16] Remove artifactsjson --- src/Azure.Functions.Cli/Azure.Functions.Cli.csproj | 3 --- src/Azure.Functions.Cli/artifactsconfig.json | 3 --- 2 files changed, 6 deletions(-) delete mode 100644 src/Azure.Functions.Cli/artifactsconfig.json diff --git a/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj b/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj index 746ad4d7f..6eac661ac 100644 --- a/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj +++ b/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj @@ -269,9 +269,6 @@ tools\python\packapp\__main__.py Always - - Always - diff --git a/src/Azure.Functions.Cli/artifactsconfig.json b/src/Azure.Functions.Cli/artifactsconfig.json deleted file mode 100644 index d41294a32..000000000 --- a/src/Azure.Functions.Cli/artifactsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "minifiedVersion" : true -} \ No newline at end of file From 6cae371a6da52a92afd31e0239bb8e240d97e0af Mon Sep 17 00:00:00 2001 From: Surgupta Date: Fri, 27 Sep 2024 20:48:31 -0700 Subject: [PATCH 11/16] PR feedback --- .../Actions/HostActions/StartHostAction.cs | 15 ++++++--------- test/Azure.Functions.Cli.Tests/E2E/StartTests.cs | 8 ++++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs b/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs index e8bb3b90c..4028eb924 100644 --- a/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs +++ b/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs @@ -498,11 +498,9 @@ private async Task ShouldExitAfterDeterminingHostRuntime(bool isVerbose) { ThrowIfInProc(); } - else - { - var isNet8InProcSpecified = string.Equals(HostRuntime, DotnetConstants.InProc8HostRuntime, StringComparison.OrdinalIgnoreCase); - StartHostAsChildProcess(isNet8InProcSpecified); - } + + var isNet8InProcSpecified = string.Equals(HostRuntime, DotnetConstants.InProc8HostRuntime, StringComparison.OrdinalIgnoreCase); + StartHostAsChildProcess(isNet8InProcSpecified); return true; } @@ -526,10 +524,9 @@ private async Task ShouldExitAfterDeterminingHostRuntime(bool isVerbose) { ThrowIfInProc(); } - else - { - StartHostAsChildProcess(shouldNet8InProcBeLaunched); - } + + StartHostAsChildProcess(shouldNet8InProcBeLaunched); + return true; } diff --git a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs index 510b9e0ae..ebf6f81da 100644 --- a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs +++ b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs @@ -454,10 +454,10 @@ await CliTester.Run(new RunConfiguration { using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { - await Task.Delay(TimeSpan.FromSeconds(5)); + await Task.Delay(TimeSpan.FromSeconds(2)); } }, - CommandTimeout = TimeSpan.FromSeconds(300), + CommandTimeout = TimeSpan.FromSeconds(100), }, _output); } @@ -479,10 +479,10 @@ await CliTester.Run(new RunConfiguration using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { - await Task.Delay(TimeSpan.FromSeconds(5)); + await Task.Delay(TimeSpan.FromSeconds(2)); } }, - CommandTimeout = TimeSpan.FromSeconds(300), + CommandTimeout = TimeSpan.FromSeconds(100), }, _output); } [Fact] From ee76d64c0dfe2cf97d82574e66780bd38c55230c Mon Sep 17 00:00:00 2001 From: Surgupta Date: Sat, 28 Sep 2024 11:57:00 -0700 Subject: [PATCH 12/16] empty line fix --- test/Azure.Functions.Cli.Tests/E2E/StartTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs index ebf6f81da..8b663d629 100644 --- a/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs +++ b/test/Azure.Functions.Cli.Tests/E2E/StartTests.cs @@ -457,7 +457,7 @@ await CliTester.Run(new RunConfiguration await Task.Delay(TimeSpan.FromSeconds(2)); } }, - CommandTimeout = TimeSpan.FromSeconds(100), + CommandTimeout = TimeSpan.FromSeconds(300), }, _output); } @@ -476,7 +476,6 @@ await CliTester.Run(new RunConfiguration ErrorContains = ["Failed to locate the inproc6 model host at"], Test = async (workingDir, p) => { - using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7073") }) { await Task.Delay(TimeSpan.FromSeconds(2)); @@ -485,6 +484,7 @@ await CliTester.Run(new RunConfiguration CommandTimeout = TimeSpan.FromSeconds(100), }, _output); } + [Fact] public async Task dont_start_inproc6_specified_runtime_for_dotnet_isolated() { From 412fc93dc4d309edbea128efc1b0598517b9927e Mon Sep 17 00:00:00 2001 From: Surgupta Date: Mon, 30 Sep 2024 14:39:30 -0700 Subject: [PATCH 13/16] making config builder inline --- src/Azure.Functions.Cli/Common/Utilities.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Azure.Functions.Cli/Common/Utilities.cs b/src/Azure.Functions.Cli/Common/Utilities.cs index 4694ab677..d9670e698 100644 --- a/src/Azure.Functions.Cli/Common/Utilities.cs +++ b/src/Azure.Functions.Cli/Common/Utilities.cs @@ -266,7 +266,9 @@ internal static IConfigurationRoot BuildHostJsonConfigutation(ScriptApplicationH internal static bool IsMinifiedVersion() { - var config = BuildArtifactsConfiguration(); + IConfigurationBuilder builder = new ConfigurationBuilder(); + builder.AddJsonFile(Constants.ArtifactsConfigFileName, optional: true); + var config = builder.Build(); try { @@ -281,15 +283,5 @@ internal static bool IsMinifiedVersion() catch { } return false; } - - internal static IConfigurationRoot BuildArtifactsConfiguration() - { - var configureBuilder = new ArtifactsConfigurationBuilder(); - var configurationBuilder = new ConfigurationBuilder(); - configureBuilder.Configure(configurationBuilder); - var root = configurationBuilder.Build(); - return root; - } - } } From 98fb231d298088560c4861844ea244d69a4c423e Mon Sep 17 00:00:00 2001 From: Surgupta Date: Mon, 30 Sep 2024 14:40:33 -0700 Subject: [PATCH 14/16] Method name update --- .../Actions/HostActions/StartHostAction.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs b/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs index 4028eb924..d8f955710 100644 --- a/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs +++ b/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs @@ -496,7 +496,7 @@ private async Task ShouldExitAfterDeterminingHostRuntime(bool isVerbose) { if (Utilities.IsMinifiedVersion()) { - ThrowIfInProc(); + ThrowForInProc(); } var isNet8InProcSpecified = string.Equals(HostRuntime, DotnetConstants.InProc8HostRuntime, StringComparison.OrdinalIgnoreCase); @@ -522,7 +522,7 @@ private async Task ShouldExitAfterDeterminingHostRuntime(bool isVerbose) if (Utilities.IsMinifiedVersion()) { - ThrowIfInProc(); + ThrowForInProc(); } StartHostAsChildProcess(shouldNet8InProcBeLaunched); @@ -583,7 +583,7 @@ private async Task ValidateHostRuntime(bool isInProc, bool isVerbose) throw new CliException($"Invalid host runtime '{HostRuntime}'. Valid values are 'default', '{DotnetConstants.InProc8HostRuntime}', '{DotnetConstants.InProc6HostRuntime}'."); } - private void ThrowIfInProc() + private void ThrowForInProc() { throw new CliException($"This version of the Azure Functions Core Tools requires your project to reference version {DotnetConstants.InProcFunctionsMinSdkVersion} or later of {DotnetConstants.InProcFunctionsSdk}. Please update to the latest version. For more information, see: {DotnetConstants.InProcFunctionsDocsLink}"); } From ef8ec80a908fdd41afc6bf28791bb2cca4f1b659 Mon Sep 17 00:00:00 2001 From: Surgupta Date: Mon, 30 Sep 2024 15:18:55 -0700 Subject: [PATCH 15/16] Removing artifact builder class --- .../ArtifactsConfigurationBuilder.cs | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs diff --git a/src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs b/src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs deleted file mode 100644 index e97209230..000000000 --- a/src/Azure.Functions.Cli/ArtifactsConfigurationBuilder.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Azure.Functions.Cli.Common; -using Microsoft.Azure.WebJobs.Script; -using Microsoft.Extensions.Configuration; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Azure.Functions.Cli -{ - internal class ArtifactsConfigurationBuilder : IConfigureBuilder - { - public void Configure(IConfigurationBuilder builder) - { - builder.AddJsonFile(Constants.ArtifactsConfigFileName, optional: true); - } - } -} From e8bf35c4eaf2ceea2c35ea06ee5720c8c49ccc3c Mon Sep 17 00:00:00 2001 From: Surgupta Date: Wed, 2 Oct 2024 15:31:48 -0700 Subject: [PATCH 16/16] Updating build to add config file for the minified versions --- build/BuildSteps.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build/BuildSteps.cs b/build/BuildSteps.cs index 5c4d13fe1..480498b59 100644 --- a/build/BuildSteps.cs +++ b/build/BuildSteps.cs @@ -120,6 +120,7 @@ public static void DotnetPublishForZips() if (isMinVersion) { RemoveLanguageWorkers(outputPath); + CreateMinConfigurationFile(outputPath); } // Publish net8 version of the artifact as well. @@ -792,6 +793,13 @@ private static void RemoveLanguageWorkers(string outputPath) } } + private static void CreateMinConfigurationFile(string outputPath) + { + var filePath = Path.Combine(outputPath, "artifactsconfig.json"); + string artifactsJsonContent = "{\"minifiedVersion\": true}"; + File.WriteAllTextAsync(filePath, artifactsJsonContent).GetAwaiter().GetResult(); + } + private static PackageInfo GetLatestPackageInfo(string name, string majorVersion, string source) { string includeAllVersion = !string.IsNullOrWhiteSpace(majorVersion) ? "-AllVersions" : string.Empty;