forked from chroma-sdk/Colore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_version.ps1
87 lines (70 loc) · 2.27 KB
/
set_version.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
86
87
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True, Position=1)]
[int]$buildCounter,
[Parameter(Mandatory=$True, Position=2)]
[string]$branch
)
$prefix = 'refs/heads/'
$tagPrefix = 'refs/tags/'
$isTag = $False
$friendlyVersion = '0.0.0'
$buildNumber = "${friendlyVersion}.${buildCounter}"
if ($branch.StartsWith($prefix))
{
$branch = $branch.substring($prefix.length)
}
elseif ($branch.StartsWith($tagPrefix))
{
$branch = $branch.substring($tagPrefix.length)
$isTag = $True
}
Write-Host "Build counter: $buildCounter"
Write-Host "Branch: $branch"
if ($branch -eq 'master')
{
$friendlyVersion = '0.0.1'
$buildNumber = "${friendlyVersion}.${buildCounter}"
}
elseif ($branch -eq 'develop')
{
$friendlyVersion = '0.0.0'
$buildNumber = "${friendlyVersion}.${buildCounter}"
}
elseif ($branch -match "^v\d+\.\d+\.\d+$")
{
$isTag = $True
$friendlyVersion = $branch.substring(1)
$buildNumber = "${friendlyVersion}.${buildCounter}"
}
$infoVersion = $friendlyVersion
if (!$isTag)
{
$infoVersion = "${friendlyVersion}-${branch}"
}
Write-Host "##teamcity[buildNumber '$buildNumber']"
Write-Host "##teamcity[setParameter name='Version' value='$friendlyVersion']"
Write-Host "##teamcity[setParameter name='InfoVersion' value='$infoVersion']"
function Update-File
{
Param([String]$file)
Write-Host "Updating version in file $file"
(Get-Content $file) `
-replace '^\[assembly: AssemblyVersion.+$', "[assembly: AssemblyVersion(`"$friendlyVersion`")]" `
-replace '^\[assembly: AssemblyFileVersion.+$', "[assembly: AssemblyFileVersion(`"$buildNumber`")]" `
-replace '^\[assembly: AssemblyInformationalVersion.+$', "[assembly: AssemblyInformationalVersion(`"$infoVersion`")]" |
Out-File $file
}
function Update-NuSpec
{
Param([String]$file)
Write-Host "Updating Colore depend version in file $file"
(Get-Content $file) `
-replace 'COLORE_VERSION', "$friendlyVersion" |
Out-File $file
}
Update-File src/Corale.Colore/Properties/AssemblyInfo.cs
Update-File src/Corale.Colore.Wpf/Properties/AssemblyInfo.cs
Update-File src/Corale.Colore.WinForms/Properties/AssemblyInfo.cs
Update-NuSpec src/Corale.Colore.Wpf/Corale.Colore.Wpf.nuspec
Update-NuSpec src/Corale.Colore.WinForms/Corale.Colore.WinForms.nuspec