forked from jburzynski/TypeGen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-version.ps1
62 lines (48 loc) · 2.24 KB
/
update-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
if ($args.Length -eq 0)
{
Write-Host "examples:
./update-version increment # increments the minor version, i.e. the middle part of the version
./update-version 2.4.9 # changes the current version to 2.4.9"
exit
}
$versionRegex = "^\d+\.\d+\.\d+$"
$oldVersion = (Select-Xml //version "nuget\TypeGen.nuspec")[0].Node.InnerText
$oldVersionMajor = $oldVersion.Split(".")[0]
$oldVersionMinor = $oldVersion.Split(".")[1]
$newVersionMinor = ($oldVersionMinor -as [int]) + 1
$newVersion = if ($args -contains "increment") {"$($oldVersionMajor).$($newVersionMinor).0"} else {$args[0]}
if (-not ($newVersion -match $versionRegex)) {
Write-Host "Wrong version format. Should be: $($versionRegex)"
exit
}
# replace files' contents
$nuspecPath = "nuget\TypeGen.nuspec"
if (Test-Path $nuspecPath) {
(Get-Content $nuspecPath).Replace("<version>$($oldVersion)</version>", "<version>$($newVersion)</version>") | Set-Content $nuspecPath
}
$dotNetCliNuspecPath = "nuget-dotnetcli\dotnet-typegen.nuspec"
if (Test-Path $dotNetCliNuspecPath) {
(Get-Content $dotNetCliNuspecPath).Replace("<version>$($oldVersion)</version>", "<version>$($newVersion)</version>") | Set-Content $dotNetCliNuspecPath
#.Replace("id=""TypeGen"" version=""$($oldVersion)""", "id=""TypeGen"" version=""$($newVersion)""")
}
#$docsConfPath = "..\TypeGenDocs\source\conf.py"
#if (Test-Path $docsConfPath) {
# (Get-Content $docsConfPath).Replace("version = u'$($oldVersion)'", "version = u'$($newVersion)'") | Set-Content $docsConfPath
#}
$appConfigPath = "src\TypeGen\TypeGen.Cli\AppConfig.cs"
if (Test-Path $appConfigPath) {
(Get-Content $appConfigPath).Replace("Version => ""$($oldVersion)""", "Version => ""$($newVersion)""") | Set-Content $appConfigPath
}
$nugetUpdatePath = "nuget-update.ps1"
if (Test-Path $nugetUpdatePath) {
(Get-Content $nugetUpdatePath).Replace("TypeGen.$($oldVersion)", "TypeGen.$($newVersion)").Replace("dotnet-typegen.$($oldVersion)", "dotnet-typegen.$($newVersion)") | Set-Content $nugetUpdatePath
}
# remove old NuGet package
$oldNupkgPath = "nuget\TypeGen.$($oldVersion).nupkg"
if (Test-Path $oldNupkgPath) {
rm $oldNupkgPath
}
$oldDotNetCliNupkgPath = "nuget-dotnetcli\dotnet-typegen.$($oldVersion).nupkg"
if (Test-Path $oldDotNetCliNupkgPath) {
rm $oldDotNetCliNupkgPath
}