CI : Update agent from web
Some checks failed
release / build (push) Successful in 27s
release / verify-windows (push) Failing after 59s

This commit is contained in:
jeanotx32
2026-08-11 20:16:08 +02:00
parent 4f7b8f56ae
commit 6916ff4be3
8 changed files with 217 additions and 9 deletions

View File

@@ -129,6 +129,16 @@ if ($isUpgrade) {
}
$applied = @()
# Toujours rafraîchie : ce n'est pas de l'identité, c'est de l'infrastructure.
# Sans elle, l'agent ne saurait pas où chercher sa propre mise à jour.
if ($current.PSObject.Properties.Name -notcontains 'packageUrl') {
$current | Add-Member -NotePropertyName packageUrl -NotePropertyValue $url -Force
$applied += 'packageUrl'
} elseif ($current.packageUrl -ne $url) {
$current.packageUrl = $url
$applied += 'packageUrl'
}
if ($PSBoundParameters.ContainsKey('Server')) { $current.serverUrl = $Server; $applied += 'serverUrl' }
if ($PSBoundParameters.ContainsKey('Name')) { $current.name = $Name; $applied += 'name' }
if ($PSBoundParameters.ContainsKey('ObsHost')) { $current.obs.host = $ObsHost; $applied += 'obs.host' }
@@ -151,10 +161,11 @@ if ($isUpgrade) {
Info 'Configuration mise à jour, identité de l''agent préservée'
} else {
$config = [ordered]@{
serverUrl = $Server
token = $Token
name = $Name
obs = [ordered]@{ host = $ObsHost; port = $ObsPort; password = $ObsPassword }
serverUrl = $Server
token = $Token
name = $Name
packageUrl = $url
obs = [ordered]@{ host = $ObsHost; port = $ObsPort; password = $ObsPassword }
}
# Surtout pas Set-Content -Encoding UTF8 : sous PowerShell 5.1 il préfixe un
# BOM, et JSON.parse côté Node refuse le fichier.

View File

@@ -185,12 +185,19 @@ if [ "$IS_UPGRADE" = true ]; then
node -e '
const fs = require("node:fs");
const a = process.argv.slice(1);
const [file, serverUrl, name, obsHost, obsPort, pwFlag, obsPassword, resetFlag, token] = a;
const [file, serverUrl, name, obsHost, obsPort, pwFlag, obsPassword, resetFlag, token, packageUrl] = a;
const current = JSON.parse(fs.readFileSync(file, "utf8").replace(/^\uFEFF/, ""));
const next = { ...current, obs: { ...(current.obs || {}) } };
const applied = [];
// Toujours rafraichie : infrastructure et non identite. Sans elle, un agent
// ne saurait pas ou chercher sa propre mise a jour.
// (Pas d apostrophe dans ce bloc : il vit dans une chaine bash entre quotes.)
if (packageUrl && packageUrl !== current.packageUrl) {
next.packageUrl = packageUrl;
applied.push("packageUrl");
}
if (serverUrl) { next.serverUrl = serverUrl; applied.push("serverUrl"); }
if (name) { next.name = name; applied.push("name"); }
if (obsHost) { next.obs.host = obsHost; applied.push("obs.host"); }
@@ -210,7 +217,7 @@ console.log(applied.length
? " champs mis à jour : " + applied.join(", ")
: " aucun changement demandé");
' "$CONFIG_FILE" "$SERVER_URL" "$AGENT_NAME" "$OBS_HOST" "$OBS_PORT" \
"$PW_FLAG" "$OBS_PASSWORD" "$RESET_FLAG" "$TOKEN" \
"$PW_FLAG" "$OBS_PASSWORD" "$RESET_FLAG" "$TOKEN" "$URL" \
|| die "Fusion de la configuration existante impossible ($CONFIG_FILE)."
info "Configuration mise à jour, identité de l'agent préservée"
@@ -221,6 +228,7 @@ else
"serverUrl": "$SERVER_URL",
"token": "$TOKEN",
"name": "$AGENT_NAME",
"packageUrl": "$URL",
"obs": {
"host": "$OBS_HOST",
"port": $OBS_PORT,