Browse Source

Parameters fixes

pull/12072/head
Max Katz 3 years ago
parent
commit
65e29787dd
  1. 30
      .nuke/build.schema.json
  2. 19
      nukebuild/ApiDiffValidation.cs
  3. 21
      nukebuild/BuildParameters.cs

30
.nuke/build.schema.json

@ -6,21 +6,18 @@
"build": { "build": {
"type": "object", "type": "object",
"properties": { "properties": {
"ApiValidationBaseline": { "api-baseline": {
"type": "string", "type": "string"
"description": "api-baseline"
}, },
"Configuration": { "configuration": {
"type": "string", "type": "string"
"description": "configuration"
}, },
"Continue": { "Continue": {
"type": "boolean", "type": "boolean",
"description": "Indicates to continue a previously failed build attempt" "description": "Indicates to continue a previously failed build attempt"
}, },
"ForceNugetVersion": { "force-nuget-version": {
"type": "string", "type": "string"
"description": "force-nuget-version"
}, },
"Help": { "Help": {
"type": "boolean", "type": "boolean",
@ -98,13 +95,11 @@
] ]
} }
}, },
"SkipPreviewer": { "skip-previewer": {
"type": "boolean", "type": "boolean"
"description": "skip-previewer"
}, },
"SkipTests": { "skip-tests": {
"type": "boolean", "type": "boolean"
"description": "skip-tests"
}, },
"Target": { "Target": {
"type": "array", "type": "array",
@ -134,9 +129,8 @@
] ]
} }
}, },
"UpdateApiValidationSuppression": { "update-api-suppression": {
"type": "boolean", "type": "boolean"
"description": "update-api-suppression"
}, },
"Verbosity": { "Verbosity": {
"type": "string", "type": "string",

19
nukebuild/ApiDiffValidation.cs

@ -10,8 +10,10 @@ using Nuke.Common.Tooling;
public static class ApiDiffValidation public static class ApiDiffValidation
{ {
private static readonly HttpClient s_httpClient = new();
public static async Task ValidatePackage( public static async Task ValidatePackage(
Tool apiCompatTool, string packagePath, Version baselineVersion, Tool apiCompatTool, string packagePath, string baselineVersion,
string suppressionFilesFolder, bool updateSuppressionFile) string suppressionFilesFolder, bool updateSuppressionFile)
{ {
if (baselineVersion is null) if (baselineVersion is null)
@ -25,7 +27,7 @@ public static class ApiDiffValidation
Directory.CreateDirectory(suppressionFilesFolder!); Directory.CreateDirectory(suppressionFilesFolder!);
} }
using (var baselineStream = await DownloadBaselinePackage(packagePath, baselineVersion)) await using (var baselineStream = await DownloadBaselinePackage(packagePath, baselineVersion))
using (var target = new ZipArchive(File.Open(packagePath, FileMode.Open, FileAccess.Read), ZipArchiveMode.Read)) using (var target = new ZipArchive(File.Open(packagePath, FileMode.Open, FileAccess.Read), ZipArchiveMode.Read))
using (var baseline = new ZipArchive(baselineStream, ZipArchiveMode.Read)) using (var baseline = new ZipArchive(baselineStream, ZipArchiveMode.Read))
using (Helpers.UseTempDir(out var tempFolder)) using (Helpers.UseTempDir(out var tempFolder))
@ -43,7 +45,7 @@ public static class ApiDiffValidation
var baselineDllPath = Path.Combine("baseline", baselineDll.target, baselineDll.entry.Name); var baselineDllPath = Path.Combine("baseline", baselineDll.target, baselineDll.entry.Name);
var baselineDllRealPath = Path.Combine(tempFolder, baselineDllPath); var baselineDllRealPath = Path.Combine(tempFolder, baselineDllPath);
Directory.CreateDirectory(Path.GetDirectoryName(baselineDllRealPath)!); Directory.CreateDirectory(Path.GetDirectoryName(baselineDllRealPath)!);
using (var baselineDllFile = File.Create(baselineDllRealPath)) await using (var baselineDllFile = File.Create(baselineDllRealPath))
{ {
await baselineDll.entry.Open().CopyToAsync(baselineDllFile); await baselineDll.entry.Open().CopyToAsync(baselineDllFile);
} }
@ -58,7 +60,7 @@ public static class ApiDiffValidation
var targetDllPath = Path.Combine("target", targetDll.target, targetDll.entry.Name); var targetDllPath = Path.Combine("target", targetDll.target, targetDll.entry.Name);
var targetDllRealPath = Path.Combine(tempFolder, targetDllPath); var targetDllRealPath = Path.Combine(tempFolder, targetDllPath);
Directory.CreateDirectory(Path.GetDirectoryName(targetDllRealPath)!); Directory.CreateDirectory(Path.GetDirectoryName(targetDllRealPath)!);
using (var targetDllFile = File.Create(targetDllRealPath)) await using (var targetDllFile = File.Create(targetDllRealPath))
{ {
await targetDll.entry.Open().CopyToAsync(targetDllFile); await targetDll.entry.Open().CopyToAsync(targetDllFile);
} }
@ -96,7 +98,7 @@ public static class ApiDiffValidation
.ToArray(); .ToArray();
} }
static async Task<Stream> DownloadBaselinePackage(string packagePath, Version baselineVersion) static async Task<Stream> DownloadBaselinePackage(string packagePath, string baselineVersion)
{ {
Build.Information("Downloading {0} baseline package for version {1}", Path.GetFileName(packagePath), baselineVersion); Build.Information("Downloading {0} baseline package for version {1}", Path.GetFileName(packagePath), baselineVersion);
@ -106,9 +108,10 @@ public static class ApiDiffValidation
Path.GetFileNameWithoutExtension(packagePath), Path.GetFileNameWithoutExtension(packagePath),
"""(\.\d+\.\d+\.\d+)$""", ""); """(\.\d+\.\d+\.\d+)$""", "");
using var httpClient = new HttpClient(); using var response = await s_httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get,
using var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, $"https://www.nuget.org/api/v2/package/{packageId}/{baselineVersion}"), HttpCompletionOption.ResponseHeadersRead);
$"https://www.nuget.org/api/v2/package/{packageId}/{baselineVersion}")); response.EnsureSuccessStatusCode();
await using var stream = await response.Content.ReadAsStreamAsync(); await using var stream = await response.Content.ReadAsStreamAsync();
var memoryStream = new MemoryStream(); var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream); await stream.CopyToAsync(memoryStream);

21
nukebuild/BuildParameters.cs

@ -10,22 +10,22 @@ using static Nuke.Common.IO.PathConstruction;
public partial class Build public partial class Build
{ {
[Parameter("configuration")] [Parameter(Name = "configuration")]
public string Configuration { get; set; } public string Configuration { get; set; }
[Parameter("skip-tests")] [Parameter(Name = "skip-tests")]
public bool SkipTests { get; set; } public bool SkipTests { get; set; }
[Parameter("force-nuget-version")] [Parameter(Name = "force-nuget-version")]
public string ForceNugetVersion { get; set; } public string ForceNugetVersion { get; set; }
[Parameter("skip-previewer")] [Parameter(Name = "skip-previewer")]
public bool SkipPreviewer { get; set; } public bool SkipPreviewer { get; set; }
[Parameter("api-baseline")] [Parameter(Name = "api-baseline")]
public string ApiValidationBaseline { get; set; } public string ApiValidationBaseline { get; set; }
[Parameter("update-api-suppression")] [Parameter(Name = "update-api-suppression")]
public bool UpdateApiValidationSuppression { get; set; } public bool UpdateApiValidationSuppression { get; set; }
public class BuildParameters public class BuildParameters
@ -63,7 +63,7 @@ public partial class Build
public string FileZipSuffix { get; } public string FileZipSuffix { get; }
public AbsolutePath ZipCoreArtifacts { get; } public AbsolutePath ZipCoreArtifacts { get; }
public AbsolutePath ZipNuGetArtifacts { get; } public AbsolutePath ZipNuGetArtifacts { get; }
public Version ApiValidationBaseline { get; } public string ApiValidationBaseline { get; }
public bool UpdateApiValidationSuppression { get; } public bool UpdateApiValidationSuppression { get; }
public AbsolutePath ApiValidationSuppressionFiles { get; } public AbsolutePath ApiValidationSuppressionFiles { get; }
@ -73,10 +73,6 @@ public partial class Build
Configuration = b.Configuration ?? "Release"; Configuration = b.Configuration ?? "Release";
SkipTests = b.SkipTests; SkipTests = b.SkipTests;
SkipPreviewer = b.SkipPreviewer; SkipPreviewer = b.SkipPreviewer;
ApiValidationBaseline = b.ApiValidationBaseline is not null ?
new Version(b.ApiValidationBaseline) :
new Version(11, 0);
UpdateApiValidationSuppression = b.UpdateApiValidationSuppression;
// CONFIGURATION // CONFIGURATION
MainRepo = "https://github.com/AvaloniaUI/Avalonia"; MainRepo = "https://github.com/AvaloniaUI/Avalonia";
@ -115,6 +111,9 @@ public partial class Build
// VERSION // VERSION
Version = b.ForceNugetVersion ?? GetVersion(); Version = b.ForceNugetVersion ?? GetVersion();
ApiValidationBaseline = b.ApiValidationBaseline ?? new Version(new Version(Version).Major, 0).ToString();
UpdateApiValidationSuppression = b.UpdateApiValidationSuppression;
if (IsRunningOnAzure) if (IsRunningOnAzure)
{ {
if (!IsNuGetRelease) if (!IsNuGetRelease)

Loading…
Cancel
Save