Skip to content

Commit

Permalink
Improve the API diff (#15020)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne authored Jun 9, 2022
1 parent 78c7918 commit 414c5bf
Show file tree
Hide file tree
Showing 21 changed files with 896 additions and 1,712 deletions.
2 changes: 1 addition & 1 deletion external/api-tools
2 changes: 1 addition & 1 deletion tools/apidiff/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
temp/
diff/
output/
links/
references/
updated-references/
Expand Down
422 changes: 210 additions & 212 deletions tools/apidiff/Makefile

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions tools/apidiff/merger.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

Expand All @@ -20,16 +21,15 @@ public static void Process (string platform, string path, string os, string? des
if (!Directory.Exists (path))
throw new DirectoryNotFoundException (path);

if (destinationPath is not null && !Directory.Exists (destinationPath))
throw new DirectoryNotFoundException (destinationPath);

var content = new StringWriter ();
var files = Directory.GetFileSystemEntries (path, "*.md");
Array.Sort (files);
string from = "unknown";
string to = "unknown";
bool lookForVersion = false;
foreach (var file in files) {
if (new FileInfo (file).Length == 0)
continue;
// skip everything before and including title (single #) from each file, we already have one
string? foundTitle = null;
foreach (var line in File.ReadAllLines (file)) {
Expand All @@ -55,6 +55,7 @@ public static void Process (string platform, string path, string os, string? des
}
}
}
var hasVersions = from != "unknown" && to != "unknown";

// https://github.com/MicrosoftDocs/xamarin-docs/blob/live/contributing-guidelines/template.md#file-name
var filename = $"{os}-{from}-{to}".Replace ('.', '-').ToLowerInvariant () + ".md";
Expand All @@ -65,11 +66,18 @@ public static void Process (string platform, string path, string os, string? des
var guid = new Guid (digest[0..16]);

var headers = new StringWriter ();
var title = $"{platform} SDK API diff: {from} vs {to}";
var title = $"{platform} SDK API diff";
if (hasVersions) {
title += $": {from} vs {to}";
}
// https://github.com/MicrosoftDocs/xamarin-docs/blob/live/contributing-guidelines/template.md#metadata
headers.WriteLine ("---");
headers.WriteLine ($"title: \"{title}\"");
headers.WriteLine ($"description: List of API changes between {platform} versions {from} and {to}.");
if (hasVersions) {
headers.WriteLine ($"description: List of API changes between {platform} versions {from} and {to}.");
} else {
headers.WriteLine ($"description: List of API changes for {platform}.");
}
headers.WriteLine ($"author: spouliot");
headers.WriteLine ($"ms.author: sepoulio");
headers.WriteLine ($"ms.date: {DateTime.Now.ToString ("d", new CultureInfo ("en-US"))}");
Expand All @@ -81,17 +89,13 @@ public static void Process (string platform, string path, string os, string? des
headers.WriteLine ($"# {title}");
headers.WriteLine ();

var filePath = destinationPath is not null ? Path.Combine (destinationPath, filename) : filename;
var filePath = destinationPath;
File.WriteAllText (filePath, headers.ToString ());

var alldiffs = content.ToString ();
if (alldiffs.Length == 0)
alldiffs = "No changes were found between both versions."; // should not happen for releases (versions change)
File.AppendAllText (filePath, alldiffs);
Console.WriteLine ($"@MonkeyWrench: AddFile: {Path.GetFullPath (filePath)}");

if (File.Exists ("api-diff.html"))
File.AppendAllText ("api-diff.html", $"\n<h2><a href=\"{filePath}\">{platform} API diff (markdown)</a></h2>");
}

public static int Main (string [] args)
Expand Down
53 changes: 53 additions & 0 deletions tools/apidiff/report-status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash -e

PLATFORM=$1
OUTPUT_DIR=$2
FORMAT=$3
HTML=$4
MARKDOWN=$5
OUTPUT=$6

if test -n "$7"; then
shift 6
echo "Too many arguments: $*"
exit 1
fi

if [[ $FORMAT == html ]]; then
echo -n "<li>" >> "$OUTPUT"

if ! test -f "$OUTPUT_DIR/$HTML"; then
echo -n "<s>$PLATFORM</s> (no diff detected)" >> "$OUTPUT"
elif ! test -s "$OUTPUT_DIR/$HTML"; then
echo -n "<s>$PLATFORM</s> (empty diff detected)" >> "$OUTPUT"
elif grep "BreakingChangesDetected" "$OUTPUT_DIR/$HTML" >/dev/null 2>&1; then
echo -n "$PLATFORM: <a href='$HTML'>html</a> <a href='$MARKDOWN'>markdown</a> ($HTML_BREAKING_CHANGES_MESSAGE)" >> "$OUTPUT"
elif ! grep "No change detected" "$OUTPUT_DIR/$HTML" >/dev/null 2>&1; then
echo -n "$PLATFORM: <a href='$HTML'>html</a> <a href='$MARKDOWN'>markdown</a> ($HTML_NO_BREAKING_CHANGES_MESSAGE)" >> "$OUTPUT"
else
echo -n "<s>$PLATFORM</s> (no change detected)" >> "$OUTPUT"
fi

echo "</li>" >> "$OUTPUT"

elif [[ $FORMAT == markdown ]]; then
echo -n "* " >> "$OUTPUT"

if ! test -f "$OUTPUT_DIR/$HTML"; then
echo -n "~$PLATFORM~: (no diff detected)" >> "$OUTPUT"
elif ! test -s "$OUTPUT_DIR/$HTML"; then
echo -n "~$PLATFORM~: (empty diff detected)" >> "$OUTPUT"
elif grep "BreakingChangesDetected" "$OUTPUT_DIR/$HTML" >/dev/null 2>&1; then
echo -n "$PLATFORM: [vsdrops]($HTML) [gist]($MARKDOWN) ($MARKDOWN_BREAKING_CHANGES_MESSAGE)" >> "$OUTPUT"
elif ! grep "No change detected" "$OUTPUT_DIR/$HTML" >/dev/null 2>&1; then
echo -n "$PLATFORM: [vsdrops]($HTML) [gist]($MARKDOWN) ($MARKDOWN_NO_BREAKING_CHANGES_MESSAGE)" >> "$OUTPUT"
else
echo -n "~$PLATFORM~ (no change detected)" >> "$OUTPUT"
fi

echo "" >> "$OUTPUT"
else
echo "Unknown output format: $FORMAT"
exit 1
fi

Loading

0 comments on commit 414c5bf

Please sign in to comment.