-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReleaseFlow.ps1
85 lines (67 loc) · 3.21 KB
/
ReleaseFlow.ps1
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
param(
[string]$PipeBuildNumber,
[string]$PipeSourceBranch,
[string]$PipeSourceVersion,
[string]$PipeTargetBranch,
[string]$PipeBuildId
)
write-host "The build number is: $PipeBuildNumber"
$numParts = "$PipeBuildNumber".Split('.')
$datePart = $numParts[0].PadLeft(8, '0')
$buildNoPart = $numParts[1].PadLeft(4, '0')
$patchNumber = $datePart + $buildNoPart
$buildNumber = "$PipeBuildNumber"
$parts = $buildNumber.Split('.')
$major = $parts[0].Substring(0,4)
$minor = $parts[0].Substring(4,2)
$patch = $parts[0].Substring(6,2)
$build = $parts[1]
$mainVersion = "0.0.$PipeBuildId" + "-build"
Write-Host "Version number for main: $mainVersion"
write-host "The build number formatted is: $patchNumber"
write-host "The source branch is: $PipeSourceBranch"
write-host "This is the commit id using the pre-defined variable Build.SourceVersion: $PipeSourceVersion"
if ("$PipeSourceBranch" -like "*/pull/*"){
write-host "Source Branch should be pull here: $PipeSourceBranch"
write-host "Target Branch of the PR should be: $PipeTargetBranch"
if ("$PipeTargetBranch" -eq "main"){
write-host "PR target is main branch. Setting currentBranch to refs/heads/main"
write-host "##vso[task.setvariable variable=currentBranch]refs/heads/main"
# git fetch --tags
# $tag = git describe --tags $(git rev-list --tags --max-count=1 --no-walk $PipeSourceVersion)
# Write-Host "Tag: $tag"
write-host "##vso[task.setvariable variable=versionNo]$mainVersion"
}
elseif ("$PipeTargetBranch" -like "releases/*"){
write-host "PR target is a release branch. Setting currentBranch to refs/heads/$PipeTargetBranch"
write-host "##vso[task.setvariable variable=currentBranch]refs/heads/$PipeTargetBranch"
$path = "refs/heads/$PipeTargetBranch"
$version = Split-Path $path -Leaf
Write-Host $version
write-host "##vso[task.setvariable variable=versionNo]$version.$build"
}
}
elseif ("$PipeSourceBranch" -like "*/releases/*"){
write-host "Source Branch should be releases here: $PipeSourceBranch"
write-host "##vso[task.setvariable variable=currentBranch]$PipeSourceBranch"
$path = "$PipeSourceBranch"
$version = Split-Path $path -Leaf
Write-Host $version
write-host "##vso[task.setvariable variable=versionNo]$version.$build"
}
elseif ("$PipeSourceBranch" -like "*/tags/release-*"){
write-host "Source Branch should be tags here: $PipeSourceBranch"
#$branch = Invoke-Expression "git branch -r --contains $(Build.SourceBranch)"
$path = "$PipeSourceBranch"
$version = Split-Path $path -Leaf
Write-Host $version
$releaseVersion = "$version".Replace("release-", "")
$releaseBranch = "refs/heads/releases/$releaseVersion"
write-host "##vso[task.setvariable variable=currentBranch]$releaseBranch"
write-host "##vso[task.setvariable variable=versionNo]$releaseVersion"
}
elseif ("$PipeSourceBranch" -like "*/main"){
write-host "Source Branch should be main here: $PipeSourceBranch"
write-host "##vso[task.setvariable variable=currentBranch]$PipeSourceBranch"
write-host "##vso[task.setvariable variable=versionNo]$mainVersion"
}