-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathgenerate-version.ps1
46 lines (34 loc) · 1.41 KB
/
generate-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
$ErrorActionPreference = "Stop"
$versionFile = "version.json"
$version = Get-Content -Raw (Join-Path $PSScriptRoot $versionFile) | ConvertFrom-Json -AsHashtable
$major = $version.Major
$minor = $version.Minor
$patch = $version.Patch
Write-Host "Current version: $major.$minor.$patch"
$versionString = "$major.$minor.$patch"
$tag = git tag | Where-Object { $_ -eq $versionString }
if ($tag) {
$commit = git rev-parse HEAD
$tagCommit = git rev-parse $tag
if ($commit -eq $tagCommit) {
Write-Host "Tag $tag already exists, but is on the current commit, allowing.."
}
else {
Write-Error "Tag $tag already exists, please increment the version number in version.json"
}
}
else {
Write-Host "Tag $versionString does not exist yet"
}
$targetFilename = Join-Path $PSScriptRoot "lua/tardis/libraries/libraries/libraries/sh_version_generated.lua"
$content = [System.Text.StringBuilder]::new()
$null = $content.AppendLine("-- AUTO GENERATED FILE - DO NOT EDIT --")
$null = $content.AppendLine("-- SOURCE FILE: $versionFile --")
$null = $content.AppendLine()
$null = $content.AppendLine("TARDIS.Version = {")
$null = $content.AppendLine(" Major = $major,")
$null = $content.AppendLine(" Minor = $minor,")
$null = $content.AppendLine(" Patch = $patch")
$null = $content.AppendLine("}")
Write-Host "Writing version to $targetFilename"
Set-Content -NoNewline -Path $targetFilename -Value $content