Files
gomag-vending/update.ps1
Claude Agent 9ee61415cf feat(deploy): smart update script with skip-if-no-changes and silent mode
Only pulls and restarts the service when new commits exist.
Supports -Silent flag for Task Scheduler (logs to update.log).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 17:47:24 +00:00

73 lines
1.9 KiB
PowerShell

# GoMag Vending - Update Script
# Ruleaza interactiv: .\update.ps1
# Ruleaza din scheduler: .\update.ps1 -Silent
param(
[switch]$Silent
)
$RepoPath = "C:\gomag-vending"
$TokenFile = Join-Path $RepoPath ".gittoken"
$LogFile = Join-Path $RepoPath "update.log"
function Log($msg, $color = "White") {
$ts = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
if ($Silent) {
Add-Content -Path $LogFile -Value "$ts $msg"
} else {
Write-Host $msg -ForegroundColor $color
}
}
# Citire token
if (-not (Test-Path $TokenFile)) {
Log "EROARE: $TokenFile nu exista!" "Red"
exit 1
}
$token = (Get-Content $TokenFile -Raw).Trim()
# Fetch remote
Set-Location $RepoPath
git -c credential.helper="" fetch "https://gomag-vending:$token@gitea.romfast.ro/romfast/gomag-vending.git" main 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Log "EROARE: git fetch esuat!" "Red"
exit 1
}
# Compara local vs remote
$local = git rev-parse HEAD
$remote = git rev-parse FETCH_HEAD
if ($local -eq $remote) {
Log "Nicio actualizare disponibila." "Gray"
exit 0
}
# Exista update-uri
$commits = git log --oneline "$local..$remote"
Log "==> Update disponibil ($($commits.Count) commit-uri noi)" "Cyan"
if (-not $Silent) {
$commits | ForEach-Object { Write-Host " $_" -ForegroundColor DarkGray }
}
# Git pull
Log "==> Git pull..." "Cyan"
git -c credential.helper="" pull "https://gomag-vending:$token@gitea.romfast.ro/romfast/gomag-vending.git" 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Log "EROARE: git pull esuat!" "Red"
exit 1
}
# Pip install (daca s-au schimbat dependintele)
Log "==> Verificare dependinte..." "Cyan"
& "$RepoPath\venv\Scripts\pip.exe" install -r "$RepoPath\api\requirements.txt" --quiet 2>&1 | Out-Null
# Restart serviciu
Log "==> Restart GoMagVending..." "Cyan"
nssm restart GoMagVending 2>&1 | Out-Null
Start-Sleep -Seconds 3
$status = nssm status GoMagVending 2>&1
Log "Serviciu: $status" "Green"
Log "Update complet!" "Green"