82 lines
2.4 KiB
PowerShell
82 lines
2.4 KiB
PowerShell
param(
|
|
[Parameter(Mandatory = $true, Position = 0)]
|
|
[string]$Version
|
|
)
|
|
|
|
function Test-VersionFormat {
|
|
param([string]$Ver)
|
|
$pattern = '^\d+\.\d+\.\d+(?:-[a-zA-Z0-9]+)?$'
|
|
return $Ver -match $pattern
|
|
}
|
|
|
|
function Update-FileVersion {
|
|
param(
|
|
[string]$FilePath,
|
|
[string]$Pattern,
|
|
[string]$NewVersion
|
|
)
|
|
try {
|
|
$content = Get-Content -Path $FilePath -Raw
|
|
$newContent = $content -replace $Pattern, $NewVersion
|
|
if ($content -eq $newContent) {
|
|
Write-Host "[OK] $(Split-Path -Leaf $FilePath) already up-to-date" -ForegroundColor Green
|
|
return $true
|
|
}
|
|
Set-Content -Path $FilePath -Value $newContent -NoNewline
|
|
Write-Host "[OK] Updated $(Split-Path -Leaf $FilePath)" -ForegroundColor Green
|
|
return $true
|
|
}
|
|
catch {
|
|
Write-Host "[ERROR] Error: $_" -ForegroundColor Red
|
|
return $false
|
|
}
|
|
}
|
|
|
|
if (-not (Test-VersionFormat $Version)) {
|
|
Write-Host "[ERROR] Invalid version format: $Version" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
$projectRoot = Split-Path -Parent $PSCommandPath
|
|
$pyprojectPath = Join-Path $projectRoot "pyproject.toml"
|
|
$initPath = Join-Path (Join-Path $projectRoot "agravity_client") "__init__.py"
|
|
|
|
Write-Host "======================================================================"
|
|
Write-Host "Updating Agravity Client to version $Version"
|
|
Write-Host "======================================================================"
|
|
|
|
$success = $true
|
|
|
|
if (Test-Path $pyprojectPath) {
|
|
$pattern = 'version = "[^"]+"'
|
|
$newVersion = "version = `"$Version`""
|
|
if (-not (Update-FileVersion $pyprojectPath $pattern $newVersion)) {
|
|
$success = $false
|
|
}
|
|
}
|
|
else {
|
|
Write-Host "[ERROR] pyproject.toml not found" -ForegroundColor Red
|
|
$success = $false
|
|
}
|
|
|
|
if (Test-Path $initPath) {
|
|
$pattern = '__version__ = "[^"]+"'
|
|
$newVersion = "__version__ = `"$Version`""
|
|
if (-not (Update-FileVersion $initPath $pattern $newVersion)) {
|
|
$success = $false
|
|
}
|
|
}
|
|
else {
|
|
Write-Host "[ERROR] init file not found" -ForegroundColor Red
|
|
$success = $false
|
|
}
|
|
|
|
Write-Host "======================================================================"
|
|
if ($success) {
|
|
Write-Host "[OK] Version successfully updated to $Version" -ForegroundColor Green
|
|
exit 0
|
|
}
|
|
else {
|
|
Write-Host "[ERROR] Update completed with errors" -ForegroundColor Red
|
|
exit 1
|
|
}
|