- WPF + WinRT BLE controller for ELK-BLEDOM compatible LED strips - Multi-device control, effects, grayscale and temperature modes - Velopack updates via Gitea Releases, Gitea Actions CI
68 lines
2.5 KiB
PowerShell
68 lines
2.5 KiB
PowerShell
[CmdletBinding(DefaultParameterSetName = "Patch")]
|
|
param(
|
|
[Parameter(Mandatory = $true, ParameterSetName = "Major")]
|
|
[switch]$Major,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = "Minor")]
|
|
[switch]$Minor,
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName = "Patch")]
|
|
[switch]$Patch,
|
|
|
|
[string]$Project = "src/RgbLedStripController/RgbLedStripController.csproj"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
Set-StrictMode -Version Latest
|
|
|
|
$repoRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\.."))
|
|
$projectPath = if ([System.IO.Path]::IsPathRooted($Project)) {
|
|
$Project
|
|
} else {
|
|
Join-Path $repoRoot $Project
|
|
}
|
|
|
|
$projectPath = [System.IO.Path]::GetFullPath($projectPath)
|
|
if (-not (Test-Path -LiteralPath $projectPath)) {
|
|
throw "Project file not found: $projectPath"
|
|
}
|
|
|
|
$content = Get-Content -Raw -LiteralPath $projectPath
|
|
$versionMatch = [System.Text.RegularExpressions.Regex]::Match($content, "<Version>(?<value>\d+\.\d+\.\d+)</Version>")
|
|
if (-not $versionMatch.Success) {
|
|
throw "No semantic <Version> value found in project file: $projectPath"
|
|
}
|
|
|
|
$currentVersion = $versionMatch.Groups["value"].Value
|
|
$parts = $currentVersion.Split(".") | ForEach-Object { [int]$_ }
|
|
|
|
$newVersion = switch ($PSCmdlet.ParameterSetName) {
|
|
"Major" { "{0}.0.0" -f ($parts[0] + 1) }
|
|
"Minor" { "{0}.{1}.0" -f $parts[0], ($parts[1] + 1) }
|
|
default { "{0}.{1}.{2}" -f $parts[0], $parts[1], ($parts[2] + 1) }
|
|
}
|
|
|
|
$newAssemblyVersion = "$newVersion.0"
|
|
|
|
function Replace-FirstMatch {
|
|
param(
|
|
[string]$Text,
|
|
[string]$Pattern,
|
|
[string]$Replacement
|
|
)
|
|
|
|
$regex = [System.Text.RegularExpressions.Regex]::new($Pattern)
|
|
return $regex.Replace($Text, $Replacement, 1)
|
|
}
|
|
|
|
$content = Replace-FirstMatch $content "<Version>[^<]+</Version>" "<Version>$newVersion</Version>"
|
|
$content = Replace-FirstMatch $content "<AssemblyVersion>[^<]+</AssemblyVersion>" "<AssemblyVersion>$newAssemblyVersion</AssemblyVersion>"
|
|
$content = Replace-FirstMatch $content "<FileVersion>[^<]+</FileVersion>" "<FileVersion>$newAssemblyVersion</FileVersion>"
|
|
$content = Replace-FirstMatch $content "<InformationalVersion>[^<]+</InformationalVersion>" "<InformationalVersion>$newVersion</InformationalVersion>"
|
|
|
|
$utf8NoBom = [System.Text.UTF8Encoding]::new($false)
|
|
[System.IO.File]::WriteAllText($projectPath, $content, $utf8NoBom)
|
|
|
|
Write-Host ("Version updated: {0} -> {1}" -f $currentVersion, $newVersion) -ForegroundColor Green
|
|
Write-Host ("Project file: {0}" -f $projectPath)
|