From bf37f55efd725993a11f861e3f000c6855f5771f Mon Sep 17 00:00:00 2001 From: Shyju Krishnankutty Date: Fri, 27 Sep 2024 16:31:55 -0700 Subject: [PATCH] Updating the artifact name to include "_inproc" suffix (#3849) --- .../ArtifactAssembler.cs | 23 +++++++++++++++++-- .../Program.cs | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Azure.Functions.ArtifactAssembler/ArtifactAssembler.cs b/src/Azure.Functions.ArtifactAssembler/ArtifactAssembler.cs index 2cac8ea31..7cd94c064 100644 --- a/src/Azure.Functions.ArtifactAssembler/ArtifactAssembler.cs +++ b/src/Azure.Functions.ArtifactAssembler/ArtifactAssembler.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using System.Text.RegularExpressions; + namespace Azure.Functions.ArtifactAssembler { internal sealed class ArtifactAssembler @@ -10,6 +12,8 @@ internal sealed class ArtifactAssembler private const string InProc6DirectoryName = "in-proc6"; private const string CoreToolsHostDirectoryName = "host"; private const string OutputArtifactDirectoryName = "coretools-visualstudio"; + private const string _InProcOutputArtifactNameSuffix = "_inproc"; + private const string _coreToolsProductVersionPattern = @"(\d+\.\d+\.\d+)$"; /// /// The artifacts for which we want to pack a custom host with it. @@ -117,6 +121,20 @@ private static async Task MoveArtifactsToStagingDirectoryAndExtractIfNee return destinationDirectory; } + // Gets the product version part from the artifact directory name. + // Example input: Azure.Functions.Cli.min.win-x64.4.0.6353 + // Example output: 4.0.6353 + private static string GetCoreToolsProductVersion(string artifactDirectoryName) + { + var match = Regex.Match(artifactDirectoryName, _coreToolsProductVersionPattern); + if (match.Success) + { + return match.Value; + } + + throw new InvalidOperationException($"The artifact directory name '{artifactDirectoryName}' does not include a core tools product version in the expected format (e.g., '4.0.6353'). Please ensure the directory name follows the correct naming convention."); + } + private async Task CreateVisualStudioCoreToolsAsync() { // Create a directory to store the assembled artifacts. @@ -134,7 +152,8 @@ private async Task CreateVisualStudioCoreToolsAsync() // Create a new directory to store the custom host with in-proc8 and in-proc6 files. var artifactDirName = Path.GetFileName(inProc8ArtifactDirPath); - var consolidatedArtifactDirPath = Path.Combine(customHostTargetArtifactDir, artifactDirName); + var consolidatedArtifactDirName = $"{artifactName}{_InProcOutputArtifactNameSuffix}.{GetCoreToolsProductVersion(artifactDirName)}"; + var consolidatedArtifactDirPath = Path.Combine(customHostTargetArtifactDir, consolidatedArtifactDirName); Directory.CreateDirectory(consolidatedArtifactDirPath); // Copy in-proc8 files @@ -154,7 +173,7 @@ private async Task CreateVisualStudioCoreToolsAsync() await Task.WhenAll(inProc8CopyTask, inProc6CopyTask, coreToolsHostCopyTask); // consolidatedArtifactDirPath now contains custom core-tools host, in-proc6 and in-proc8 sub directories. Create a zip file. - var zipPath = Path.Combine(customHostTargetArtifactDir, $"{artifactDirName}.zip"); + var zipPath = Path.Combine(customHostTargetArtifactDir, $"{consolidatedArtifactDirName}.zip"); await Task.Run(() => FileUtilities.CreateZipFile(consolidatedArtifactDirPath, zipPath)); Console.WriteLine($"Successfully created target runtime zip at: {zipPath}"); diff --git a/src/Azure.Functions.ArtifactAssembler/Program.cs b/src/Azure.Functions.ArtifactAssembler/Program.cs index 8f81e7b73..aa8821895 100644 --- a/src/Azure.Functions.ArtifactAssembler/Program.cs +++ b/src/Azure.Functions.ArtifactAssembler/Program.cs @@ -9,7 +9,7 @@ static async Task Main(string[] args) { try { - var currentWorkingDirectory = Environment.CurrentDirectory; + var currentWorkingDirectory = Environment.CurrentDirectory; var artifactAssembler = new ArtifactAssembler(currentWorkingDirectory); await artifactAssembler.AssembleArtifactsAsync();