This repository has been archived on 2023-02-13. You can view files and clone it, but cannot push or open issues or pull requests.
gswi-server/gswi/update-version.ps1

53 lines
1.3 KiB
PowerShell
Raw Normal View History

2022-02-20 19:04:11 +01:00
#! /snap/bin/pwsh
function Get-VersionFromBranch {
$branch = git rev-parse --abbrev-ref HEAD
$versions = $branch.Split('.')
$major = "0"
$minor = "0"
$micro = "0"
if ($versions.Count -gt 0) {
$major = $versions[0]
}
if ($versions.Count -gt 1) {
$minor = $versions[1]
}
if ($versions.Count -gt 2) {
$micro = $versions[2]
}
return $major, $minor, $micro
}
function Get-VersionAsJSON([string]$major, [string]$minor, [string]$micro) {
return @{
"Major" = "$major"
"Minor" = "$minor"
"Micro" = "$micro"
} | ConvertTo-Json
}
function Get-AppsettingsAsJSON() {
return Get-Content -Raw -Path "./appsettings.json" | ConvertFrom-Json
}
function Set-AppsettingsAsJSON($settings) {
$settings | ConvertTo-Json | Out-File "./appsettings.json"
}
function Set-VersionFromBranch([string]$major, [string]$minor, [string]$micro) {
$versionJSON = Get-VersionAsJSON $major $minor $micro
$appsettings = Get-AppsettingsAsJSON
$appsettings.API.ApiVersion.Major = $major
$appsettings.API.ApiVersion.Minor = $minor
$appsettings.API.ApiVersion.Micro = $micro
Set-AppsettingsAsJSON $appsettings
}
$res = Get-VersionFromBranch
Set-VersionFromBranch $res[0] $res[1] $res[2]