forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrepare-Release.ps1
More file actions
286 lines (235 loc) · 8.66 KB
/
Prepare-Release.ps1
File metadata and controls
286 lines (235 loc) · 8.66 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$package,
[string]$ReleaseDate
)
function Get-LevenshteinDistance {
<#
.SYNOPSIS
Get the Levenshtein distance between two strings.
.DESCRIPTION
The Levenshtein Distance is a way of quantifying how dissimilar two strings (e.g., words) are to one another by counting the minimum number of operations required to transform one string into the other.
.EXAMPLE
Get-LevenshteinDistance 'kitten' 'sitting'
.LINK
http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#C.23
http://en.wikipedia.org/wiki/Edit_distance
https://communary.wordpress.com/
https://github.com/gravejester/Communary.PASM
.NOTES
Author: Øyvind Kallstad
Date: 07.11.2014
Version: 1.0
#>
[CmdletBinding()]
param(
[Parameter(Position = 0)]
[string]$String1,
[Parameter(Position = 1)]
[string]$String2,
# Makes matches case-sensitive. By default, matches are not case-sensitive.
[Parameter()]
[switch] $CaseSensitive,
# A normalized output will fall in the range 0 (perfect match) to 1 (no match).
[Parameter()]
[switch] $NormalizeOutput
)
if (-not($CaseSensitive)) {
$String1 = $String1.ToLowerInvariant()
$String2 = $String2.ToLowerInvariant()
}
$d = New-Object 'Int[,]' ($String1.Length + 1), ($String2.Length + 1)
for ($i = 0; $i -le $d.GetUpperBound(0); $i++) {
$d[$i,0] = $i
}
for ($i = 0; $i -le $d.GetUpperBound(1); $i++) {
$d[0,$i] = $i
}
for ($i = 1; $i -le $d.GetUpperBound(0); $i++) {
for ($j = 1; $j -le $d.GetUpperBound(1); $j++) {
$cost = [Convert]::ToInt32((-not($String1[$i–1] -ceq $String2[$j–1])))
$min1 = $d[($i–1),$j] + 1
$min2 = $d[$i,($j–1)] + 1
$min3 = $d[($i–1),($j–1)] + $cost
$d[$i,$j] = [Math]::Min([Math]::Min($min1,$min2),$min3)
}
}
$distance = ($d[$d.GetUpperBound(0),$d.GetUpperBound(1)])
if ($NormalizeOutput) {
return (1 – ($distance) / ([Math]::Max($String1.Length,$String2.Length)))
}
else {
return $distance
}
}
function Get-ReleaseDay($baseDate)
{
# Find first friday
while ($baseDate.DayOfWeek -ne 5)
{
$baseDate = $baseDate.AddDays(1)
}
# Go to Tuesday
$baseDate = $baseDate.AddDays(4)
return $baseDate;
}
$ErrorPreference = 'Stop'
$repoRoot = Resolve-Path "$PSScriptRoot/../..";
if (!(Get-Command az)) {
throw 'You must have the Azure CLI installed: https://aka.ms/azure-cli'
}
az extension show -n azure-devops > $null
if (!$?){
throw 'You must have the azure-devops extension run `az extension add --name azure-devops`'
}
. ${repoRoot}\eng\common\scripts\SemVer.ps1
. ${repoRoot}\eng\common\scripts\ChangeLog-Operations.ps1
$packageDirectory = Get-ChildItem "$repoRoot/sdk" -Directory -Recurse -Depth 2 -Filter $package
$serviceDirectory = $packageDirectory.Parent.Name
Write-Host "Source directory $serviceDirectory"
try
{
$existing = Invoke-WebRequest "https://api.nuget.org/v3-flatcontainer/$($package.ToLower())/index.json" | ConvertFrom-Json;
}
catch
{
$existing = @()
}
$libraryType = "Preview";
$latestVersion = $null;
foreach ($existingVersion in $existing.versions)
{
$parsedVersion = [AzureEngSemanticVersion]::new($existingVersion)
if (!$parsedVersion.IsPrerelease)
{
$libraryType = "GA"
}
$latestVersion = $existingVersion;
}
$currentProjectVersion = ([xml](Get-Content "$packageDirectory/src/*.csproj")).Project.PropertyGroup.Version
if ($latestVersion)
{
Write-Host
Write-Host "Latest released version $latestVersion, library type $libraryType" -ForegroundColor Green
}
else
{
Write-Host
Write-Host "No released version, library type $libraryType" -ForegroundColor Green
}
$newVersion = Read-Host -Prompt "Input the new version or press Enter to use use current project version '$currentProjectVersion'"
if (!$newVersion)
{
$newVersion = $currentProjectVersion;
}
if ($latestVersion)
{
$releaseType = "None";
$parsedNewVersion = [AzureEngSemanticVersion]::new($newVersion)
if ($parsedNewVersion.Major -ne $parsedVersion.Major)
{
$releaseType = "Major"
}
elseif ($parsedNewVersion.Minor -ne $parsedVersion.Minor)
{
$releaseType = "Minor"
}
elseif ($parsedNewVersion.Patch -ne $parsedVersion.Patch)
{
$releaseType = "Bugfix"
}
elseif ($parsedNewVersion.IsPrerelease)
{
$releaseType = "Bugfix"
}
}
else
{
$releaseType = "Major";
}
Write-Host
Write-Host "Detected released type $releaseType" -ForegroundColor Green
if (!$ReleaseDate)
{
$currentDate = Get-Date
$thisMonthReleaseDate = Get-ReleaseDay((Get-Date -Day 1));
$nextMonthReleaseDate = Get-ReleaseDay((Get-Date -Day 1).AddMonths(1));
if ($thisMonthReleaseDate -ge $currentDate)
{
# On track for this month release
$ParsedReleaseDate = $thisMonthReleaseDate
}
elseif ($currentDate.Day -lt 15)
{
# Catching up to this month release
$ParsedReleaseDate = $currentDate
}
else
{
# Next month release
$ParsedReleaseDate = $nextMonthReleaseDate
}
}
else
{
$ParsedReleaseDate = [datetime]::ParseExact($ReleaseDate, 'yyyy-MM-dd', [Globalization.CultureInfo]::InvariantCulture)
}
$releaseDateString = $ParsedReleaseDate.ToString("yyyy-MM-dd")
$month = $ParsedReleaseDate.ToString("MMMM")
Write-Host
Write-Host "Assuming release is in $month with release date $releaseDateString" -ForegroundColor Green
Write-Host
Write-Host "Updating versions" -ForegroundColor Green
& "$repoRoot\eng\scripts\Update-PkgVersion.ps1" -ServiceDirectory $serviceDirectory -PackageName $package -NewVersionString $newVersion -ReleaseDate $releaseDateString
$commonParameter = @("--organization", "https://dev.azure.com/azure-sdk", "-o", "json", "--only-show-errors")
$workItems = az boards query @commonParameter --project Release --wiql "SELECT [ID], [State], [Iteration Path], [Title] FROM WorkItems WHERE [State] <> 'Closed' AND [Iteration Path] under 'Release\2020\$month' AND [Title] contains '.NET'" | ConvertFrom-Json;
Write-Host
Write-Host "The following work items exist:"
foreach ($item in $workItems)
{
$id = $item.fields."System.ID";
$title = $item.fields."System.Title";
$path = $item.fields."System.IterationPath";
Write-Host "$id - $path - $title"
}
# Sort using fuzzy match
$workItems = $workItems | Sort-Object -property @{Expression = { Get-LevenshteinDistance $_.fields."System.Title" $package -NormalizeOutput }}
$mostProbable = $workItems | Select-Object -Last 1
$issueId = Read-Host -Prompt "Input the work item ID or press Enter to use '$($mostProbable.fields."System.ID") - $($mostProbable.fields."System.Title")' (fuzzy matched based on title)"
if (!$issueId)
{
$issueId = $mostProbable.fields."System.ID"
}
$changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation "$packageDirectory/CHANGELOG.md" -VersionString $newVersion
$githubAnchor = $changeLogEntry.ReleaseTitle.Replace("## ", "").Replace(".", "").Replace("(", "").Replace(")", "").Replace(" ", "-")
$notes = "> dotnet add package $package --version $newVersion`n`n";
$notes += "### $package [Changelog](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/$serviceDirectory/$package/CHANGELOG.md#$githubAnchor)`n"
$changeLogEntry.ReleaseContent | %{ $notes += "$_`n" }
$fields = @{
"Permalink usetag"="https://github.com/Azure/azure-sdk-for-net/sdk/$serviceDirectory/$package/README.md"
"Package Registry Permalink"="https://nuget.org/packages/$package/$newVersion"
"Library Type"=$libraryType
"Release Type"=$releaseType
"Version Number"=$newVersion
"Planned Release Date"=$releaseDateString
"Notes"=[System.Net.WebUtility]::HtmlEncode($notes).Replace("`n", "<br>")
}
Write-Host
Write-Host "Going to set the following fields:" -ForegroundColor Green
foreach ($field in $fields.Keys)
{
Write-Host " $field = $($fields[$field])"
}
$decision = $Host.UI.PromptForChoice("Updating work item https://dev.azure.com/azure-sdk/Release/_workitems/edit/$issueId", 'Are you sure you want to proceed?', @('&Yes'; '&No'), 0)
if ($decision -eq 0)
{
az boards work-item update @commonParameter --id $issueId --state Active > $null
foreach ($field in $fields.Keys)
{
az boards work-item update @commonParameter --id $issueId -f "$field=$($fields[$field])" > $null
}
}
Write-Host
Write-Host "Snippet for the centralized CHANGELOG:" -ForegroundColor Green
Write-Host $notes