pacework 1.7.1 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/pacework-runner-ctl.mjs +61 -12
- package/bin/pacework-runner.mjs +5 -0
- package/lib/service.mjs +46 -0
- package/lib/version.mjs +13 -0
- package/package.json +1 -1
|
@@ -41,9 +41,12 @@ import {
|
|
|
41
41
|
installService,
|
|
42
42
|
installStableCopy,
|
|
43
43
|
installCommandLauncher,
|
|
44
|
+
installedServiceVersion,
|
|
44
45
|
isServiceInstalled,
|
|
45
46
|
isServiceRunning,
|
|
47
|
+
moveServiceTo,
|
|
46
48
|
privacyProtectedFolder,
|
|
49
|
+
serviceNeedsUpdate,
|
|
47
50
|
serviceKind,
|
|
48
51
|
startService,
|
|
49
52
|
stopService,
|
|
@@ -72,6 +75,57 @@ async function checkForUpdate() {
|
|
|
72
75
|
} catch {}
|
|
73
76
|
}
|
|
74
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Move the login service to this copy of the runner when it runs an older one.
|
|
80
|
+
* The service runs the stable copy `up` saved, so installing a new version or
|
|
81
|
+
* restarting used to leave it on the old runner (PWK-307). Returns true when it
|
|
82
|
+
* moved.
|
|
83
|
+
*/
|
|
84
|
+
function moveServiceToThisVersion() {
|
|
85
|
+
if (!isServiceInstalled() || !LOCAL_VERSION) return false
|
|
86
|
+
const running = installedServiceVersion()
|
|
87
|
+
if (!serviceNeedsUpdate(running, LOCAL_VERSION)) return false
|
|
88
|
+
console.log(` Moving the runner service from ${running ?? "an older copy"} to \x1b[1m${LOCAL_VERSION}\x1b[0m…`)
|
|
89
|
+
try {
|
|
90
|
+
moveServiceTo(path.resolve(__dirname, ".."), LOCAL_VERSION)
|
|
91
|
+
return true
|
|
92
|
+
} catch (err) {
|
|
93
|
+
console.error(` Could not move the runner service to ${LOCAL_VERSION}: ${err.message}`)
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* `pacework update`: install the newest published version and restart the
|
|
100
|
+
* runner on it. With nothing newer on npm, still move a service that runs an
|
|
101
|
+
* older copy than this one.
|
|
102
|
+
*/
|
|
103
|
+
async function updateRunner() {
|
|
104
|
+
console.log("Checking for updates…")
|
|
105
|
+
const latest = await latestPublishedVersion().catch(() => null)
|
|
106
|
+
if (!latest) {
|
|
107
|
+
console.log("\x1b[31mCould not reach npm registry.\x1b[0m")
|
|
108
|
+
return 1
|
|
109
|
+
}
|
|
110
|
+
if (!isNewerVersion(latest, LOCAL_VERSION)) {
|
|
111
|
+
console.log(`\x1b[32m✓\x1b[0m Already on latest (\x1b[1m${LOCAL_VERSION}\x1b[0m)`)
|
|
112
|
+
if (moveServiceToThisVersion()) console.log(`\x1b[32m✓\x1b[0m Runner service now runs ${LOCAL_VERSION}`)
|
|
113
|
+
return 0
|
|
114
|
+
}
|
|
115
|
+
console.log(`Updating ${LOCAL_VERSION} → \x1b[1m${latest}\x1b[0m…`)
|
|
116
|
+
const install = spawn("npm", ["install", "-g", `${NPM_PACKAGE}@${latest}`], { stdio: "inherit" })
|
|
117
|
+
const installed = await new Promise((resolve) => install.on("exit", (code) => resolve(code === 0)))
|
|
118
|
+
if (!installed) {
|
|
119
|
+
console.log("\x1b[31mnpm install failed; the runner keeps running the current version.\x1b[0m")
|
|
120
|
+
return 1
|
|
121
|
+
}
|
|
122
|
+
// This process is still the old version: restart through the new one, whose
|
|
123
|
+
// `start` moves the service to it.
|
|
124
|
+
console.log(`Restarting the runner on ${latest}…`)
|
|
125
|
+
const restart = spawn("npx", ["-y", `${NPM_PACKAGE}@${latest}`, "start"], { stdio: "inherit", env: process.env })
|
|
126
|
+
return await new Promise((resolve) => restart.on("exit", (code) => resolve(code ?? 1)))
|
|
127
|
+
}
|
|
128
|
+
|
|
75
129
|
// ── ascii banner ──────────────────────────────────────────────────────────────
|
|
76
130
|
|
|
77
131
|
const BANNER = `\x1b[38;5;39m${BANNER_LINES.map((line) => ` ${line}`).join("\n")}\x1b[0m`
|
|
@@ -279,6 +333,7 @@ ${row("pacework doctor", "Check this machine's setup")}
|
|
|
279
333
|
${row("pacework triage [--once]", "Only triage, in the foreground")}
|
|
280
334
|
${row("pacework up --token CODE", "One-step setup from the command in pacework's Runners page; asks for the runner's name and model")}
|
|
281
335
|
${row("pacework down", "Remove the background service")}
|
|
336
|
+
${row("pacework update", "Install the newest version and restart the runner on it")}
|
|
282
337
|
|
|
283
338
|
\x1b[1mRunner flags\x1b[0m ${d("for start, connect and up")}
|
|
284
339
|
--repo-root PATH --executor TOOL --name NAME --model ID --max-parallel-runs N --sandbox --no-triage
|
|
@@ -930,6 +985,7 @@ else if (command === "start") {
|
|
|
930
985
|
|
|
931
986
|
if (isServiceInstalled()) {
|
|
932
987
|
const logOffset = (() => { try { return fs.statSync(LOG_FILE).size } catch { return 0 } })()
|
|
988
|
+
moveServiceToThisVersion()
|
|
933
989
|
if (!isServiceRunning()) {
|
|
934
990
|
try { startService() } catch (err) { console.error(`Could not start the runner service: ${err.message}`); process.exit(1) }
|
|
935
991
|
}
|
|
@@ -1044,6 +1100,10 @@ run()
|
|
|
1044
1100
|
|
|
1045
1101
|
// ── stop ─────────────────────────────────────────────────────────────────────
|
|
1046
1102
|
|
|
1103
|
+
else if (command === "update") {
|
|
1104
|
+
process.exit(await updateRunner())
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1047
1107
|
else if (command === "stop") {
|
|
1048
1108
|
// With a login service, stop it first; otherwise it restarts the runner the
|
|
1049
1109
|
// moment the process below is killed.
|
|
@@ -2547,18 +2607,7 @@ else if (command === "shell" || command === "sh") {
|
|
|
2547
2607
|
break
|
|
2548
2608
|
}
|
|
2549
2609
|
case "update": {
|
|
2550
|
-
|
|
2551
|
-
try {
|
|
2552
|
-
const latest = await latestPublishedVersion()
|
|
2553
|
-
if (!latest) throw new Error("no version")
|
|
2554
|
-
if (!isNewerVersion(latest, LOCAL_VERSION)) {
|
|
2555
|
-
console.log(`\x1b[32m✓\x1b[0m Already on latest (\x1b[1m${LOCAL_VERSION}\x1b[0m)`)
|
|
2556
|
-
} else {
|
|
2557
|
-
console.log(`Updating ${LOCAL_VERSION} → \x1b[1m${latest}\x1b[0m…`)
|
|
2558
|
-
const child = spawn("npm", ["install", "-g", `${NPM_PACKAGE}@${latest}`], { stdio: "inherit" })
|
|
2559
|
-
await new Promise(r => child.on("exit", r))
|
|
2560
|
-
}
|
|
2561
|
-
} catch { console.log("\x1b[31mCould not reach npm registry.\x1b[0m") }
|
|
2610
|
+
await updateRunner()
|
|
2562
2611
|
break
|
|
2563
2612
|
}
|
|
2564
2613
|
case "login": {
|
package/bin/pacework-runner.mjs
CHANGED
|
@@ -33,6 +33,7 @@ import { AVAILABILITY_MODES, describeRegistration, isRevokedError, registrationC
|
|
|
33
33
|
import { describeTriageJob, runTriageLoop, TRIAGE_EXECUTORS } from "../lib/triage-worker.mjs"
|
|
34
34
|
import { automationDenyRules, automationLimits } from "../lib/automation-limits.mjs"
|
|
35
35
|
import { truncateSummary } from "../lib/summary-text.mjs"
|
|
36
|
+
import { RUNNER_VERSION } from "../lib/version.mjs"
|
|
36
37
|
|
|
37
38
|
function parseArgs(argv) {
|
|
38
39
|
const args = {}
|
|
@@ -966,6 +967,7 @@ async function registerRunner() {
|
|
|
966
967
|
local_executor: defaultExecutor,
|
|
967
968
|
labels,
|
|
968
969
|
max_parallel_runs: maxParallelRuns,
|
|
970
|
+
...(RUNNER_VERSION ? { version: RUNNER_VERSION } : {}),
|
|
969
971
|
...(homeTeam ? { home_team: homeTeam } : {}),
|
|
970
972
|
...(availabilityMode ? { availability_mode: availabilityMode } : {}),
|
|
971
973
|
capabilities: runnerCapabilities(),
|
|
@@ -1041,6 +1043,9 @@ async function heartbeat(state, status = "online") {
|
|
|
1041
1043
|
runner_id: state.runner_id,
|
|
1042
1044
|
status,
|
|
1043
1045
|
local_executors: installedExecutors,
|
|
1046
|
+
// Sent on every heartbeat, so the runner list shows the version a
|
|
1047
|
+
// runner is on now, not the one it registered with.
|
|
1048
|
+
...(RUNNER_VERSION ? { version: RUNNER_VERSION } : {}),
|
|
1044
1049
|
capabilities: runnerCapabilities(),
|
|
1045
1050
|
}),
|
|
1046
1051
|
})
|
package/lib/service.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import path from "node:path"
|
|
|
4
4
|
import process from "node:process"
|
|
5
5
|
import { execFileSync } from "node:child_process"
|
|
6
6
|
import { PACEWORK_DIR, LOG_FILE, USES_LEGACY_DIR } from "./control-state.mjs"
|
|
7
|
+
import { isNewerVersion } from "./version.mjs"
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Run the runner as an OS-managed login service, so it starts at login, restarts
|
|
@@ -230,6 +231,51 @@ WantedBy=default.target
|
|
|
230
231
|
return { kind, file }
|
|
231
232
|
}
|
|
232
233
|
|
|
234
|
+
/**
|
|
235
|
+
* The runner version a service file starts: the `<version>` in the stable copy's
|
|
236
|
+
* path, `.../runner-app/<version>/bin/pacework-runner-ctl.mjs`. Null when the
|
|
237
|
+
* file points somewhere else (an install from before stable copies).
|
|
238
|
+
*/
|
|
239
|
+
export function serviceVersionFromFile(text) {
|
|
240
|
+
const match = String(text || "").match(/runner-app[\\/]+([^\\/<"'\s]+)[\\/]+bin[\\/]+pacework-runner-ctl\.mjs/)
|
|
241
|
+
return match ? match[1] : null
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** The runner version the installed login service runs, or null when unknown or not installed. */
|
|
245
|
+
export function installedServiceVersion() {
|
|
246
|
+
const file = serviceFilePath()
|
|
247
|
+
if (!file) return null
|
|
248
|
+
try {
|
|
249
|
+
return serviceVersionFromFile(fs.readFileSync(file, "utf8"))
|
|
250
|
+
} catch {
|
|
251
|
+
return null
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Whether the service should move to `version`. It keeps running the copy `up`
|
|
257
|
+
* saved, so updating the package or restarting left it on the old runner
|
|
258
|
+
* (PWK-307). Never moves it back to an older version: an old copy in npx's
|
|
259
|
+
* cache must not downgrade a newer service.
|
|
260
|
+
*/
|
|
261
|
+
export function serviceNeedsUpdate(installedVersion, version) {
|
|
262
|
+
if (!version) return false
|
|
263
|
+
if (!installedVersion) return true
|
|
264
|
+
return isNewerVersion(version, installedVersion)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Point the login service at a stable copy of the package in `sourceRoot` and
|
|
269
|
+
* restart it from there. Returns the new control script's path.
|
|
270
|
+
*/
|
|
271
|
+
export function moveServiceTo(sourceRoot, version) {
|
|
272
|
+
stopService()
|
|
273
|
+
const ctlPath = installStableCopy(sourceRoot, version)
|
|
274
|
+
try { installCommandLauncher(ctlPath) } catch {}
|
|
275
|
+
installService({ ctlPath })
|
|
276
|
+
return ctlPath
|
|
277
|
+
}
|
|
278
|
+
|
|
233
279
|
/** Start an installed service that was stopped. */
|
|
234
280
|
export function startService() {
|
|
235
281
|
const kind = serviceKind()
|
package/lib/version.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import fs from "node:fs"
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* The CLI's own npm package. The update check and `pacework update` both use
|
|
3
5
|
* this name: they used to ask for "pacework-runner", a name nobody owns, so no
|
|
@@ -25,3 +27,14 @@ export async function latestPublishedVersion(fetchImpl = fetch) {
|
|
|
25
27
|
const { version } = await res.json()
|
|
26
28
|
return typeof version === "string" ? version : null
|
|
27
29
|
}
|
|
30
|
+
|
|
31
|
+
/** This package's own version, from its package.json; null when it cannot be read. */
|
|
32
|
+
export const RUNNER_VERSION = (() => {
|
|
33
|
+
try {
|
|
34
|
+
const raw = fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")
|
|
35
|
+
const version = JSON.parse(raw).version
|
|
36
|
+
return typeof version === "string" ? version : null
|
|
37
|
+
} catch {
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
})()
|