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

Core tools changes to support .NET8 in-proc #3680

Merged
merged 17 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
96 changes: 72 additions & 24 deletions build/BuildSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,31 @@ public static void DotnetPack()
Shell.Run("dotnet", $"pack {Settings.SrcProjectPath} " +
$"/p:BuildNumber=\"{Settings.BuildNumber}\" " +
$"/p:NoWorkers=\"true\" " +
$"/p:TargetFramework=net6.0 " + // without TargetFramework, the generated nuspec has incorrect path for the copy files operation.
$"/p:CommitHash=\"{Settings.CommitId}\" " +
(string.IsNullOrEmpty(Settings.IntegrationBuildNumber) ? string.Empty : $"/p:IntegrationBuildNumber=\"{Settings.IntegrationBuildNumber}\" ") +
$"-o {outputPath} -c Release --no-build");
$"-o {outputPath} -c Release ");
kshyju marked this conversation as resolved.
Show resolved Hide resolved
}

public static void DotnetPublishForZips()
{
foreach (var runtime in Settings.TargetRuntimes)
{
var isMinVersion = runtime.StartsWith(Settings.MinifiedVersionPrefix);
var outputPath = Path.Combine(Settings.OutputDir, runtime);
var rid = GetRuntimeId(runtime);
Shell.Run("dotnet", $"publish {Settings.ProjectFile} " +
$"/p:BuildNumber=\"{Settings.BuildNumber}\" " +
$"/p:CommitHash=\"{Settings.CommitId}\" " +
(string.IsNullOrEmpty(Settings.IntegrationBuildNumber) ? string.Empty : $"/p:IntegrationBuildNumber=\"{Settings.IntegrationBuildNumber}\" ") +
$"-o {outputPath} -c Release " +
(string.IsNullOrEmpty(rid) ? string.Empty : $" -r {rid}"));

if (runtime.StartsWith(Settings.MinifiedVersionPrefix))

ExecuteDotnetPublish(outputPath, rid, "net6.0", skipLaunchingNet8ChildProcess: isMinVersion);

if (isMinVersion)
{
RemoveLanguageWorkers(outputPath);
}

// Publish net8 version of the artifact as well.
var outputPathNet8 = BuildNet8ArtifactPath(runtime);
ExecuteDotnetPublish(outputPathNet8, rid, "net8.0", skipLaunchingNet8ChildProcess: true);
RemoveLanguageWorkers(outputPathNet8);
kshyju marked this conversation as resolved.
Show resolved Hide resolved
}

if (!string.IsNullOrEmpty(Settings.IntegrationBuildNumber) && (_integrationManifest != null))
Expand All @@ -131,6 +134,22 @@ public static void DotnetPublishForZips()
}
}

private static string BuildNet8ArtifactPath(string runtime)
{
return Path.Combine(Settings.OutputDir, runtime + "_net8.0");
}

private static void ExecuteDotnetPublish(string outputPath, string rid, string targetFramework, bool skipLaunchingNet8ChildProcess)
{
Shell.Run("dotnet", $"publish {Settings.ProjectFile} " +
$"/p:BuildNumber=\"{Settings.BuildNumber}\" " +
$"/p:SkipInProcessHost=\"{skipLaunchingNet8ChildProcess}\" " +
$"/p:CommitHash=\"{Settings.CommitId}\" " +
(string.IsNullOrEmpty(Settings.IntegrationBuildNumber) ? string.Empty : $"/p:IntegrationBuildNumber=\"{Settings.IntegrationBuildNumber}\" ") +
$"-o {outputPath} -c Release -f {targetFramework} --self-contained" +
(string.IsNullOrEmpty(rid) ? string.Empty : $" -r {rid}"));
}

public static void FilterPowershellRuntimes()
{
var minifiedRuntimes = Settings.TargetRuntimes.Where(r => r.StartsWith(Settings.MinifiedVersionPrefix));
Expand Down Expand Up @@ -314,7 +333,7 @@ public static void Test()

Environment.SetEnvironmentVariable("DURABLE_FUNCTION_PATH", Settings.DurableFolder);

Shell.Run("dotnet", $"test {Settings.TestProjectFile} --logger trx");
Shell.Run("dotnet", $"test {Settings.TestProjectFile} -f net6.0 --logger trx");
}

public static void CopyBinariesToSign()
Expand Down Expand Up @@ -371,7 +390,7 @@ public static void CopyBinariesToSign()

// These assemblies are currently signed, but with an invalid root cert.
// Until that is resolved, we are explicity signing the AppService.Middleware packages

unSignedBinaries = unSignedBinaries.Concat(allFiles
.Where(f => f.Contains("Microsoft.Azure.AppService.Middleware") || f.Contains("Microsoft.Azure.AppService.Proxy"))).ToList();

Expand All @@ -384,6 +403,8 @@ public static void CopyBinariesToSign()

public static void TestPreSignedArtifacts()
{
var filterExtensionsSignSet = new HashSet<string>(Settings.SignInfo.FilterExtensionsSign);

foreach (var supportedRuntime in Settings.SignInfo.RuntimesToSign)
{
if (supportedRuntime.StartsWith("osx"))
Expand All @@ -397,20 +418,30 @@ public static void TestPreSignedArtifacts()
Directory.CreateDirectory(targetDir);
FileHelpers.RecursiveCopy(sourceDir, targetDir);

var toSignPaths = Settings.SignInfo.authentiCodeBinaries.Select(el => Path.Combine(targetDir, el));
var toSignThirdPartyPaths = Settings.SignInfo.thirdPartyBinaries.Select(el => Path.Combine(targetDir, el));
var inProc8Directory = Path.Combine(targetDir, "in-proc8");
var inProc8DirectoryExists = Directory.Exists(inProc8Directory);

var toSignPathsForInProc8 = inProc8DirectoryExists
? Settings.SignInfo.authentiCodeBinaries.Select(el => Path.Combine(inProc8Directory, el))
: Enumerable.Empty<string>();
var toSignPaths = Settings.SignInfo.authentiCodeBinaries.Select(el => Path.Combine(targetDir, el)).Concat(toSignPathsForInProc8);

var toSignThirdPartyPathsForInProc8 = inProc8DirectoryExists
? Settings.SignInfo.thirdPartyBinaries.Select(el => Path.Combine(inProc8Directory, el))
: Enumerable.Empty<string>();
var toSignThirdPartyPaths = Settings.SignInfo.thirdPartyBinaries.Select(el => Path.Combine(targetDir, el)).Concat(toSignThirdPartyPathsForInProc8);

var unSignedFiles = FileHelpers.GetAllFilesFromFilesAndDirs(FileHelpers.ExpandFileWildCardEntries(toSignPaths))
.Where(file => !Settings.SignInfo.FilterExtensionsSign.Any(ext => file.EndsWith(ext))).ToList();
.Where(file => !filterExtensionsSignSet.Any(ext => file.EndsWith(ext))).ToList();

unSignedFiles.AddRange(FileHelpers.GetAllFilesFromFilesAndDirs(FileHelpers.ExpandFileWildCardEntries(toSignThirdPartyPaths))
.Where(file => !Settings.SignInfo.FilterExtensionsSign.Any(ext => file.EndsWith(ext))));
.Where(file => !filterExtensionsSignSet.Any(ext => file.EndsWith(ext))));

unSignedFiles.ForEach(filePath => File.Delete(filePath));

var unSignedPackages = GetUnsignedBinaries(targetDir);
if (unSignedPackages.Count() != 0)
{

var missingSignature = string.Join($",{Environment.NewLine}", unSignedPackages);
ColoredConsole.Error.WriteLine($"This files are missing valid signatures: {Environment.NewLine}{missingSignature}");
throw new Exception($"sigcheck.exe test failed. Following files are unsigned: {Environment.NewLine}{missingSignature}");
Expand Down Expand Up @@ -498,31 +529,47 @@ public static List<string> GetUnsignedBinaries(string targetDir)
return unSignedPackages;
}

private static void CreateZipFromArtifact(string artifactSourcePath, string zipPath)
{
if (!Directory.Exists(artifactSourcePath))
{
return;
kshyju marked this conversation as resolved.
Show resolved Hide resolved
}

ColoredConsole.WriteLine($"Creating {zipPath}");
ZipFile.CreateFromDirectory(artifactSourcePath, zipPath, CompressionLevel.Optimal, includeBaseDirectory: false);
}

public static void Zip()
{
var version = CurrentVersion;

foreach (var runtime in Settings.TargetRuntimes)
{
var path = Path.Combine(Settings.OutputDir, runtime);
var isMinVersion = runtime.StartsWith(Settings.MinifiedVersionPrefix);
var artifactPath = Path.Combine(Settings.OutputDir, runtime);

var zipPath = Path.Combine(Settings.OutputDir, $"Azure.Functions.Cli.{runtime}.{version}.zip");
ColoredConsole.WriteLine($"Creating {zipPath}");
ZipFile.CreateFromDirectory(path, zipPath, CompressionLevel.Optimal, includeBaseDirectory: false);
CreateZipFromArtifact(artifactPath, zipPath);

// Zip the .net8 version as well.
var net8Path = BuildNet8ArtifactPath(runtime);
var net8ZipPath = zipPath.Replace(".zip", "_net8.0.zip");
CreateZipFromArtifact(net8Path, net8ZipPath);


// We leave the folders beginning with 'win' to generate the .msi files. They will be deleted in
// the ./generateMsiFiles.ps1 script
if (!runtime.StartsWith("win"))
{
try
{
Directory.Delete(path, recursive: true);
Directory.Delete(artifactPath, recursive: true);
}
catch
catch (Exception ex)
{
ColoredConsole.Error.WriteLine($"Error deleting {path}");
ColoredConsole.Error.WriteLine($"Error deleting {artifactPath}. Exception: {ex}");
}

}

ColoredConsole.WriteLine();
Expand Down Expand Up @@ -576,9 +623,10 @@ public static void DotnetPublishForNupkg()
Shell.Run("dotnet", $"publish {Settings.ProjectFile} " +
$"/p:BuildNumber=\"{Settings.BuildNumber}\" " +
$"/p:NoWorkers=\"true\" " +
$"/p:TargetFramework=net6.0 " +
$"/p:CommitHash=\"{Settings.CommitId}\" " +
(string.IsNullOrEmpty(Settings.IntegrationBuildNumber) ? string.Empty : $"/p:IntegrationBuildNumber=\"{Settings.IntegrationBuildNumber}\" ") +
$"-c Release");
$"-c Release -f net6.0");
}

public static void GenerateSBOMManifestForNupkg()
Expand Down
2 changes: 1 addition & 1 deletion build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void Main(string[] args)
.Then(Test, skip: args.Contains("--codeql"))
.Then(GenerateSBOMManifestForZips, skip: !args.Contains("--generateSBOM"))
.Then(Zip)
.Then(DotnetPublishForNupkg)
//.Then(DotnetPublishForNupkg) // DotnetPack step now does build and pack.
.Then(GenerateSBOMManifestForNupkg, skip: !args.Contains("--generateSBOM"))
kshyju marked this conversation as resolved.
Show resolved Hide resolved
.Then(DotnetPack)
.Then(DeleteSBOMTelemetryFolder, skip: !args.Contains("--generateSBOM"))
Expand Down
8 changes: 4 additions & 4 deletions build/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ private static string config(string @default = null, [CallerMemberName] string k
: value;
}

public const string DotnetIsolatedItemTemplatesVersion = "4.0.2945";
public const string DotnetIsolatedProjectTemplatesVersion = "4.0.2945";
public const string DotnetItemTemplatesVersion = "4.0.2945";
public const string DotnetProjectTemplatesVersion = "4.0.2945";
public const string DotnetIsolatedItemTemplatesVersion = "4.0.3038";
public const string DotnetIsolatedProjectTemplatesVersion = "4.0.3038";
public const string DotnetItemTemplatesVersion = "4.0.3038";
public const string DotnetProjectTemplatesVersion = "4.0.3038";
public const string TemplateJsonVersion = "3.1.1648";

public static readonly string SBOMManifestToolPath = Path.GetFullPath("../ManifestTool/Microsoft.ManifestTool.dll");
Expand Down
2 changes: 1 addition & 1 deletion build/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static void Run(string program, string arguments, bool streamOutput = tru

if (exitcode != 0)
{
throw new Exception($"{program} Exit Code == {exitcode}");
throw new Exception($"{program} {arguments} Exit Code == {exitcode}");
}
}

Expand Down
5 changes: 5 additions & 0 deletions pipelineUtilities.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ $DotnetSDKVersionRequirements = @{
MinimalPatch = '417'
DefaultPatch = '417'
}

'8.0' = @{
MinimalPatch = '204'
DefaultPatch = '204'
}
}

function AddLocalDotnetDirPath {
Expand Down
Loading
Loading