forked from microsoft/security-devops-azdevops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate-BuildTaskVersion.ps1
More file actions
83 lines (66 loc) · 2.07 KB
/
Copy pathUpdate-BuildTaskVersion.ps1
File metadata and controls
83 lines (66 loc) · 2.07 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
# Copyright (c) Microsoft Corporation. All rights reserved.
Param
(
[Parameter(ParameterSetName="Major")]
[Parameter(ParameterSetName="Minor")]
[Parameter(ParameterSetName="Patch")]
[String] $FilePath,
[Parameter(ParameterSetName="Major")]
[Switch] $Major,
[Parameter(ParameterSetName="Minor")]
[Switch] $Minor,
[Parameter(ParameterSetName="Patch")]
[Switch] $Patch,
[Parameter(ParameterSetName="Major")]
[Parameter(ParameterSetName="Minor")]
[Parameter(ParameterSetName="Patch")]
[Int] $Count = 1
)
Write-Host "Upticking build task - $($FilePath)"
if ($Count -eq 0)
{
Write-Host "Count is 0. Skipping upticking task version: $($FilePath)"
return
}
if (-not $Major -and -not $Minor -and -not $Patch)
{
throw 'No version upticks requested.'
}
$lines = @()
$majorRegex = '(?<=\"Major\"\:\s*)(?<Version>\d+)'
$minorRegex = '(?<=\"Minor\"\:\s*)(?<Version>\d+)'
$patchRegex = '(?<=\"Patch\"\:\s*)(?<Version>\d+)'
$findMajor = $Major.IsPresent
$findMinor = $Major.IsPresent -or $Minor.IsPresent
$findPatch = $Major.IsPresent -or -$Minor.IsPresent -or $Patch.IsPresent
Get-Content -Path $FilePath | ForEach-Object {
$line = $_
if ($Major.IsPresent -and $line -imatch $majorRegex)
{
$version = [Int]$matches['Version'] += $Count
$line = $line -replace $majorRegex, $version
$findMajor = $false
}
elseif ($findMinor -and $line -imatch $minorRegex)
{
$version = 0
if ($Minor.IsPresent)
{
$version = [Int]$matches['Version'] += $Count
}
$line = $line -replace $minorRegex, $version
$findMinor = $false
}
elseif ($findPatch -and $line -imatch $patchRegex)
{
$version = 0
if ($Patch.IsPresent)
{
$version = [Int]$matches['Version'] += $Count
}
$line = $line -replace $patchRegex, $version
$findPatch = $false
}
$lines += $line
}
[System.IO.File]::WriteAllLines($FilePath, $lines)