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>
This commit is contained in:
63
update.ps1
63
update.ps1
@@ -1,35 +1,72 @@
|
||||
# GoMag Vending - Update Script
|
||||
# Ruleaza ca Administrator: .\update.ps1
|
||||
# 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)) {
|
||||
Write-Host "EROARE: $TokenFile nu exista!" -ForegroundColor Red
|
||||
Log "EROARE: $TokenFile nu exista!" "Red"
|
||||
exit 1
|
||||
}
|
||||
$token = (Get-Content $TokenFile -Raw).Trim()
|
||||
|
||||
# Git pull
|
||||
Write-Host "==> Git pull..." -ForegroundColor Cyan
|
||||
# Fetch remote
|
||||
Set-Location $RepoPath
|
||||
git -c credential.helper="" pull "https://gomag-vending:$token@gitea.romfast.ro/romfast/gomag-vending.git"
|
||||
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) {
|
||||
Write-Host "EROARE: git pull esuat!" -ForegroundColor Red
|
||||
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)
|
||||
Write-Host "==> Verificare dependinte..." -ForegroundColor Cyan
|
||||
& "$RepoPath\venv\Scripts\pip.exe" install -r "$RepoPath\api\requirements.txt" --quiet
|
||||
Log "==> Verificare dependinte..." "Cyan"
|
||||
& "$RepoPath\venv\Scripts\pip.exe" install -r "$RepoPath\api\requirements.txt" --quiet 2>&1 | Out-Null
|
||||
|
||||
# Restart serviciu
|
||||
Write-Host "==> Restart GoMagVending..." -ForegroundColor Cyan
|
||||
nssm restart GoMagVending
|
||||
Log "==> Restart GoMagVending..." "Cyan"
|
||||
nssm restart GoMagVending 2>&1 | Out-Null
|
||||
|
||||
Start-Sleep -Seconds 3
|
||||
$status = nssm status GoMagVending 2>&1
|
||||
Write-Host "Serviciu: $status" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Update complet! Acces: http://localhost/gomag/" -ForegroundColor Green
|
||||
Log "Serviciu: $status" "Green"
|
||||
Log "Update complet!" "Green"
|
||||
|
||||
Reference in New Issue
Block a user