Skip to content

Commit 246c477

Browse files
mattocklstipakov
authored andcommitted
windows-msi: introduce a Powershell script for bumping version.m4
This is required for providing Windows snapshot packages Signed-off-by: Samuli Seppänen <samuli@openvpn.net>
1 parent f83f21e commit 246c477

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

windows-msi/bump-version.m4.ps1

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Change PRODUCT_CODE and PRODUCT_VERSION in version.m4. Primarily intended to
2+
# be used within a CI system, not for release builds.
3+
4+
<#
5+
.Description
6+
Get the current value of PRODUCT_VERSION in version.m4. This is needed so that we can increment it. Example: 2.5.028.
7+
#>
8+
Function Get-ProductVersion {
9+
ForEach ($line in (Get-Content version.m4)) {
10+
if ($line -match '^define\(\[PRODUCT_VERSION\], \[(.*?)\]\)') {
11+
$ProductVersion = $Matches[1]
12+
break
13+
}
14+
}
15+
16+
$ProductVersion
17+
}
18+
19+
<#
20+
.Description
21+
Increment the last digit in PRODUCTION_VERSION. Only used internally.
22+
#>
23+
Function Increment-Counter {
24+
param (
25+
[string]$Counter
26+
)
27+
28+
# String off leading zeroes, if any
29+
$Counter = $Counter -replace '^0+', ''
30+
$IntCounter = [int]$Counter
31+
$IntCounter += 1
32+
$Counter = [string]$IntCounter
33+
34+
# Add back leading zeroes, if any
35+
$Counter = $Counter.PadLeft(3, '0')
36+
$Counter
37+
}
38+
39+
<#
40+
.Description
41+
Create an incremented PRODUCT_VERSION (e.g. 2.5.029).
42+
#>
43+
Function New-ProductVersion {
44+
$OldProductVersion = (Get-ProductVersion) -match '(\d\.\d?)\.(\d\d\d?)'
45+
$Version = $Matches[1]
46+
$Counter = $Matches[2]
47+
$Counter = Increment-Counter -Counter $Counter
48+
"${Version}.${Counter}"
49+
}
50+
51+
# Get updated values for PRODUCT_VERSION and PRODUCT_CODE
52+
$NewProductVersion = New-ProductVersion
53+
$NewProductCode = (New-Guid).ToString().ToUpper()
54+
55+
# Replace old values with the newly generated ones, overwriting version.m4
56+
$version_m4 = (Get-Content version.m4)
57+
$version_m4 -replace '^define\(\[PRODUCT_CODE\], \[\{(?<ProductCode>.*)\}]\)', "define([PRODUCT_CODE], [{${NewProductCode}}])" `
58+
-replace '^define\(\[PRODUCT_VERSION\], \[(.*?)\]\)', "define([PRODUCT_VERSION], [${NewProductVersion}])" | Out-File -Encoding ASCII version.m4

0 commit comments

Comments
 (0)