Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating coretools to detect unsupported inproc6 sdk scenario #3825

Merged
merged 18 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,14 @@ private async Task<bool> ShouldExitAfterDeterminingHostRuntime(bool isVerbose)

if (!string.Equals(HostRuntime, "default", StringComparison.OrdinalIgnoreCase))
{
if (Utilities.IsMinifiedVersion())
{
ThrowForInProc();
}

var isNet8InProcSpecified = string.Equals(HostRuntime, DotnetConstants.InProc8HostRuntime, StringComparison.OrdinalIgnoreCase);
StartHostAsChildProcess(isNet8InProcSpecified);
surgupta-msft marked this conversation as resolved.
Show resolved Hide resolved

return true;
}
}
Expand All @@ -514,7 +520,13 @@ private async Task<bool> ShouldExitAfterDeterminingHostRuntime(bool isVerbose)
PrintVerboseForHostSelection(isVerbose, DotnetConstants.InProc6HostRuntime);
}

if (Utilities.IsMinifiedVersion())
{
ThrowForInProc();
}

StartHostAsChildProcess(shouldNet8InProcBeLaunched);
surgupta-msft marked this conversation as resolved.
Show resolved Hide resolved

return true;

}
Expand Down Expand Up @@ -571,6 +583,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 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}");
}
private void PrintVerboseForHostSelection(bool isVerbose, string hostRuntime)
{
if (isVerbose)
Expand Down
2 changes: 2 additions & 0 deletions src/Azure.Functions.Cli/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions src/Azure.Functions.Cli/Common/DotnetConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
20 changes: 20 additions & 0 deletions src/Azure.Functions.Cli/Common/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,25 @@ internal static IConfigurationRoot BuildHostJsonConfigutation(ScriptApplicationH
var configuration = builder.Build();
return configuration;
}

internal static bool IsMinifiedVersion()
{
IConfigurationBuilder builder = new ConfigurationBuilder();
builder.AddJsonFile(Constants.ArtifactsConfigFileName, optional: true);
var config = builder.Build();

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;
}
}
}
25 changes: 0 additions & 25 deletions test/Azure.Functions.Cli.Tests/E2E/StartTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -677,31 +677,6 @@ await CliTester.Run(new RunConfiguration
}, _output);
}

[Fact]
public async Task start_dotnet_isolated_inproc_with_specifying_runtime()
surgupta-msft marked this conversation as resolved.
Show resolved Hide resolved
{
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,
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));
}
},
CommandTimeout = TimeSpan.FromSeconds(100),
}, _output);
}


[Fact]
public async Task start_dotnet_isolated_csharp_with_oop_host_with_runtime_specified()
{
Expand Down
16 changes: 16 additions & 0 deletions test/Azure.Functions.Cli.Tests/UtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}