|
12 | 12 | The published SqlServer version is needed when SqlServer is not built because downstream |
13 | 13 | SqlClient projects restore that existing package from NuGet. |
14 | 14 |
|
15 | | - The supplied revision is mapped to the range 1 through 65535 before canonical versions |
16 | | - are evaluated so every file version has a valid fourth component. When AddRevision is true, that |
17 | | - same mapped value is inserted as the fourth numeric component of package versions built during |
18 | | - this run. Any prerelease suffix remains after the revision. For example, 1.2.3-preview1 with |
19 | | - revision 165500 becomes package version 1.2.3.34430-preview1 and file version 1.2.3.34430. |
| 15 | + Two mutually exclusive package version shapes are supported: |
| 16 | +
|
| 17 | + When AddRevision is true, BuildNumber is ignored if specified. For non-preview releases, versions |
| 18 | + will be 1.2.3.<revision>. For preview releases, versions will be 1.2.3.<revision>-previewX. |
| 19 | +
|
| 20 | + When AddRevision is false, BuildNumber must be specified. Non-preview versions will be 1.2.3, and |
| 21 | + preview releases will be 1.2.3-previewX.<build_number>. |
| 22 | +
|
| 23 | + This asymmetry maintains the existing package versioning practice where previews include a |
| 24 | + date-coded build number, but normal releases do not. |
| 25 | +
|
| 26 | + File versions are always four-part and always carry a build number in the fourth component, even |
| 27 | + when the package version does not: |
| 28 | +
|
| 29 | + - AddRevision true. The fourth component is the mapped revision, so package and file versions |
| 30 | + agree. A package version of 1.2.3.34430-preview1 has file version 1.2.3.34430. |
| 31 | +
|
| 32 | + - AddRevision false. The fourth component is the first segment of BuildNumber. A package |
| 33 | + version of 1.2.3-preview1.26238.3 has file version 1.2.3.26238, and a stable package version |
| 34 | + of 1.2.3 still has file version 1.2.3.26238. This keeps every file version date-encoded and |
| 35 | + traceable back to the run that produced it. |
20 | 36 |
|
21 | | - Revisions above 65535 wrap through the valid unsigned 16-bit file-version range. The script logs |
| 37 | + The supplied revision is mapped to the range 1 through 65535 before canonical versions |
| 38 | + are evaluated so every file version has a valid fourth component. Revisions above 65535 wrap |
| 39 | + through the valid unsigned 16-bit file-version range. When AddRevision is true the script logs |
22 | 40 | the mapping because the revision may then collide with an earlier run. An unbuilt SqlServer |
23 | | - package is never revised because its effective version must continue to identify the package |
24 | | - that already exists on NuGet. |
| 41 | + package is never revised or stamped with a build number because its effective version must |
| 42 | + continue to identify the package that already exists on NuGet. |
25 | 43 |
|
26 | 44 | The script emits these output variables for downstream stages: |
27 | 45 | - VersionRevision |
|
33 | 51 |
|
34 | 52 | .PARAMETER Revision |
35 | 53 | Positive integer used to distinguish versions. Values above 65535 are wrapped into the unsigned |
36 | | - 16-bit revision range. |
| 54 | + 16-bit revision range. Only consumed when AddRevision is true. |
| 55 | +
|
| 56 | +.PARAMETER BuildNumber |
| 57 | + Pipeline build number in the form <date>.<run>, such as 26238.3. Required when AddRevision is |
| 58 | + false, and ignored when AddRevision is true. When required, it is appended to prerelease package |
| 59 | + versions and its first segment becomes the file-version build number, so file versions remain |
| 60 | + date-encoded. |
37 | 61 |
|
38 | 62 | .PARAMETER BuildSqlServer |
39 | 63 | Whether this run builds Microsoft.SqlServer.Server. When false, the effective SqlServer package |
|
47 | 71 | dotnet executable to invoke. Defaults to the dotnet command resolved from PATH. This parameter |
48 | 72 | primarily supports isolated testing and specialized agent configurations. |
49 | 73 |
|
| 74 | +.EXAMPLE |
| 75 | + ./compute-versions.ps1 ` |
| 76 | + -ProjectPath ./build.proj ` |
| 77 | + -Revision 165500 ` |
| 78 | + -BuildNumber 26238.3 ` |
| 79 | + -BuildSqlServer $true ` |
| 80 | + -AddRevision $false |
| 81 | +
|
| 82 | + Computes versions for an official-style run that builds SqlServer. Prerelease package versions |
| 83 | + become 7.1.0-preview3.26238.3 and file versions become 7.1.0.26238. |
| 84 | +
|
50 | 85 | .EXAMPLE |
51 | 86 | ./compute-versions.ps1 ` |
52 | 87 | -ProjectPath ./build.proj ` |
|
55 | 90 | -AddRevision $true |
56 | 91 |
|
57 | 92 | Computes versions for a run that builds SqlServer and appends mapped revision 34430 to both |
58 | | - package families and their file versions. |
| 93 | + package families and their file versions. BuildNumber is not supplied because AddRevision is |
| 94 | + true. |
59 | 95 |
|
60 | 96 | .EXAMPLE |
61 | 97 | ./compute-versions.ps1 ` |
@@ -83,6 +119,10 @@ param( |
83 | 119 | [ValidateRange(1, [long]::MaxValue)] |
84 | 120 | [long]$Revision, |
85 | 121 |
|
| 122 | + [Parameter(HelpMessage = "Pipeline build number, such as 26238.3. Required when AddRevision is false.")] |
| 123 | + [ValidatePattern("^$|^\d+\.\d+$")] |
| 124 | + [string]$BuildNumber = "", |
| 125 | + |
86 | 126 | [Parameter(Mandatory = $true, HelpMessage = "Whether Microsoft.SqlServer.Server is built in this run.")] |
87 | 127 | [bool]$BuildSqlServer, |
88 | 128 |
|
@@ -98,7 +138,7 @@ Set-StrictMode -Version Latest |
98 | 138 | $ErrorActionPreference = "Stop" |
99 | 139 |
|
100 | 140 | $wrappedRevision = (($Revision - 1) % 65535) + 1 |
101 | | -if ($Revision -gt 65535) { |
| 141 | +if ($AddRevision -and $Revision -gt 65535) { |
102 | 142 | Write-Host "Revision $Revision exceeds the unsigned 16-bit limit and wrapped to $wrappedRevision; this revision may collide with an earlier run." |
103 | 143 | } |
104 | 144 |
|
@@ -196,6 +236,43 @@ function Add-VersionRevision { |
196 | 236 | return $versionWithRevision |
197 | 237 | } |
198 | 238 |
|
| 239 | +<# |
| 240 | +.SYNOPSIS |
| 241 | + Appends a pipeline build number to a prerelease package version. |
| 242 | +
|
| 243 | +.DESCRIPTION |
| 244 | + Reproduces the version shape used by earlier previews, where the build number follows the |
| 245 | + prerelease suffix, such as 7.1.0-preview3.26238.3. Stable versions are returned unchanged |
| 246 | + because released packages are not stamped with a build number. |
| 247 | +
|
| 248 | +.PARAMETER Version |
| 249 | + Package version with a three-part numeric base and optional prerelease suffix. |
| 250 | +
|
| 251 | +.PARAMETER BuildNumber |
| 252 | + Pipeline build number to append. |
| 253 | +
|
| 254 | +.OUTPUTS |
| 255 | + The package version with the build number appended to its prerelease suffix, or the original |
| 256 | + version when it carries no prerelease suffix. |
| 257 | +#> |
| 258 | +function Add-VersionBuildNumber { |
| 259 | + param( |
| 260 | + [string]$Version, |
| 261 | + [string]$BuildNumber |
| 262 | + ) |
| 263 | + |
| 264 | + $parts = $Version -split "-", 2 |
| 265 | + if ($parts[0] -notmatch "^\d+\.\d+\.\d+$") { |
| 266 | + throw "Expected a three-part numeric version base, but received '$Version'." |
| 267 | + } |
| 268 | + |
| 269 | + if ($parts.Count -eq 2) { |
| 270 | + return "$($parts[0])-$($parts[1]).$BuildNumber" |
| 271 | + } |
| 272 | + |
| 273 | + return $Version |
| 274 | +} |
| 275 | + |
199 | 276 | <# |
200 | 277 | .SYNOPSIS |
201 | 278 | Emits an Azure DevOps job output variable for consumption by downstream stages. |
@@ -232,6 +309,8 @@ $sqlServerPackageVersion = if ($BuildSqlServer) { |
232 | 309 | $sqlServerVersions.PublishedVersion |
233 | 310 | } |
234 | 311 |
|
| 312 | +$fileVersionBuildNumber = $null |
| 313 | + |
235 | 314 | if ($AddRevision) { |
236 | 315 | $sqlClientPackageVersion = Add-VersionRevision ` |
237 | 316 | -Version $sqlClientPackageVersion ` |
@@ -242,13 +321,34 @@ if ($AddRevision) { |
242 | 321 | -Revision $wrappedRevision |
243 | 322 | } |
244 | 323 |
|
| 324 | + # The revision is already the fourth component of the package version, so it is also the |
| 325 | + # file-version build number. |
| 326 | + $fileVersionBuildNumber = $wrappedRevision |
245 | 327 | Write-Host "Version revision: $wrappedRevision (input=$Revision)" |
246 | 328 | } |
| 329 | +else { |
| 330 | + if ([string]::IsNullOrWhiteSpace($BuildNumber)) { |
| 331 | + throw "BuildNumber is required when AddRevision is false." |
| 332 | + } |
| 333 | + |
| 334 | + $fileVersionBuildNumber = $BuildNumber.Split(".")[0] |
| 335 | + |
| 336 | + $sqlClientPackageVersion = Add-VersionBuildNumber ` |
| 337 | + -Version $sqlClientPackageVersion ` |
| 338 | + -BuildNumber $BuildNumber |
| 339 | + if ($BuildSqlServer) { |
| 340 | + $sqlServerPackageVersion = Add-VersionBuildNumber ` |
| 341 | + -Version $sqlServerPackageVersion ` |
| 342 | + -BuildNumber $BuildNumber |
| 343 | + } |
| 344 | + |
| 345 | + Write-Host "Version build number: $BuildNumber (file version build number=$fileVersionBuildNumber)" |
| 346 | +} |
247 | 347 |
|
248 | 348 | Write-Host "Effective versions:" |
249 | 349 | Write-Host " SqlClient (family): $sqlClientPackageVersion" |
250 | 350 | Write-Host " SqlServer: $sqlServerPackageVersion" |
251 | 351 |
|
252 | 352 | Set-PipelineOutputVariable -Name "SqlClientPackageVersion" -Value $sqlClientPackageVersion |
253 | 353 | Set-PipelineOutputVariable -Name "SqlServerPackageVersion" -Value $sqlServerPackageVersion |
254 | | -Set-PipelineOutputVariable -Name "VersionRevision" -Value $wrappedRevision |
| 354 | +Set-PipelineOutputVariable -Name "VersionRevision" -Value $fileVersionBuildNumber |