forked from microsoft/microsoft-ui-xaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReleaseHelper.ps1
243 lines (198 loc) · 8.07 KB
/
ReleaseHelper.ps1
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
Write-Verbose "PSScriptRoot: $PSScriptRoot"
. $PSScriptRoot\ADALAuth.ps1
###############################################################################
# Retrieve-Headers
# Pops an authentication flow for VSTS
#
# This just wraps the base function from ADALAuth.ps1, and saves the
# headers so that any future calls to this return immediately
###############################################################################
function Retrieve-Headers
{
if ($global:vstsRestApiHeaders -eq $null)
{
$global:vstsRestApiHeaders = Get-AuthorizationHeaders
}
}
###############################################################################
# GetAnswer
# Stolen from Jevan's CopyAndPrepVHD script
###############################################################################
function GetAnswer
{
Param([string[]]$Choices)
while ($true)
{
$choice = Read-Host -Prompt ("[" + ([string]::Join("|", $Choices)) + "]")
foreach ($possibleChoice in $Choices)
{
if ($possibleChoice -like $choice)
{
return $choice
}
}
}
return $null
}
###############################################################################
# RunLocalization
# Run the localization script with a unique tag
###############################################################################
function RunLocalization
{
Param([string] $branchName)
$locWorkflowName = $branchName -replace '/','_'
$locWorkflowName = "localization_nuget_release_" + $locWorkflowName
$DateTime = Get-Date #or any other command to get DateTime object
$locWorkflowName = $locWorkflowName + ([DateTimeOffset]$DateTime).ToUnixTimeSeconds();
Write-Host $locWorkflowName
pushd build/localization
.\RunLocWorkflow.ps1 $locWorkflowName
popd
}
###############################################################################
# New-BranchPullRequest
# Create a pull request from the specified branch into master
###############################################################################
function New-BranchPullRequest
{
Param([string] $branchName)
Retrieve-Headers
$pullRequestParameters = @{
"sourceRefName"="refs/heads/$branchname"
"targetRefName"="refs/heads/master"
"title"="Updating custom.props and localization in master (from nuget package creation)"
"description"=""
"reviewers"=@()
}
Invoke-RestMethod -Uri "https://microsoft.visualstudio.com/defaultcollection/os/_apis/git/repositories/dep.controls/pullRequests?api-version=3.0-preview&sourceRefName=refs/heads/$branchname" -Body (ConvertTo-Json $pullRequestParameters) -Method Post -ContentType "application/json" -Headers $global:vstsRestApiHeaders 2>&1> $null
}
function Get-BranchPullRequests
{
Invoke-RestMethod -Uri "https://microsoft.visualstudio.com/defaultcollection/os/_apis/git/repositories/dep.controls/pullRequests?api-version=3.0-preview&sourceRefName=refs/heads/$branchname" -Method Get -Headers $global:vstsRestApiHeaders
}
function Lock-Branch
{
Param([string] $branchName)
Retrieve-Headers
$parameters = @{
"isLocked"="true"
}
Invoke-RestMethod -Uri "https://microsoft.visualstudio.com/defaultcollection/os/_apis/git/repositories/dep.controls/refs/heads/$($branchName)?api-version=1.0" -Body (ConvertTo-Json $parameters) -Method Patch -ContentType "application/json" -Headers $global:vstsRestApiHeaders 2>&1> $null
}
###############################################################################
# Queue-NewReleaseBuild
# Queue a build of the specified branch
###############################################################################
function Queue-NewReleaseBuild
{
Param([string] $branchName)
Retrieve-Headers
$root = @{
"sourceBranch" = "refs/heads/$branchName";
"definition" = @{
"id" = "11819" # depcontrols_release build defn
};
"project" = @{
"id" = "8d47e068-03c8-4cdc-aa9b-fc6929290322" # OS
};
"repository" = @{
"id" = "d39af991-db55-43c3-bdef-c6333a2b3264" # dep.controls
};
};
$response = Invoke-RestMethod https://microsoft.visualstudio.com/DefaultCollection/os/_apis/build/builds?api-version=2.0 -Body (ConvertTo-Json $root) -Method Post -ContentType "application/json" -Headers $global:vstsRestApiHeaders
$id = $response.id;
$url = "https://microsoft.visualstudio.com/DefaultCollection/OS/_build/index?buildId=$id"
Write-Host "New build at $url"
Start-Process $url
}
#####################################################
# START ACTUAL SCRIPT #
#####################################################
Write-Host "Make sure this branch is clear of changes!"
Write-Host "ReleaseHelper, select your action:"
Write-Host "1. Create and prepare release branch"
# Write-Host "2. Deploy nuget package to feed"
$scriptAction = GetAnswer("1", "2");
if ($scriptAction -eq "1")
{
Write-Host "Do you want me to switch to master and pull?"
if ((GetAnswer("Y", "N")) -eq "Y")
{
Write-Host "YEAH BOY";
git checkout master
git pull
}
$branchName = git name-rev --name-only HEAD
Write-Host "Create a release branch [Y]? Or use existing branch $branchName [N]"
if ((GetAnswer("Y", "N")) -eq "Y")
{
Write-Host "Pick a name for the release branch, it should look something like release/1801/nuget-18013-180123"
Write-Host "That's release/[YY][MM]/nuget-[YY][MM][release # for this month]-[YY][MM][todays date]"
$branchName = Read-Host "Release branch name"
git checkout -b $choice
}
$gitChanges = $false;
Write-Host ""
Write-Host "Run localization?"
Write-Host ""
Write-Host "Remember, if you are adding new strings, you'll need to re-run localization (after the translations are done)"
Write-Host "to actually get the newly translated strings pulled back down into our project. Since we are releasing a new"
Write-Host "package every week-ish, this only matters if for some reason we add new/update strings in a release end-game,"
Write-Host "but just something to keep in mind!"
if ((GetAnswer("Y", "N")) -eq "Y")
{
RunLocalization($branchName);
$gitChanges = $true;
}
Write-Host "Time to update custom.props, usually you set the VersionMinor to the [YY][MM][release # for this month] of your branch name"
Write-Host "Update custom.props?"
if ((GetAnswer("Y", "N")) -eq "Y")
{
notepad custom.props
git add custom.props
$gitChanges = $true;
}
if ($gitChanges -eq $true)
{
git commit -m "Updated custom.props"
git push --set-upstream origin $branchName
}
Write-Host "Lock the branch? This will prevent further commits (including by future runs of this script)"
if ((GetAnswer("Y", "N")) -eq "Y")
{
Lock-Branch($branchName)
}
Write-Host "Create pull request to merge changes back to master?"
if ((GetAnswer("Y", "N")) -eq "Y")
{
Write-Host "You may be asked to install some nuget packages the first time you go through this flow"
New-BranchPullRequest($branchName); # rename function
$BranchPullRequests = Get-BranchPullRequests
if ($BranchPullRequests.count -eq 0)
{
Write-Error "Could not create pull request!"
exit 1
}
else
{
$pullRequest = $BranchPullRequests.value[0];
$pullRequestID = $pullRequest.pullRequestId;
$url = "https://microsoft.visualstudio.com/OS/OS%20Team/_git/dep.controls/pullrequest/$pullRequestID#_a=overview"
Write-Host "New pull request: $url"
Start-Process $url
}
}
Write-Host "Spin a new depcontrols_release build?"
if ((GetAnswer("Y", "N")) -eq "Y")
{
Queue-NewReleaseBuild($branchName);
}
Write-Host "---"
Write-Host ""
Write-Host "Remember go to https://microsoft.visualstudio.com/DefaultCollection/OS/ft_xamlcon/_git/dep.controls/branches and LOCK your new branch"
}
Elseif ($scriptAction -eq "2")
{
# Write-Host "NUYGETSFDASD"
}