This repository has been archived by the owner on Nov 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
/
nuget-diff.cake
93 lines (76 loc) · 3.03 KB
/
nuget-diff.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// SECTION: Arguments and Settings
var ROOT_DIR = MakeAbsolute((DirectoryPath)Argument("root", "."));
var ARTIFACTS_DIR = MakeAbsolute((DirectoryPath)Argument("artifacts", ROOT_DIR.Combine("output").FullPath));
var CACHE_DIR = MakeAbsolute((DirectoryPath)Argument("cache", ROOT_DIR.Combine("externals/api-diff").FullPath));
var OUTPUT_DIR = MakeAbsolute((DirectoryPath)Argument("output", ROOT_DIR.Combine("output/api-diff").FullPath));
// SECTION: Main Script
Information("");
Information("Script Arguments:");
Information(" Root directory: {0}", ROOT_DIR);
Information(" Artifacts directory: {0}", ARTIFACTS_DIR);
Information(" Cache directory: {0}", CACHE_DIR);
Information(" Output directory: {0}", OUTPUT_DIR);
Information("");
// SECTION: Diff NuGets
var nupkgs = GetFiles($"{ARTIFACTS_DIR}/**/*.nupkg");
if (!nupkgs.Any()) {
Warning($"##vso[task.logissue type=warning]No NuGet packages were found.");
} else {
Parallel.ForEach (nupkgs, nupkg => {
var version = "--latest";
var versionFile = nupkg.FullPath + ".baseversion";
if (FileExists(versionFile)) {
version = "--version=" + System.IO.File.ReadAllText(versionFile).Trim();
}
var exitCode = StartProcess("api-tools", new ProcessSettings {
Arguments = new ProcessArgumentBuilder()
.Append("nuget-diff")
.AppendQuoted(nupkg.FullPath)
.Append(version)
.Append("--prerelease")
.Append("--group-ids")
.Append("--ignore-unchanged")
.Append("--compare-nuget-structure")
.AppendSwitchQuoted("--output", OUTPUT_DIR.FullPath)
.AppendSwitchQuoted("--cache", CACHE_DIR.Combine("package-cache").FullPath)
});
if (exitCode != 0)
throw new Exception ($"api-tools exited with error code {exitCode} ({nupkg.FullPath}).");
});
}
// SECTION: Create combined nuget-diff.md
var nu_diffs = GetFiles($"{OUTPUT_DIR.FullPath}/**/nuget-diff.md");
if (nu_diffs.Any()) {
using (var output = System.IO.File.Create(System.IO.Path.Combine(OUTPUT_DIR.FullPath, "all-nuget-diffs.md"))) {
foreach (var file in nu_diffs) {
using (var input = System.IO.File.OpenRead(file.FullPath)) {
input.CopyTo(output);
Console.WriteLine();
}
}
}
}
// SECTION: Upload Diffs
var diffs = GetFiles($"{OUTPUT_DIR}/**/*.md");
if (!diffs.Any()) {
Warning($"##vso[task.logissue type=warning]No NuGet diffs were found.");
} else {
var temp = CACHE_DIR.Combine("md-files");
EnsureDirectoryExists(temp);
foreach (var diff in diffs) {
var segments = diff.Segments.Reverse().ToArray();
var nugetId = segments[2];
var platform = segments[1];
var assembly = ((FilePath)segments[0]).GetFilenameWithoutExtension().GetFilenameWithoutExtension();
var breaking = segments[0].EndsWith(".breaking.md");
// using non-breaking spaces
var newName = breaking ? "[BREAKING] " : "";
newName += $"{nugetId} {assembly} ({platform}).md";
var newPath = temp.CombineWithFilePath(newName);
CopyFile(diff, newPath);
}
var temps = GetFiles($"{temp}/**/*.md");
foreach (var t in temps.OrderBy(x => x.FullPath)) {
Information($"##vso[task.uploadsummary]{t}");
}
}