Skip to content

Commit 48853da

Browse files
[release/6.x] Release tool updates (#1483)
- Change NugetLayoutWorker to only consider files under the packages directory - Add checksum file to ChecksumAssets in publish manifest - Add unprocessed files to BlobAssets in publish manifest - Add --dry-run option to run tool without publishing Co-authored-by: Justin Anderson <jander@microsoft.com>
1 parent ab5ed30 commit 48853da

File tree

10 files changed

+86
-21
lines changed

10 files changed

+86
-21
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.IO;
2+
3+
namespace ReleaseTool.Core
4+
{
5+
public sealed class BlobLayoutWorker : PassThroughLayoutWorker
6+
{
7+
public BlobLayoutWorker(string stagingPath) : base(
8+
shouldHandleFileFunc: static _ => true,
9+
getRelativePublishPathFromFileFunc: static file => Helpers.GetDefaultPathForFileCategory(file, FileClass.Blob),
10+
getMetadataForFileFunc: static file => Helpers.GetDefaultFileMetadata(file, FileClass.Blob),
11+
stagingPath
12+
){}
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.IO;
2+
3+
namespace ReleaseTool.Core
4+
{
5+
public sealed class ChecksumLayoutWorker : PassThroughLayoutWorker
6+
{
7+
public ChecksumLayoutWorker(string stagingPath) : base(
8+
shouldHandleFileFunc: static file => file.Extension == ".sha512",
9+
getRelativePublishPathFromFileFunc: static file => Helpers.GetDefaultPathForFileCategory(file, FileClass.Checksum),
10+
getMetadataForFileFunc: static file => Helpers.GetDefaultFileMetadata(file, FileClass.Checksum),
11+
stagingPath
12+
){}
13+
}
14+
}

eng/release/DiagnosticsReleaseTool/Common/NugetLayoutWorker.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
using System;
12
using System.IO;
23

34
namespace ReleaseTool.Core
45
{
56
public sealed class NugetLayoutWorker : PassThroughLayoutWorker
67
{
7-
public NugetLayoutWorker(string stagingPath) : base(
8-
shouldHandleFileFunc: static file => file.Extension == ".nupkg" && !file.Name.EndsWith(".symbols.nupkg"),
8+
public NugetLayoutWorker(string stagingPath, Func<FileInfo, bool> additionalFileConstraint = null) : base(
9+
shouldHandleFileFunc: file => file.Extension == ".nupkg" && (null == additionalFileConstraint || additionalFileConstraint(file)),
910
getRelativePublishPathFromFileFunc: static file => Helpers.GetDefaultPathForFileCategory(file, FileClass.Nuget),
1011
getMetadataForFileFunc: static file => Helpers.GetDefaultFileMetadata(file, FileClass.Nuget),
1112
stagingPath
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using ReleaseTool.Core;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
namespace ReleaseTool.Core
8+
{
9+
internal class SkipPublisher : IPublisher
10+
{
11+
private readonly HashSet<string> _relativeOutputPaths = new(StringComparer.OrdinalIgnoreCase);
12+
13+
public void Dispose()
14+
{
15+
}
16+
17+
public Task<string> PublishFileAsync(FileMapping fileData, CancellationToken ct)
18+
{
19+
if (!_relativeOutputPaths.Add(fileData.RelativeOutputPath))
20+
{
21+
throw new InvalidOperationException($"File {fileData.LocalSourcePath} was already published to {fileData.RelativeOutputPath}.");
22+
}
23+
24+
return Task.FromResult(fileData.RelativeOutputPath);
25+
}
26+
}
27+
}

eng/release/DiagnosticsReleaseTool/Core/FileMetadata.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public enum FileClass
77
Blob,
88
Nuget,
99
SymbolPackage,
10+
Checksum,
1011
Unknown
1112
}
1213

@@ -66,6 +67,7 @@ public FileMetadata(FileClass fileClass, string assetCategory, bool shouldPublis
6667
FileClass.Blob => "BlobAssets",
6768
FileClass.Nuget => "NugetAssets",
6869
FileClass.SymbolPackage => "SymbolNugetAssets",
70+
FileClass.Checksum => "ChecksumAssets",
6971
FileClass.Unknown => "UnknownAssets",
7072
_ => "UnknownAssets"
7173
};

eng/release/DiagnosticsReleaseTool/Core/Release.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,6 @@ private async Task<int> LayoutFilesAsync(CancellationToken ct)
224224

225225
if (layoutResult.Status == LayoutResultStatus.FileHandled)
226226
{
227-
if (isProcessed)
228-
{
229-
// TODO: Might be worth to relax this limitation. It just needs to turn the
230-
// source -> fileData relationship to something like source -> List<FileData>).
231-
_logger.LogError("[{buildFilePath}, {worker}] File {file} is getting handled by several workers.", file.FullName, worker.GetType().FullName, file);
232-
return -1;
233-
}
234-
235227
isProcessed = true;
236228

237229
(FileMapping fileMap, FileMetadata fileMetadata)[] layoutResultArray = layoutResult.LayoutDataEnumerable.ToArray();
@@ -261,6 +253,9 @@ private async Task<int> LayoutFilesAsync(CancellationToken ct)
261253
_logger.LogTrace("[{buildFilePath}, {worker}, {layoutInd}: {srcPath} -> {dstPath}, {fileMetadata}] adding layout to release data.", file.FullName, worker.GetType().FullName, i, srcPath, dstPath, fileMetadata);
262254
_filesToRelease.Add(new FileReleaseData(fileMap, fileMetadata));
263255
}
256+
257+
// Skip remaining layout workers
258+
break;
264259
}
265260
}
266261

eng/release/DiagnosticsReleaseTool/DarcHelpers.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,10 @@ internal DirectoryInfo GetShippingDirectoryForSingleProjectVariants(IEnumerable<
9696
return new DirectoryInfo(matchingProducts.First().GetProperty("fileshare").GetString());
9797
}
9898
}
99+
100+
internal static bool IsNuGetPackage(FileInfo file)
101+
{
102+
return file.Extension == ".nupkg" && file.Directory.Name == "packages";
103+
}
99104
}
100105
}

eng/release/DiagnosticsReleaseTool/DiagnosticsReleaseCommandLine.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public static Command PrepareRelease() =>
2727
name: "prepare-release",
2828
description: "Given a darc drop, generates validated manifests and layouts to initiate a tool release.")
2929
{
30-
CommandHandler.Create<Config, bool, CancellationToken>(DiagnosticsReleaseRunner.PrepareRelease),
30+
CommandHandler.Create<Config, bool, bool, CancellationToken>(DiagnosticsReleaseRunner.PrepareRelease),
3131
// Inputs
3232
InputDropPathOption(), ToolManifestPathOption(), ReleaseNameOption(),
3333
// Toggles
34-
ToolManifestVerificationOption(), DiagnosticLoggingOption(),
34+
ToolManifestVerificationOption(), DiagnosticLoggingOption(), DryRunOption(),
3535
// Outputs
3636
StagingPathOption(), AzureStorageAccountNameOption(), AzureStorageAccountKeyOption(), AzureStorageContainerNameOption(), AzureStorageSasExpirationOption()
3737
};
@@ -42,6 +42,12 @@ private static Option<bool> DiagnosticLoggingOption() =>
4242
description: "Enables diagnostic logging",
4343
getDefaultValue: () => false);
4444

45+
private static Option<bool> DryRunOption() =>
46+
new Option<bool>(
47+
aliases: new[] { "--dry-run" },
48+
description: "Stages files and generates manifest, but does not publish.",
49+
getDefaultValue: () => false);
50+
4551
private static Option ToolManifestPathOption() =>
4652
new Option<FileInfo>(
4753
aliases: new[] { "--tool-manifest", "-t" },

eng/release/DiagnosticsReleaseTool/DiagnosticsReleaseRunner.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88

99
using Microsoft.Extensions.Configuration;
1010
using Microsoft.Extensions.Logging;
11-
using System;
1211

1312
namespace DiagnosticsReleaseTool.Impl
1413
{
1514
internal class DiagnosticsReleaseRunner
1615
{
1716
internal const string ManifestName = "publishManifest.json";
1817

19-
internal async static Task<int> PrepareRelease(Config releaseConfig, bool verbose, CancellationToken ct)
18+
internal async static Task<int> PrepareRelease(Config releaseConfig, bool verbose, bool dryRun, CancellationToken ct)
2019
{
2120
// TODO: This will throw if invalid drop path is given.
2221
var darcLayoutHelper = new DarcHelpers(releaseConfig.DropPath);
@@ -26,11 +25,12 @@ internal async static Task<int> PrepareRelease(Config releaseConfig, bool verbos
2625
var layoutWorkerList = new List<ILayoutWorker>
2726
{
2827
// TODO: We may want to inject a logger.
29-
new NugetLayoutWorker(stagingPath: releaseConfig.StagingDirectory.FullName),
28+
new NugetLayoutWorker(stagingPath: releaseConfig.StagingDirectory.FullName, DarcHelpers.IsNuGetPackage),
3029
new SymbolPackageLayoutWorker(stagingPath: releaseConfig.StagingDirectory.FullName),
31-
new SkipLayoutWorker(
32-
shouldHandleFileFunc: DiagnosticsRepoHelpers.IsDockerUtilityFile
33-
)
30+
new ChecksumLayoutWorker(stagingPath: releaseConfig.StagingDirectory.FullName),
31+
new SkipLayoutWorker(shouldHandleFileFunc: DiagnosticsRepoHelpers.IsDockerUtilityFile),
32+
// This should always be last since it will accept any file
33+
new BlobLayoutWorker(stagingPath: releaseConfig.StagingDirectory.FullName)
3434
};
3535

3636
var verifierList = new List<IReleaseVerifier> { };
@@ -46,7 +46,9 @@ internal async static Task<int> PrepareRelease(Config releaseConfig, bool verbos
4646
DirectoryInfo basePublishDirectory = darcLayoutHelper.GetShippingDirectoryForSingleProjectVariants(DiagnosticsRepoHelpers.ProductNames);
4747
string publishManifestPath = Path.Combine(releaseConfig.StagingDirectory.FullName, ManifestName);
4848

49-
IPublisher releasePublisher = new AzureBlobBublisher(releaseConfig.AccountName, releaseConfig.AccountKey, releaseConfig.ContainerName, releaseConfig.ReleaseName, releaseConfig.SasValidDays, logger);
49+
IPublisher releasePublisher = dryRun ?
50+
new SkipPublisher() :
51+
new AzureBlobBublisher(releaseConfig.AccountName, releaseConfig.AccountKey, releaseConfig.ContainerName, releaseConfig.ReleaseName, releaseConfig.SasValidDays, logger);
5052
IManifestGenerator manifestGenerator = new DiagnosticsManifestGenerator(releaseMetadata, releaseConfig.ToolManifest, logger);
5153

5254
using var diagnosticsRelease = new Release(

eng/release/DiagnosticsReleaseTool/DiagnosticsRepoHelpers.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ public static class DiagnosticsRepoHelpers
77
public static readonly string[] ProductNames = new []{ "dotnet-monitor", "dotnet-dotnet-monitor" };
88
public static readonly string[] RepositoryUrls = new [] { "https://github.com/dotnet/dotnet-monitor", "https://dev.azure.com/dnceng/internal/_git/dotnet-dotnet-monitor" };
99
internal static bool IsDockerUtilityFile(FileInfo arg) =>
10-
arg.FullName.EndsWith(".nupkg.sha512")
11-
|| arg.FullName.EndsWith(".nupkg.version")
10+
arg.FullName.EndsWith(".nupkg.version")
1211
|| arg.FullName.EndsWith(".nupkg.buildversion");
1312
}
1413
}

0 commit comments

Comments
 (0)