Skip to content

Commit

Permalink
Updating the artifact name to include "_inproc" suffix (#3849)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyju authored and fabiocav committed Nov 6, 2024
1 parent 8e51cb0 commit bf37f55
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/Azure.Functions.ArtifactAssembler/ArtifactAssembler.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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+)$";

/// <summary>
/// The artifacts for which we want to pack a custom host with it.
Expand Down Expand Up @@ -117,6 +121,20 @@ private static async Task<string> 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.
Expand All @@ -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
Expand All @@ -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}");

Expand Down
2 changes: 1 addition & 1 deletion src/Azure.Functions.ArtifactAssembler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static async Task<int> Main(string[] args)
{
try
{
var currentWorkingDirectory = Environment.CurrentDirectory;
var currentWorkingDirectory = Environment.CurrentDirectory;
var artifactAssembler = new ArtifactAssembler(currentWorkingDirectory);
await artifactAssembler.AssembleArtifactsAsync();

Expand Down

0 comments on commit bf37f55

Please sign in to comment.