This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
prebuild.ps1
68 lines (54 loc) · 2.23 KB
/
prebuild.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
param(
[parameter(Mandatory=$true)] [string] $dir
)
function SetVersion ($file, $version) {
"Changing version in $file to $version"
$fileObject = get-item $file
#$fileObject.Set_IsReadOnly($False)
$sr = new-object System.IO.StreamReader( $file, [System.Text.Encoding]::GetEncoding("utf-8") )
$content = $sr.ReadToEnd()
$sr.Close()
$content = [Regex]::Replace($content, "(\d+)\.(\d+)\.(\d+)[\.(\d+)]*", $version);
$sw = new-object System.IO.StreamWriter( $file, $false, [System.Text.Encoding]::GetEncoding("utf-8") )
$sw.Write( $content )
$sw.Close()
#$fileObject.Set_IsReadOnly($True)
}
function GetVersion ($dir) {
#$info_files = Get-ChildItem $dir -Recurse -Include "AssemblyInfo.cs" | where { $_ -match 'ELS' }
$info_files = "$dir\src\Properties\AssemblyInfo.cs", "$dir\server\ELS-Server\Properties\AssemblyInfo.cs"
Write-Host "Getting version in" $info_files[0]
#$fileObject = get-item $info_files[0]
#$fileObject.Set_IsReadOnly($False)
$sr = new-object System.IO.StreamReader( $info_files[0], [System.Text.Encoding]::GetEncoding("utf-8") )
$content = $sr.ReadToEnd()
$sr.Close()
$content = [Regex]::Match($content, "(\d+)\.(\d+)\.(\d+)\.(\d+)*");
#Write-Host $content.Groups
$new = [int]$content.Groups[4].Value + 1
if ($new -eq 10000) {
$new = 0
$major = [int]$content.Groups[3].Value + 1
$content = [regex]::Replace($content, "(\d+)\.(\d+)\.(\d+)\.(\d+)*", '$1.$2.' + $major + '.' + $new)
return $content
}
$content = [regex]::Replace($content, "(\d+)\.(\d+)\.(\d+)\.(\d+)*", '$1.$2.$3.' + $new)
return $content
}
function setVersionInDir($dir, $version) {
if ($version -eq "") {
Write-Host "version not found"
exit 1
}
# Set the Assembly version
#$info_files = Get-ChildItem $dir -Recurse -Include "AssemblyInfo.cs" | where { $_ -match 'ELS' }
$info_files = "$dir\src\Properties\AssemblyInfo.cs", "$dir\server\ELS-Server\Properties\AssemblyInfo.cs", "$dir\src\fxmanifest.lua"
foreach ($file in $info_files) {
SetVersion $file $version
}
}
# First get tag from Git
#$dir = "./"
Write-Host $dir
$version = GetVersion $dir
setVersionInDir $dir $version