-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set-AppVersion.ps1
44 lines (40 loc) · 1.35 KB
/
Set-AppVersion.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
param(
[Parameter(Mandatory = $true)]
[string]
$BuildDate,
[Parameter(Mandatory = $true)]
[string]
$GitRef
)
# Ignore for the refs portion, and just get the important information.
If ($GitRef.StartsWith('refs/heads/')) {
$GitRef = $GitRef.Substring(11)
}
If ($GitRef.StartsWith('refs/tags/')) {
$GitRef = $GitRef.Substring(10)
}
# Update the code file for easy access to the information.
$Path = Join-Path $PSScriptRoot 'src/Tetrominoes/AppVersion.cs'
$Content = Get-Content -Raw -Path $Path
$Content = $Content.Replace('DateTime.UtcNow.ToString("O")', "`"${BuildDate}`"")
$Content = $Content.Replace('GitRef = "local"', "GitRef = `"${GitRef}`"")
$Content | Set-Content -Path $Path
# When the git ref is a version, make sure the
# binaries are also tagged with that version.
$Version = $null
If ([System.Version]::TryParse($GitRef, [ref]$Version)) {
# Hacky way of setting version, should probably be done
# through dotnet cli instead, but lazy.
$Projects = @(
'src/Tetrominoes/Tetrominoes.csproj',
'src/Tetrominoes.OpenGL/Tetrominoes.OpenGL.csproj'
)
$Projects | ForEach-Object {
$Content = Get-Content -Raw -Path $_
$Content = $Content.Replace(
'<Version>0.0.0</Version>',
"<Version>${Version}</Version>"
)
$Content | Set-Content -Path $_
}
}