-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_version.ps1
57 lines (43 loc) · 1.66 KB
/
read_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
<#
.DESCRIPTION
Script to read project version from Directory.Build.props file
.EXAMPLE
./script.ps1 -b "Directory.Build.props" -docker-continious-tag "latest"
.OUTPUTS
tuple: versionPrefix, versionSuffix, buildVersion, dockerTag
.LINK
https://github.com/Gigas002/dotnet_gh_deploy
#>
[CmdletBinding(PositionalBinding = $false)]
param (
# Directory.Build.props path
[Parameter ()]
[ValidateNotNullOrEmpty ()]
[Alias("b", "build-props-path")]
[string] $buildPropsPath = "Directory.Build.props",
# docker continious tag
[Parameter ()]
[ValidateNotNullOrEmpty ()]
[Alias("docker-continious-tag")]
[string] $dockerContiniousTag = "latest"
)
#region Constants
Set-Variable VersionPrefixPath -Option ReadOnly -Value "/Project/PropertyGroup/VersionPrefix"
Set-Variable VersionSuffixPath -Option ReadOnly -Value "/Project/PropertyGroup/VersionSuffix"
Set-Variable AssemblyVersionPath -Option ReadOnly -Value "/Project/PropertyGroup/AssemblyVersion"
#endregion
#region Read version
$versionPrefix = (Select-Xml -Path $buildPropsPath -XPath $VersionPrefixPath).Node.InnerText
$versionSuffix = (Select-Xml -Path $buildPropsPath -XPath $VersionSuffixPath).Node.InnerText
$assemblyVersion = (Select-Xml -Path $buildPropsPath -XPath $AssemblyVersionPath).Node.InnerText
$buildVersion = $assemblyVersion.Split('.')[-1]
$dockerTag = ""
if ("$versionSuffix") {
$dockerTag = "$dockerContiniousTag"
}
else {
$dockerTag = "v$versionPrefix"
}
#endregion
Write-Host "prefix: $versionPrefix, suffix: $versionSuffix, build: $buildVersion, docker: $dockerTag" -ForegroundColor Yellow
return $versionPrefix, $versionSuffix, $buildVersion, $dockerTag