40 lines
1.5 KiB
PowerShell
40 lines
1.5 KiB
PowerShell
<#
|
|||
|
|
.SYNOPSIS
|
||
|
|
Actualiza el proyecto a una versión (etiqueta de git) y reinicia el servicio. Sirve también para volver a una
|
||
|
|
versión anterior (rollback). Ejecutar en PowerShell como administrador.
|
||
|
|
|
||
|
|
.EXAMPLE
|
||
|
|
.\deploy\actualizar.ps1 -Version v1.2.0
|
||
|
|
.\deploy\actualizar.ps1 -Version v1.1.0 # volver a la anterior
|
||
|
|
#>
|
||
|
|
param(
|
||
|
|
[Parameter(Mandatory = $true)][string]$Version,
|
||
|
|
[string]$Nombre = "descarga_factura_transporte",
|
||
|
|
[string]$Nssm = "nssm"
|
||
|
|
)
|
||
|
|
|
||
|
|
$ErrorActionPreference = "Stop"
|
||
|
|
$Proyecto = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
|
||
|
|
Set-Location $Proyecto
|
||
|
|
|
||
|
|
if (git status --porcelain --untracked-files=no) {
|
||
|
|
throw "Hay cambios locales sin guardar en $Proyecto. Revíselos (git status) antes de actualizar."
|
||
|
|
}
|
||
|
|
|
||
|
|
function Comprobar($paso) { if ($LASTEXITCODE -ne 0) { throw "Falló: $paso (código $LASTEXITCODE)" } }
|
||
|
|
|
||
|
|
git fetch --tags origin
|
||
|
|
Comprobar "git fetch"
|
||
|
|
if (-not (git tag --list $Version)) { throw "No existe la etiqueta $Version. Etiquetas disponibles: $(git tag --list | Out-String)" }
|
||
|
|
|
||
|
|
& $Nssm stop $Nombre confirm | Out-Null
|
||
|
|
try {
|
||
|
|
git checkout $Version
|
||
|
|
Comprobar "git checkout $Version"
|
||
|
|
& (Join-Path $Proyecto "venv\Scripts\python.exe") -m pip install -r requirements.txt
|
||
|
|
Comprobar "pip install"
|
||
|
|
} finally {
|
||
|
|
& $Nssm start $Nombre | Out-Null # arranca siempre: si algo falló, vuelve a levantar lo que había
|
||
|
|
}
|
||
|
|
Write-Host "Servicio '$Nombre' en la versión $Version."
|
||
|
|
Write-Host "Compruebe la versión en el log: Select-String 'versión' logs\descarga_factura_transporte.log | Select-Object -Last 1"
|