Skip to content

Commit ed44271

Browse files
committed
Generate release notes (#3201)
This commit adds the generation of draft release notes to build/output. Closed issues for labelled with the target release label are fetched from Github and grouped by Bug,Feature and Deprecation labels, appearing in more than one group if featuring more than one of those labels. Comparison link is generated from the version in global.json and the version being released. (cherry picked from commit 238e890) (cherry picked from commit ed82eb8)
1 parent c20849a commit ed44271

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed

build/scripts/Paths.fsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ open Projects
1515

1616
module Paths =
1717

18-
let Repository = "https://github.com/elastic/elasticsearch-net"
18+
let OwnerName = "elastic"
19+
let RepositoryName = "elasticsearch-net"
20+
let Repository = sprintf "https://github.com/%s/%s" OwnerName RepositoryName
1921

2022
let BuildFolder = "build"
2123
let BuildOutput = sprintf "%s/output" BuildFolder

build/scripts/Releasing.fsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
#I @"../../packages/build/FAKE/tools"
2+
#I @"../../packages/build/Octokit/lib/net45"
23
#r @"FakeLib.dll"
4+
#r "Octokit.dll"
5+
#nowarn "0044" //TODO sort out FAKE 5
36

47
#load @"Projects.fsx"
58
#load @"Paths.fsx"
69
#load @"Tooling.fsx"
710
#load @"Versioning.fsx"
811

912
open System
13+
open System.Collections.Generic
1014
open System.IO
1115
open System.Linq
1216
open System.Text
1317
open System.Xml.Linq
1418
open Microsoft.FSharp.Quotations
1519
open Microsoft.FSharp.Quotations.Patterns
1620
open Fake
21+
open Octokit
1722

1823
open Paths
1924
open Projects
@@ -90,3 +95,56 @@ module Release =
9095
| 0 -> traceFAKE "publish to myget succeeded" |> ignore
9196
| _ -> failwith "publish to myget failed" |> ignore
9297
)
98+
99+
let GenerateNotes() =
100+
let previousVersion = Versioning.GlobalJsonVersion.ToString()
101+
let currentVersion = Versioning.CurrentVersion.ToString()
102+
let label = sprintf "v%s" currentVersion
103+
let releaseNotes = sprintf "ReleaseNotes-%s.md" currentVersion |> Paths.Output
104+
let client = new GitHubClient(new ProductHeaderValue("ReleaseNotesGenerator"))
105+
client.Credentials <- Credentials.Anonymous
106+
107+
let filter = new RepositoryIssueRequest()
108+
filter.Labels.Add label
109+
filter.State <- ItemStateFilter.Closed
110+
111+
let labelHeaders =
112+
[("Feature", "Features & Enhancements");
113+
("Bug", "Bug Fixes");
114+
("Deprecation", "Deprecations");]
115+
|> Map.ofList
116+
117+
let groupByLabel (issues:IReadOnlyList<Issue>) =
118+
let dict = new Dictionary<string, Issue list>()
119+
for issue in issues do
120+
for labelHeader in labelHeaders do
121+
if issue.Labels.Any(fun l -> l.Name = labelHeader.Key) then
122+
let exists,list = dict.TryGetValue(labelHeader.Key)
123+
match exists with
124+
| true -> dict.[labelHeader.Key] <- issue :: list
125+
| false -> dict.Add(labelHeader.Key, [issue])
126+
dict
127+
128+
let closedIssues = client.Issue.GetAllForRepository(Paths.OwnerName, Paths.RepositoryName, filter)
129+
|> Async.AwaitTask
130+
|> Async.RunSynchronously
131+
|> groupByLabel
132+
133+
use file = File.OpenWrite <| releaseNotes
134+
use writer = new StreamWriter(file)
135+
writer.WriteLine(sprintf "%s/compare/%s...%s" Paths.Repository previousVersion currentVersion)
136+
writer.WriteLine()
137+
for closedIssue in closedIssues do
138+
labelHeaders.[closedIssue.Key] |> sprintf "## %s" |> writer.WriteLine
139+
writer.WriteLine()
140+
for issue in closedIssue.Value do
141+
sprintf "- #%i %s" issue.Number issue.Title |> writer.WriteLine
142+
writer.WriteLine()
143+
144+
sprintf "### [View the full list of issues and PRs](%s/issues?utf8=%%E2%%9C%%93&q=label%%3A%s)" Paths.Repository label
145+
|> writer.WriteLine
146+
147+
148+
149+
150+

build/scripts/Targets.fsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Target "Release" <| fun _ ->
7070
Release.NugetPack()
7171
Versioning.ValidateArtifacts()
7272
StrongName.ValidateDllsInNugetPackage()
73+
Release.GenerateNotes()
7374

7475
Target "Canary" <| fun _ ->
7576
trace "Running canary build"

build/scripts/Versioning.fsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ module Versioning =
3838
newGlobalJson.JsonValue.WriteTo(tw, JsonSaveOptions.None)
3939
tracefn "Written (%s) to global.json as the current version will use this version from now on as current in the build" (version.ToString())
4040

41+
let GlobalJsonVersion = parse(globalJson.Version)
42+
4143
let CurrentVersion =
4244
Commandline.parse()
43-
let currentVersion = parse(globalJson.Version)
45+
let currentVersion = GlobalJsonVersion
4446
let bv = getBuildParam "version"
4547
let buildVersion = if (isNullOrEmpty bv) then None else Some(parse(bv))
4648
match (getBuildParam "target", buildVersion) with

paket.dependencies

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ group build
77
nuget FAKE
88
nuget FSharp.Data
99

10-
#Profiling.fsx uses this
10+
# persisting profiling results
1111
nuget Nest framework: net45
12+
13+
nuget Octokit

0 commit comments

Comments
 (0)