...
1#Requires -Version 6.0
2
3<#
4.SYNOPSIS
5This script will do the necessary book keeping work needed to release a package.
6
7.DESCRIPTION
8This 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
15For more information see https://aka.ms/azsdk/mark-release-status.
16
17.PARAMETER PackageName
18The full package name of the package you want to prepare for release. (i.e Azure.Core, azure-core, @azure/core-https)
19
20.PARAMETER ServiceDirectory
21Optional: Provide a service directory to scope the search of the entire repo to speed-up the project search. This should be the directory
22name under the 'sdk' folder (i.e for the core package which lives under 'sdk\core' the value to pass would be 'core').
23
24.PARAMETER ReleaseDate
25Optional: Provide a specific date for when you plan to release the package. Should be the date (MM/dd/yyyy) that the given package is going to ship.
26If one isn't provided, then it will compute the next ship date or today's date if past the ship date for the month as the planned date.
27
28.PARAMETER ReleaseTrackingOnly
29Optional: 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.
30
31.EXAMPLE
32PS> ./eng/common/scripts/Prepare-Release.ps1 <PackageName>
33
34The 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.
35You 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.
36
37.EXAMPLE
38PS> ./eng/common/scripts/Prepare-Release.ps1 <PackageName> -ReleaseTrackingOnly
39
40If 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.
41option. 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
42as 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.
43#>
44[CmdletBinding()]
45param(
46 [Parameter(Mandatory = $true)]
47 [string]$PackageName,
48 [string]$ServiceDirectory,
49 [string]$ReleaseDate, # Pass Date in the form MM/dd/yyyy"
50 [switch]$ReleaseTrackingOnly = $false
51)
52Set-StrictMode -Version 3
53
54. ${PSScriptRoot}\common.ps1
55. ${PSScriptRoot}\Helpers\ApiView-Helpers.ps1
56
57function Get-ReleaseDay($baseDate)
58{
59 # Find first friday
60 while ($baseDate.DayOfWeek -ne 5)
61 {
62 $baseDate = $baseDate.AddDays(1)
63 }
64
65 # Go to Tuesday
66 $baseDate = $baseDate.AddDays(4)
67
68 return $baseDate;
69}
70
71$ErrorPreference = 'Stop'
72
73$packageProperties = $null
74$packageProperties = Get-PkgProperties -PackageName $PackageName -ServiceDirectory $ServiceDirectory
75
76if (!$packageProperties)
77{
78 Write-Error "Could not find a package with name [ $packageName ], please verify the package name matches the exact name."
79 exit 1
80}
81
82Write-Host "Package Name [ $($packageProperties.Name) ]"
83Write-Host "Source directory [ $($packageProperties.ServiceDirectory) ]"
84
85if (!$ReleaseDate)
86{
87 $currentDate = Get-Date
88 $thisMonthReleaseDate = Get-ReleaseDay((Get-Date -Day 1));
89 $nextMonthReleaseDate = Get-ReleaseDay((Get-Date -Day 1).AddMonths(1));
90
91 if ($thisMonthReleaseDate -ge $currentDate)
92 {
93 # On track for this month release
94 $ParsedReleaseDate = $thisMonthReleaseDate
95 }
96 elseif ($currentDate.Day -lt 15)
97 {
98 # Catching up to this month release
99 $ParsedReleaseDate = $currentDate
100 }
101 else
102 {
103 # Next month release
104 $ParsedReleaseDate = $nextMonthReleaseDate
105 }
106}
107else
108{
109 $ParsedReleaseDate = [datetime]$ReleaseDate
110}
111
112$releaseDateString = $ParsedReleaseDate.ToString("MM/dd/yyyy")
113$month = $ParsedReleaseDate.ToString("MMMM")
114
115Write-Host "Assuming release is in $month with release date $releaseDateString" -ForegroundColor Green
116if (Test-Path "Function:GetExistingPackageVersions")
117{
118 $releasedVersions = GetExistingPackageVersions -PackageName $packageProperties.Name -GroupId $packageProperties.Group
119 if ($null -ne $releasedVersions -and $releasedVersions.Count -gt 0)
120 {
121 $latestReleasedVersion = $releasedVersions[$releasedVersions.Count - 1]
122 Write-Host "Latest released version: ${latestReleasedVersion}" -ForegroundColor Green
123 }
124}
125
126$currentProjectVersion = $packageProperties.Version
127$newVersion = Read-Host -Prompt "Input the new version, or press Enter to use use current project version '$currentProjectVersion'"
128
129if (!$newVersion)
130{
131 $newVersion = $currentProjectVersion;
132}
133
134$newVersionParsed = [AzureEngSemanticVersion]::ParseVersionString($newVersion)
135if ($null -eq $newVersionParsed)
136{
137 Write-Error "Invalid version $newVersion. Version must follow standard SemVer rules, see https://aka.ms/azsdk/engsys/packageversioning"
138 exit 1
139}
140
141&$EngCommonScriptsDir/Update-DevOps-Release-WorkItem.ps1 `
142 -language $LanguageDisplayName `
143 -packageName $packageProperties.Name `
144 -version $newVersion `
145 -plannedDate $releaseDateString `
146 -packageRepoPath $packageProperties.serviceDirectory `
147 -packageType $packageProperties.SDKType `
148 -packageNewLibrary $packageProperties.IsNewSDK
149
150if ($LASTEXITCODE -ne 0) {
151 Write-Error "Updating of the Devops Release WorkItem failed."
152 exit 1
153}
154
155# Check API status if version is GA
156if (!$newVersionParsed.IsPrerelease)
157{
158 try
159 {
160 az account show *> $null
161 if (!$?) {
162 Write-Host 'Running az login...'
163 az login *> $null
164 }
165 $url = az keyvault secret show --name "APIURL" --vault-name "AzureSDKPrepRelease-KV" --query "value" --output "tsv"
166 $apiKey = az keyvault secret show --name "APIKEY" --vault-name "AzureSDKPrepRelease-KV" --query "value" --output "tsv"
167 Check-ApiReviewStatus -PackageName $packageProperties.Name -packageVersion $newVersion -Language $LanguageDisplayName -url $url -apiKey $apiKey
168 }
169 catch
170 {
171 Write-Warning "Failed to get APIView URL and API Key from Keyvault AzureSDKPrepRelease-KV. Please check and ensure you have access to this Keyvault as reader."
172 }
173}
174
175if ($releaseTrackingOnly)
176{
177 Write-Host
178 Write-Host "Script is running in release tracking only mode so only updating the release tracker and not updating versions locally."
179 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."
180
181 exit 0
182}
183
184if (Test-Path "Function:SetPackageVersion")
185{
186 $replaceLatestEntryTitle = $true
187 $latestVersion = Get-LatestReleaseDateFromChangeLog -ChangeLogLocation $packageProperties.ChangeLogPath
188 if ($latestVersion)
189 {
190 $promptMessage = "The latest entry in the CHANGELOG.md already has a release date. Do you want to replace the latest entry title? Please enter (y or n)."
191 while (($readInput = Read-Host -Prompt $promptMessage) -notmatch '^[yn]$'){ }
192 $replaceLatestEntryTitle = ($readInput -eq "y")
193 }
194 SetPackageVersion -PackageName $packageProperties.Name -Version $newVersion `
195 -ServiceDirectory $packageProperties.ServiceDirectory -ReleaseDate $releaseDateString `
196 -PackageProperties $packageProperties -ReplaceLatestEntryTitle $replaceLatestEntryTitle
197}
198else
199{
200 LogError "The function 'SetPackageVersion' was not found.`
201 Make sure it is present in eng/scripts/Language-Settings.ps1.`
202 See https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/common_engsys.md#code-structure"
203 exit 1
204}
205
206$changelogIsValid = Confirm-ChangeLogEntry -ChangeLogLocation $packageProperties.ChangeLogPath -VersionString $newVersion -ForRelease $true -SantizeEntry
207
208if (!$changelogIsValid)
209{
210 Write-Warning "The changelog [$($packageProperties.ChangeLogPath)] is not valid for release. Please make sure it is valid before queuing release build."
211}
212
213git diff -s --exit-code $packageProperties.DirectoryPath
214if ($LASTEXITCODE -ne 0)
215{
216 git status
217 Write-Host "Some changes were made to the repo source" -ForegroundColor Green
218 Write-Host "Submit a pull request with the necessary changes to the repo, including any final changelog entry updates." -ForegroundColor Green
219}
View as plain text