-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathset-version.ps1
More file actions
77 lines (60 loc) · 2.39 KB
/
set-version.ps1
File metadata and controls
77 lines (60 loc) · 2.39 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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
<#
.SYNOPSIS
Sets the version for the PET workspace and all crates.
.DESCRIPTION
Updates the workspace version in the root Cargo.toml. All sub-crates inherit
this version via `version.workspace = true`.
For nightly/pre-release builds, pass a pre-release suffix. The base version is
read from Cargo.toml automatically (or overridden with -Version). Use a
deterministic pipeline variable (e.g., Build.BuildId) as the suffix to ensure
all platform builds in the same pipeline run get the same version number.
.PARAMETER Version
Optional base SemVer version (e.g., "0.2.0"). If omitted, reads the current
version from the workspace Cargo.toml.
.PARAMETER Suffix
Optional pre-release suffix appended as "-<Suffix>" (e.g., "dev.12345").
For nightly builds, use the Azure Pipelines Build.BuildId to guarantee
all platforms in the same run get an identical version.
.EXAMPLE
# Stable release — explicit version
./set-version.ps1 -Version 1.0.0
.EXAMPLE
# Nightly build — reads base version from Cargo.toml, appends suffix
./set-version.ps1 -Suffix "dev.$(Build.BuildId)"
#>
param(
[Parameter(Mandatory = $false)]
[ValidatePattern('^\d+\.\d+\.\d+$')]
[string]$Version,
[Parameter(Mandatory = $false)]
[ValidatePattern('^[a-zA-Z0-9._-]+$')]
[string]$Suffix
)
$ErrorActionPreference = 'Stop'
$cargoToml = Join-Path $PSScriptRoot 'Cargo.toml'
$content = Get-Content $cargoToml -Raw
# NOTE: Assumes `version` is the first key after [workspace.package] header.
$pattern = '(?m)(^\[workspace\.package\]\s*\r?\nversion\s*=\s*)"([^"]*)"'
if ($content -notmatch $pattern) {
Write-Error "Could not find [workspace.package] version in $cargoToml"
exit 1
}
# Read current version from Cargo.toml if -Version not provided
if (-not $Version) {
$Version = $Matches[2]
# Strip any existing pre-release suffix to get the base version
$Version = ($Version -split '-')[0]
Write-Host "Read base version from Cargo.toml: $Version"
}
if ($Suffix) {
$fullVersion = "$Version-$Suffix"
} else {
$fullVersion = $Version
}
Write-Host "Setting PET version to: $fullVersion"
$content = $content -replace $pattern, "`${1}`"$fullVersion`""
Set-Content $cargoToml $content -NoNewline -Encoding utf8
Write-Host "Updated $cargoToml"
Write-Host "Version set to: $fullVersion"