- Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathCalculateNewProductionVersion.ps1
65 lines (49 loc) · 2.34 KB
/
CalculateNewProductionVersion.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
Param(
[string]$owner,
[string]$repo,
[string]$previewStr
)
Write-Host"Calculating new Production Version:"-ForegroundColor Magenta;
$newVersionStr;
$releasesUrl="https://api.github.com/repos/$($owner)/$($repo)/releases";
Write-Host"Getting list of releases with '$($releasesUrl)'"-ForegroundColor Blue;
$releasesJSON=Invoke-RestMethod-Uri $releasesUrl-Method Get;
if ($releasesJSON.Count-eq0) {
Write-Host"Unable to get releases list with '$($releasesUrl)'"-ForegroundColor Red;
Write-Host"NOTE: This Script cannot handle the first release"-ForegroundColor Cyan;
EXIT1;
}
$latestReleaseJSON=$releasesJSON[0];
$latestReleaseVersionStr=$latestReleaseJSON.tag_name;
$isPreRelease=$latestReleaseJSON.prerelease;
if ([string]::IsNullOrEmpty($latestReleaseVersionStr)) {
Write-Host"Unable read the latest release tag name"-ForegroundColor Red;
Write-Host"Latest Release Data:"-ForegroundColor Cyan;
Write-Host-Object $latestReleaseJSON-ForegroundColor Cyan;
EXIT1;
}
if ([string]::IsNullOrEmpty($isPreRelease)) {
Write-Host"Unable read the latest release is pre-release or not"-ForegroundColor Red;
Write-Host"Latest Release Data:"-ForegroundColor Cyan;
Write-Host-Object $latestReleaseJSON-ForegroundColor Cyan;
EXIT1;
}
$isPreRelease=$isPreRelease-as [bool];
if (!$isPreRelease) {
Write-Host"Preview is not released for the latest changes in '$($branchName)' branch"-ForegroundColor Red;
Write-Host"Latest Release Data:"-ForegroundColor Cyan;
Write-Host-Object $latestReleaseJSON-ForegroundColor Cyan;
EXIT1;
}
$versionArr=$latestReleaseVersionStr.split("-");
if ([string]::IsNullOrEmpty($versionArr[1])) {
Write-Host"Latest release is a Preview release but the '$($previewStr)' is missing in version string $($latestReleaseVersionStr)"-ForegroundColor Red;
Write-Host"Latest Release Data:"-ForegroundColor Cyan;
Write-Host-Object $latestReleaseJSON-ForegroundColor Cyan;
EXIT1;
}
$newVersionStr=$versionArr[0];
Write-Host"Current version is '$($latestReleaseVersionStr)'"-ForegroundColor Blue;
Write-Host"New calculated version is '$($newVersionStr)'"-ForegroundColor Green;
Write-Host"##vso[task.setvariable variable=NEW_VERSION_STRING]$($newVersionStr)";
Write-Host"Updated new version in global variable"-ForegroundColor Green;