-
Notifications
You must be signed in to change notification settings - Fork 5
/
set_appveyor_version.ps1
88 lines (78 loc) · 2.72 KB
/
set_appveyor_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
88
#$env:APPVEYOR_REPO_TAG = "false"
#$env:APPVEYOR_REPO_TAG_NAME = "1.2.0"
#$env:APPVEYOR_BUILD_NUMBER = "1"
#$env:APPVEYOR_PULL_REQUEST_NUMBER = ""
#$env:APPVEYOR_REPO_BRANCH = "dfd f"
#$env:CONFIGURATION = "Release"
#$env:APPVEYOR_BUILD_VERSION = "1.0.0.1"
function getVersion() {
$version = $env:APPVEYOR_BUILD_VERSION;
$buildNumber = $env:APPVEYOR_BUILD_NUMBER;
if ($version -match "^[1-9]+(\.[0-9]+){3}$")
{
$versionParts = $version.Split(".");
$version = $versionParts[0] + "." + $versionParts[1] + "." + $versionParts[2] + "-alpha-" + $versionParts[3];
}
elseif ($version -match "^[1-9]+(\.[0-9]+){2}$")
{
$version = $version + "-alpha-" + $buildNumber;
}
$dbgSuffix = If ($env:CONFIGURATION -eq "Debug") { "-dbg" } else { "" };
if ($env:APPVEYOR_REPO_TAG -eq "true")
{
if ($env:APPVEYOR_REPO_TAG_NAME -match "^[1-9]+(\.[0-9]+){3}$")
{
$versionParts = $env:APPVEYOR_REPO_TAG_NAME.Split(".");
$mainVersion = $versionParts[0] + "." + $versionParts[1] + "." + $versionParts[2] + "-" + $versionParts[3];
$packageVersion = $mainVersion + "-" + $buildNumber;
}
elseif ($env:APPVEYOR_REPO_TAG_NAME -match "^[1-9]+(\.[0-9]+){2}-")
{
$packageVersion = $env:APPVEYOR_REPO_TAG_NAME + "-" + $buildNumber;
}
elseif ($env:APPVEYOR_REPO_TAG_NAME -match "^[1-9]+(\.[0-9]+){2}$")
{
$packageVersion = $env:APPVEYOR_REPO_TAG_NAME;
}
else
{
$packageVersion = $version + "-" + $env:APPVEYOR_REPO_TAG_NAME;
}
}
else
{
$branch = $env:APPVEYOR_REPO_BRANCH;
$noPR = [string]::IsNullOrEmpty($env:APPVEYOR_PULL_REQUEST_NUMBER);
if ($branch -eq "master" -And $noPR)
{
$packageVersion = $version + $dbgSuffix;
}
else
{
$suffix = "-ci" + $dbgSuffix;
if (!$noPR)
{
$suffix += "-pr-" + $env:APPVEYOR_PULL_REQUEST_NUMBER;
}
elseif ($branch.StartsWith("release", "CurrentCultureIgnoreCase"))
{
$suffix += "-pre";
}
else
{
$safeBranch = $branch -replace "[^0-9A-Za-z-]+", ""
$suffix += "-" + $safeBranch;
}
# Nuget limits "special version part" to 20 chars. Add one for the hyphen.
if ($suffix.Length -gt 21)
{
$suffix = $suffix.Substring(0, 21);
}
$packageVersion = $version + $suffix;
}
}
return $packageVersion;
}
$version = getVersion
echo "Build version: $version"
Update-AppveyorBuild -Version $version