Skip to content

Commit 0f7e4b0

Browse files
committed
Update asciidoc diff output
This commit updates the diff asciidoc output to make assembly diff changes more readable within the Elastic documentation. - Type changes are output as labelled list items - Member changes are emitted as source code blocks
1 parent b7012d1 commit 0f7e4b0

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

build/scripts/Commandline.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Targets:
2828
* canary [apikey] [feed]
2929
- create a canary nuget package based on the current version if [feed] and [apikey] are provided
3030
also pushes to upstream (myget)
31-
* diff <github|nuget|dir|assembly> <version|path 1> <version|path 2> [format]
31+
* diff <github|nuget|directories|assemblies> <version|path 1> <version|path 2> [format]
3232
3333
NOTE: both the `test` and `integrate` targets can be suffixed with `-all` to force the tests against all suported TFM's
3434

build/scripts/Differ.fsx

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@
77
#load @"Tooling.fsx"
88
#load @"Projects.fsx"
99

10+
open Microsoft.FSharp.Reflection
1011
open System
11-
open System.IO
12-
13-
open Fake
14-
open System
12+
open System.Collections.Generic
1513
open System.IO
1614
open System.Linq
1715
open System.Net
1816
open System.Text
1917
open System.Text.RegularExpressions
2018
open System.Xml
2119
open System.Xml.Linq
20+
open Fake
2221
open Fake.Git.CommandHelper
23-
2422
open Paths
2523
open Projects
2624
open Tooling
@@ -264,42 +262,64 @@ module Differ =
264262
| :? XmlException -> ignore()
265263

266264
let private convertToAsciidoc path first second =
265+
let createDiffDescription description (writer:TextWriter) =
266+
let m = Regex.Match(description, "(.*?) changed from (.*?) to (.*).")
267+
if m.Success then
268+
let memberType = m.Groups.[1].Value
269+
let o = m.Groups.[2].Value
270+
let n = m.Groups.[3].Value
271+
writer.WriteLine("+")
272+
writer.WriteLine(sprintf "%s change" memberType)
273+
writer.WriteLine("+")
274+
writer.WriteLine("[source,csharp]")
275+
writer.WriteLine("----")
276+
writer.WriteLine(sprintf "// before in %s" first)
277+
writer.WriteLine(sprintf "%s" o)
278+
writer.WriteLine(sprintf "// now in %s" second)
279+
writer.WriteLine(sprintf "%s" n)
280+
writer.WriteLine("----")
281+
else
282+
writer.WriteLine(sprintf "%s" description)
283+
267284
let name = path |> Path.GetFileNameWithoutExtension
268285
try
269286
let doc = XDocument.Load path
270287
let output = Path.ChangeExtension(path, "asciidoc")
271288
DeleteFile output
289+
272290
use file = File.OpenWrite <| output
273291
use writer = new StreamWriter(file)
274-
writer.WriteLine(name |> replace "." "-" |> sprintf "[[%s-breaking-changes]]")
292+
writer.WriteLine(name |> replace "." "-" |> toLower |> sprintf "[[%s-breaking-changes]]")
275293
writer.WriteLine(sprintf "== Breaking changes for %s between %s and %s" name first second)
276294
writer.WriteLine()
277295

278296
for element in (doc |> descendents "Type") do
279297
let typeName = element |> attributeValue "Name" |> replace (sprintf "%s." name) ""
280298
let diffType = element |> attributeValue "DiffType" |> convertDiffType
299+
281300
match diffType with
282-
| Deleted -> writer.WriteLine(sprintf "[float]%s=== `%s` is deleted" Environment.NewLine typeName)
283-
| New -> writer.WriteLine(sprintf "[float]%s=== `%s` is added" Environment.NewLine typeName)
301+
| Deleted -> writer.WriteLine(sprintf "`%s`:: deleted" typeName)
302+
| New -> writer.WriteLine(sprintf "`%s`:: added" typeName)
284303
| Modified ->
285304
let members = Seq.append (element |> elements "Method") (element |> elements "Property")
286305
if Seq.isEmpty members |> not then
287-
writer.WriteLine(sprintf "[float]%s=== `%s`" Environment.NewLine typeName)
306+
writer.WriteLine(sprintf "`%s`::" typeName)
288307
for m in members do
289308
let memberName = m |> attributeValue "Name"
290309
if isNotNullOrEmpty memberName then
291310
let diffType = m |> attributeValue "DiffType"
292311
if isNotNullOrEmpty diffType then
293312
match convertDiffType diffType with
294-
| Deleted -> writer.WriteLine(sprintf "[float]%s==== `%s` is deleted" Environment.NewLine memberName)
295-
| New -> writer.WriteLine(sprintf "[float]%s==== `%s` is added" Environment.NewLine memberName)
313+
| Deleted -> writer.WriteLine(sprintf " * `%s` deleted" memberName)
314+
| New -> writer.WriteLine(sprintf " * `%s` added" memberName)
296315
| Modified ->
297316
match (m.Descendants(XName.op_Implicit "DiffItem") |> Seq.tryHead) with
298317
| Some diffItem ->
299-
writer.WriteLine(sprintf "[float]%s==== `%s`" Environment.NewLine memberName)
318+
writer.WriteLine(sprintf " * `%s`" memberName)
300319
let diffDescription = diffItem.Value
301-
writer.WriteLine(Regex.Replace(diffDescription, "changed from (.*?) to (.*).", "changed from `$1` to `$2`."))
320+
writer |> createDiffDescription diffDescription
302321
| None -> ()
322+
writer.WriteLine()
303323
with
304324
| :? XmlException -> ignore()
305325

build/scripts/Targets.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Target "Profile" <| fun _ ->
5353
let url = getBuildParam "elasticsearch"
5454
Profiler.IndexResults url
5555

56-
Target "Integrate" <| Tests.RunIntegrationTests
56+
Target "Integrate" Tests.RunIntegrationTests
5757

5858
Target "Benchmark" <| fun _ ->
5959
let runInteractive = ((getBuildParam "nonInteractive") <> "1")

0 commit comments

Comments
 (0)