Skip to content

Commit 2e615ad

Browse files
committed
Generate release notes in pipeline
1 parent 2418d9e commit 2e615ad

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

scripts/write-release-notes.ps1

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
[CmdletBinding()]
2+
param
3+
(
4+
[string] $Path = ".",
5+
# if this is a pre-release or stable version
6+
[switch] $Stable,
7+
# externally provide the version number we will use
8+
[string] $PackageVersion,
9+
# in CI we don't know the end tag, so we diff till the current commit
10+
[switch] $EndWithLatestCommit
11+
)
12+
13+
if ($EndWithLatestCommit -and [string]::IsNullOrWhiteSpace($PackageVersion)) {
14+
throw "EndWithLatestCommit was enabled, provide PackageVersion in this format 16.8.0-preview-20200924-01, or this format 16.8.0."
15+
}
16+
17+
$repoUrl = $(if ((git -C $Path remote -v) -match "upstream") {
18+
git -C $Path remote get-url --push upstream
19+
}
20+
else {
21+
git -C $Path remote get-url --push origin
22+
})-replace "\.git$"
23+
24+
# list all tags on this branch ordered by creator date to get the latest, stable or pre-release tag.
25+
# For stable release we choose only tags without any dash, for pre-release we choose all tags.
26+
$tags = git -C $Path tag -l --sort=creatordate | Where-Object { $_ -match "v\d+\.\d+\.\d+.*" -and (-not $Stable -or $_ -notlike '*-*') }
27+
28+
if ($EndWithLatestCommit) {
29+
# in CI we don't have the tag yet, so we show changes between the most recent tag, and this commit
30+
# we figure out the tag from the package version that is set by vsts-prebuild
31+
$start = $tags | Select-Object -Last 1
32+
$end = git -C $Path rev-parse HEAD
33+
$tag = "v$PackageVersion"
34+
}
35+
else {
36+
# normally we show changes between the latest two tags
37+
$start, $end = $tags | Select-Object -Last 2
38+
$tag = $end
39+
}
40+
41+
# # override the tags to use if you need
42+
# $start = "v16.8.0-preview-20200812-03"
43+
# $end = $tag = "v16.8.0-preview-20200921-01"
44+
45+
46+
Write-Host "Generating release notes for $start..$end$(if ($EndWithLatestCommit) { " (expected tag: $tag)" })"
47+
48+
$sourceBranch = $branch = git -C $Path rev-parse --abbrev-ref HEAD
49+
if ($sourceBranch -eq "HEAD") {
50+
# when CI checks out just the single commit, https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
51+
$sourceBranch = $env:BUILD_SOURCEBRANCH -replace "^refs/heads/"
52+
}
53+
54+
if ([string]::IsNullOrWhiteSpace($branch)) {
55+
throw "Branch is null or empty!"
56+
}
57+
58+
if ([string]::IsNullOrWhiteSpace($sourceBranch)) {
59+
throw "SourceBranch is null or empty!"
60+
}
61+
62+
Write-Host "Branch is $branch"
63+
Write-Host "SourceBranch is $sourceBranch"
64+
$branchesWithStartTag = git -C $Path branch --contains tags/$start
65+
66+
if (-not $branchesWithStartTag -or $branchesWithStartTag -notmatch $branch) {
67+
Write-Host "This branch $branch$(if($branch -ne $sourceBranch){" ($sourceBranch)"}), does not contain the starting tag $start. Skipping generating release notes."
68+
if ($branchesWithStartTag) {
69+
Write-Host "The tag is present on branches:`n$($branchesWithStartTag)."
70+
}
71+
return
72+
}
73+
else {
74+
Write-Host "Branch $branch$(if($branch -ne $sourceBranch){" ($sourceBranch)"}) has tag $start, getting log since that."
75+
}
76+
77+
$prUrl = "$repoUrl/pull/"
78+
$v = $tag -replace '^v'
79+
$b = if ($Stable) { $v } else { $tag -replace '.*?(\d+-\d+)$', '$1' }
80+
# using .. because I want to know the changes that are on this branch, but don't care about the changes that I don't have https://stackoverflow.com/a/24186641/3065397
81+
$log = (git -C $Path log "$start..$end" --oneline --pretty="format:%s" --first-parent --no-merges)
82+
$issues = $log | ForEach-Object {
83+
if ($_ -match '^(?<message>.+)\s\(#(?<pr>\d+)\)?$') {
84+
$message = "* $($matches.message)"
85+
if ($matches.pr) {
86+
$pr = $matches.pr
87+
$message += " [#$pr]($prUrl$pr)"
88+
}
89+
90+
$message
91+
}
92+
else
93+
{
94+
"* $_"
95+
}
96+
}
97+
98+
$output = @"
99+
100+
See the release notes [here](https://github.com/microsoft/vstest-docs/blob/master/docs/releases.md#$($v -replace '\.')).
101+
102+
-------------------------------
103+
104+
## $v
105+
106+
### Issue Fixed
107+
$($issues -join "`n")
108+
109+
See full log [here]($repoUrl/compare/$start...$tag)
110+
111+
### Drops
112+
113+
* TestPlatform vsix: [$v](https://vsdrop.corp.microsoft.com/file/v1/Products/DevDiv/microsoft/vstest/$sourceBranch/$b;/TestPlatform.vsix)
114+
* Microsoft.TestPlatform.ObjectModel : [$v](https://www.nuget.org/packages/Microsoft.TestPlatform.ObjectModel/$v)
115+
"@
116+
117+
118+
$output
119+
$output | clip

0 commit comments

Comments
 (0)