Skip to content

Commit 40eee48

Browse files
Add ReleaseTrackingOnly option to Prepare-Release (Azure#20041)
Co-authored-by: Wes Haggard <[email protected]>
1 parent b29a93a commit 40eee48

File tree

4 files changed

+85
-29
lines changed

4 files changed

+85
-29
lines changed

eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,25 @@ function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $tr
163163

164164
$workItems = Invoke-AzBoardsCmd "query" $parameters $outputCommand
165165

166+
if ($workItems -and $workItems.Count -eq 1000) {
167+
Write-Warning "Retrieved the max of 1000 items so item list might not be complete."
168+
}
169+
166170
foreach ($wi in $workItems)
167171
{
168172
$localKey = BuildHashKeyNoNull $wi.fields["Custom.Language"] $wi.fields["Custom.Package"] $wi.fields["Custom.PackageVersionMajorMinor"]
169173
if (!$localKey) {
170174
$packageWorkItemWithoutKeyFields[$wi.id] = $wi
171175
Write-Host "Skipping package [$($wi.id)]$($wi.fields['System.Title']) which is missing required fields language, package, or version."
172-
continue
176+
continue
173177
}
174178
if ($packageWorkItems.ContainsKey($localKey) -and $packageWorkItems[$localKey].id -ne $wi.id) {
175179
Write-Warning "Already found package [$($packageWorkItems[$localKey].id)] with key [$localKey], using that one instead of [$($wi.id)]."
176180
}
177181
else {
178182
Write-Verbose "Caching package [$($wi.id)] for [$localKey]"
179183
$packageWorkItems[$localKey] = $wi
180-
}
184+
}
181185
}
182186

183187
if ($key -and $packageWorkItems.ContainsKey($key)) {
@@ -216,7 +220,7 @@ function UpdateWorkItemParent($childWorkItem, $parentWorkItem, $outputCommand =
216220

217221
function CreateWorkItemParent($id, $parentId, $oldParentId, $outputCommand = $true)
218222
{
219-
# Have to remove old parent first if you want to add a new parent.
223+
# Have to remove old parent first if you want to add a new parent.
220224
if ($oldParentId)
221225
{
222226
$parameters = $ReleaseDevOpsCommonParameters
@@ -287,7 +291,7 @@ function UpdateWorkItem($id, $fields, $title, $state, $assignedTo, $outputComman
287291

288292
function UpdatePackageWorkItemReleaseState($id, $state, $releaseType, $outputCommand = $true)
289293
{
290-
$fields = "`"Custom.ReleaseType=${releaseType}`""
294+
$fields = "`"Custom.ReleaseType=${releaseType}`""
291295
return UpdateWorkItem -id $id -state $state -fields $fields -outputCommand $outputCommand
292296
}
293297

@@ -399,10 +403,10 @@ function FindOrCreatePackageGroupParent($serviceName, $packageDisplayName, $outp
399403
$localKey = BuildHashKey $serviceName $packageDisplayName
400404
Write-Host "[$($workItem.id)]$localKey - Created Parent"
401405
$parentWorkItems[$localKey] = $workItem
402-
return $workItem
406+
return $workItem
403407
}
404408

405-
function FindOrCreateServiceParent($serviceName, $outputCommand = $true)
409+
function FindOrCreateServiceParent($serviceName, $outputCommand = $true)
406410
{
407411
$serviceParent = FindParentWorkItem $serviceName -outputCommand $outputCommand
408412
if ($serviceParent) {
@@ -733,7 +737,7 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions)
733737
{
734738
$versionSet[$version] = $plannedVersionSet[$version]
735739
}
736-
else
740+
else
737741
{
738742
# Looks like we shipped this version so remove it from the planned set
739743
$plannedVersionSet.Remove($version)
@@ -778,7 +782,7 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions)
778782

779783
# If no version files to update do nothing
780784
if ($fieldUpdates.Count -eq 0) {
781-
return
785+
return $pkgWorkItem
782786
}
783787

784788
$versionsForDebug = ($versionList | Foreach-Object { $_.Version }) -join ","
@@ -798,13 +802,14 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions)
798802
$encodedToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes([string]::Format("{0}:{1}", "", $devops_pat)))
799803
$headers = @{ Authorization = "Basic $encodedToken" }
800804
}
801-
else
805+
else
802806
{
803807
# Get a temp access token from the logged in az cli user for azure devops resource
804808
$jwt_accessToken = (az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv)
805809
$headers = @{ Authorization = "Bearer $jwt_accessToken" }
806810
}
807811
$response = Invoke-RestMethod -Method PATCH `
808812
-Uri "https://dev.azure.com/azure-sdk/_apis/wit/workitems/${id}?api-version=6.0" `
809-
-Headers $headers -Body $body -ContentType "application/json-patch+json"
813+
-Headers $headers -Body $body -ContentType "application/json-patch+json" | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashTable
814+
return $response
810815
}

eng/common/scripts/Package-Properties.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ function Get-PkgPropsForEntireService ($serviceDirectoryPath)
171171
function Get-ArtifactListFromYml ($ciYmlPath)
172172
{
173173
$ProgressPreference = "SilentlyContinue"
174-
if ((Get-PSRepository | ?{$_.Name -eq "PSGallery"}).Count -eq 0)
174+
if ((Get-PSRepository).Where({$_.Name -eq "PSGallery"}).Count -eq 0)
175175
{
176176
Register-PSRepository -Default -ErrorAction:SilentlyContinue
177177
}
178178

179-
if ((Get-Module -ListAvailable -Name powershell-yaml | ?{$_.Version -eq "0.4.2"}).Count -eq 0)
179+
if ((Get-Module -ListAvailable -Name powershell-yaml).Where({ $_.Version -eq "0.4.2"} ).Count -eq 0)
180180
{
181181
Install-Module -Name powershell-yaml -RequiredVersion 0.4.2 -Force -Scope CurrentUser
182182
}

eng/common/scripts/Prepare-Release.ps1

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
11
#Requires -Version 6.0
22

3+
<#
4+
.SYNOPSIS
5+
This script will do the necessary book keeping work needed to release a package.
6+
7+
.DESCRIPTION
8+
This script will do a number of things when ran:
9+
10+
- It will read the current version from the project and will have you confirm if that is the version you want to ship
11+
- It will take the package metadata and version and update the DevOps release tracking items with that information.
12+
- If there is existing release work item it will update it and if not it will create one.
13+
- It will validate that the changelog has a entry for the package version that you want to release as well as a timestamp.
14+
15+
.PARAMETER PackageName
16+
The full package name of the package you want to prepare for release. (i.e Azure.Core, azure-core, @azure/core-https)
17+
18+
.PARAMETER ServiceDirectory
19+
Optional: The service directory where the package lives (e.g. /sdk/<service directory>/<package>). If a service directory isn't provided the script
20+
will search for the package project by traversing all the packages under /sdk/, so the service directory is only a scoping mechanism.
21+
22+
.PARAMETER ReleaseDate
23+
Optional: If not shipping on the normal first Tuesday of the month you can specify a specific release date in the form of "MM/dd/yyyy".
24+
25+
.PARAMETER ReleaseTrackingOnly
26+
Optional: If this switch is passed then the script will only update the release work items and not update the versions in the local repo or validate the changelog.
27+
28+
.EXAMPLE
29+
PS> ./eng/common/scripts/Prepare-Release.ps1 <PackageName>
30+
31+
The most common usage is to call the script passing the package name. Once the script is finished then you will have modified project and change log files.
32+
You should make any additional changes to the change log to capture the changes and then submit the PR for the final changes before you do a release.
33+
34+
.EXAMPLE
35+
PS> ./eng/common/scripts/Prepare-Release.ps1 <PackageName> -ReleaseTrackingOnly
36+
37+
If you aren't ready to do the final versioning changes yet but you want to update release tracking information for shiproom pass in the -ReleaseTrackingOnly.
38+
option. This should not modify or validate anything in the repo but will update the DevOps release tracking items. Once you are ready for the verioning changes
39+
as well then come back and run the full script again without the -ReleaseTrackingOnly option and give it the same version information you did the first time.
40+
#>
341
[CmdletBinding()]
442
param(
543
[Parameter(Mandatory = $true)]
644
[string]$PackageName,
745
[string]$ServiceDirectory,
8-
[string]$ReleaseDate # Pass Date in the form MM/dd/yyyy"
46+
[string]$ReleaseDate, # Pass Date in the form MM/dd/yyyy"
47+
[switch]$ReleaseTrackingOnly = $false
948
)
1049
Set-StrictMode -Version 3
1150

@@ -27,6 +66,7 @@ function Get-ReleaseDay($baseDate)
2766

2867
$ErrorPreference = 'Stop'
2968

69+
$packageProperties = $null
3070
$packageProperties = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $ServiceDirectory
3171

3272
if (!$packageProperties)
@@ -87,6 +127,24 @@ if ($null -eq $newVersionParsed)
87127
exit 1
88128
}
89129

130+
&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 `
131+
-language $LanguageDisplayName `
132+
-packageName $packageProperties.Name `
133+
-version $newVersion `
134+
-plannedDate $releaseDateString `
135+
-packageRepoPath $packageProperties.serviceDirectory `
136+
-packageType $packageProperties.SDKType `
137+
-packageNewLibrary $packageProperties.IsNewSDK
138+
139+
if ($releaseTrackingOnly)
140+
{
141+
Write-Host
142+
Write-Host "Script is running in release tracking only mode so only updating the release tracker and not updating versions locally."
143+
Write-Host "You will need to run this script again once you are ready to update the versions to ensure the projects and changelogs contain the correct version."
144+
145+
exit 0
146+
}
147+
90148
if (Test-Path "Function:SetPackageVersion")
91149
{
92150
SetPackageVersion -PackageName $packageProperties.Name -Version $newVersion -ServiceDirectory $packageProperties.ServiceDirectory -ReleaseDate $releaseDateString `
@@ -100,19 +158,10 @@ else
100158
exit 1
101159
}
102160

103-
&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 `
104-
-language $LanguageDisplayName `
105-
-packageName $packageProperties.Name `
106-
-version $newVersion `
107-
-plannedDate $releaseDateString `
108-
-packageRepoPath $packageProperties.ServiceDirectory `
109-
-packageType $packageProperties.SDKType `
110-
-packageNewLibrary $packageProperties.IsNewSDK
111-
112161
git diff -s --exit-code $packageProperties.DirectoryPath
113162
if ($LASTEXITCODE -ne 0)
114163
{
115164
git status
116165
Write-Host "Some changes were made to the repo source" -ForegroundColor Green
117-
Write-Host "Submit a pull request with the necessary changes to the repo" -ForegroundColor Green
166+
Write-Host "Submit a pull request with the necessary changes to the repo, including any final changelog entry updates." -ForegroundColor Green
118167
}

eng/common/scripts/Update-DevOps-Release-WorkItem.ps1

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ param(
1515
[string]$packageNewLibrary = "true",
1616
[string]$devops_pat = $env:DEVOPS_PAT
1717
)
18+
#Requires -Version 6.0
1819
Set-StrictMode -Version 3
1920

20-
if (!(Get-Command az)) {
21+
if (!(Get-Command az -ErrorAction SilentlyContinue)) {
2122
Write-Host 'You must have the Azure CLI installed: https://aka.ms/azure-cli'
2223
exit 1
2324
}
2425

2526
az extension show -n azure-devops > $null
2627
if (!$?){
27-
Write-Host 'You must have the azure-devops extension run `az extension add --name azure-devops`'
28-
exit 1
28+
Write-Host 'Installing azure-devops extension'
29+
az extension add --name azure-devops
2930
}
3031

3132
. (Join-Path $PSScriptRoot SemVer.ps1)
@@ -90,7 +91,7 @@ if (!$workItem) {
9091
if (!$packageInfo.ServiceName) {
9192
Write-Host "We need a package service name to be used in various places and it should be consistent across languages for similar packages."
9293
while (($readInput = Read-Host -Prompt "Input the service name") -eq "") { }
93-
$packageInfo.ServiceName = $readInput
94+
$packageInfo.ServiceName = $readInput
9495
}
9596
Write-Host " ServiceName: $($packageInfo.ServiceName)"
9697
Write-Host " PackageType: $packageType"
@@ -104,5 +105,6 @@ if (!$workItem) {
104105
}
105106
Write-Host "Marking item [$($workItem.id)]$($workItem.fields['System.Title']) as '$state' for '$releaseType'"
106107
$updatedWI = UpdatePackageWorkItemReleaseState -id $workItem.id -state "In Release" -releaseType $releaseType -outputCommand $false
107-
UpdatePackageVersions $workItem -plannedVersions $plannedVersions
108-
Write-Host "https://dev.azure.com/azure-sdk/Release/_workitems/edit/$($updatedWI.id)/"
108+
$updatedWI = UpdatePackageVersions $workItem -plannedVersions $plannedVersions
109+
110+
Write-Host "Release tracking item is at https://dev.azure.com/azure-sdk/Release/_workitems/edit/$($updatedWI.id)/"

0 commit comments

Comments
 (0)