forked from microsoft/security-devops-azdevops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate-ExtensionVersion.ps1
More file actions
98 lines (75 loc) · 2.52 KB
/
Copy pathUpdate-ExtensionVersion.ps1
File metadata and controls
98 lines (75 loc) · 2.52 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Copyright (c) Microsoft Corporation. All rights reserved.
Param
(
[String] $FilePath,
[Switch] $Major,
[Switch] $Minor,
[Switch] $Patch,
[Switch] $Rev,
[Int] $Count = 1
)
if ($Count -eq 0)
{
Write-Host "Count is 0. Skipping upticking extension: $($FilePath)"
return
}
if (-not $Major -and -not $Minor -and -not $Patch -and -not $Rev)
{
throw 'No version upticks requested.'
}
$fileName = Split-Path -Path $FilePath -Leaf
Write-Host "Upticking extension - $($FilePath)"
$lines = @()
$versionPatchRegex = '(?<=\"version"\:\s*)\"(?<Major>\d+)\.(?<Minor>\d+)\.(?<Patch>\d+)\"'
$versionRevRegex = '(?<=\"version"\:\s*)\"(?<Major>\d+)\.(?<Minor>\d+)\.(?<Patch>\d+)\.(?<Rev>\d+)\"'
$findVersion = $true
Get-Content -Path $FilePath | ForEach-Object {
$line = $_
if ($findVersion)
{
$matchPatch = $line -match $versionPatchRegex
$matchRev = $line -match $versionRevRegex
if ($matchPatch -or $matchRev)
{
$majorVersion = [Int]$matches['Major']
$minorVersion = [Int]$matches['Minor']
$patchVersion = [Int]$matches['Patch']
$revVersion = [Int]$matches['Rev']
if ($Major)
{
$majorVersion += $Count
$minorVersion = 0
$patchVersion = 0
$revVersion = 0
}
if ($Minor)
{
$minorVersion += $Count
$patchVersion = 0
$revVersion = 0
}
if ($Patch)
{
$patchVersion += $Count
$revVersion = 0
}
if ($Rev -and $matchRev)
{
$revVersion += $Count
}
if ($matchRev)
{
$line = $line -replace $versionRevRegex, "`"$($majorVersion).$($minorVersion).$($patchVersion).$($revVersion)`""
Write-Host "Updated version: $($majorVersion).$($minorVersion).$($patchVersion).$($revVersion)"
}
else
{
$line = $line -replace $versionPatchRegex, "`"$($majorVersion).$($minorVersion).$($patchVersion)`""
Write-Host "Updated version: $($majorVersion).$($minorVersion).$($patchVersion)"
}
$findVersion = $false
}
}
$lines += $line
}
$lines | Out-File -FilePath $FilePath -Encoding 'UTF8'