relayrunner 0.10.1 → 0.11.0

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.
Files changed (3) hide show
  1. package/README.md +9 -1
  2. package/dist/cli.js +129 -34
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -40,6 +40,13 @@ resume it without going offline (see `relayrunner pause`). The terminal tab's
40
40
  title shows the machine and what it's doing, such as
41
41
  `RelayRunner · M3P0 · Waiting for jobs`.
42
42
 
43
+ `connect` installs the latest GitHub runner when it starts. While it stays
44
+ open, it checks for a newer one every 6 hours, waiting until no job is running,
45
+ or going ahead after a busy day. New jobs run on the new runner, and a job
46
+ that's already running finishes on the one it started with. GitHub stops
47
+ sending jobs to a runner about 30 days after a newer release, so a machine left
48
+ connected for weeks keeps taking jobs.
49
+
43
50
  Before it starts a job, `connect` checks the job's runner config: it must hold
44
51
  only the files GitHub's do, every server in it must be GitHub's, over https, and
45
52
  the runner must be named for that job. Anything else is refused and reported as
@@ -89,7 +96,8 @@ approved the machine also gets an email, since someone else may have its token.
89
96
  - `--no-isolated` runs jobs on the Mac itself, where they can read your
90
97
  files. `--isolated` stops with an error when jobs can't run in VMs.
91
98
  - `connect` removes the images it downloaded or built for older runner
92
- versions. It never removes images you got yourself.
99
+ versions. It never removes images you got yourself. With `--image`, the
100
+ VMs keep your image when a newer runner comes out.
93
101
  - `~/.relayrunner/isolated.log` records each `container` command and its
94
102
  result, never a job's output or credentials. Send it along when you report
95
103
  a problem.
package/dist/cli.js CHANGED
@@ -64,7 +64,8 @@ const StatusMessage = z.object({
64
64
  v: version$1,
65
65
  type: z.literal("status"),
66
66
  state: z.enum(["idle", "busy"]),
67
- running: z.number().int().nonnegative().max(1e3).optional()
67
+ running: z.number().int().nonnegative().max(1e3).optional(),
68
+ runnerVersion: z.string().min(1).optional()
68
69
  });
69
70
  const JobUsage = z.object({
70
71
  cpuP95: z.number().min(0).max(1),
@@ -184,7 +185,7 @@ function parse(version) {
184
185
  ] : null;
185
186
  }
186
187
  // version.ts
187
- const cliVersion = "0.10.1";
188
+ const cliVersion = "0.11.0";
188
189
  // paths.ts
189
190
  function relayrunnerHome() {
190
191
  return resolve(process.env.RELAYRUNNER_HOME || join(homedir(), ".relayrunner"));
@@ -221,12 +222,20 @@ async function connect(options) {
221
222
  if (socket?.readyState === WebSocket.OPEN) socket.send(encodeMessage(message));
222
223
  else if (message.type === "job") pending.push(message);
223
224
  };
224
- const sendStatus = () => send({
225
- v: 1,
226
- type: "status",
227
- state: busy.size > 0 ? "busy" : "idle",
228
- running: busy.size
229
- });
225
+ const runnerVersion = () => options.runnerVersion?.() ?? options.hello.runnerVersion;
226
+ let saidVersion = "";
227
+ const sendStatus = () => {
228
+ const version = runnerVersion();
229
+ const changed = version !== saidVersion && socket?.readyState === WebSocket.OPEN;
230
+ send({
231
+ v: 1,
232
+ type: "status",
233
+ state: busy.size > 0 ? "busy" : "idle",
234
+ running: busy.size,
235
+ ...changed && { runnerVersion: version }
236
+ });
237
+ if (changed) saidVersion = version;
238
+ };
230
239
  const saveToken = (next) => {
231
240
  if (!options.saveToken) return;
232
241
  try {
@@ -318,10 +327,12 @@ async function connect(options) {
318
327
  opened = true;
319
328
  emit({ type: "connected" });
320
329
  const rotatesToken = options.saveToken ? true : void 0;
330
+ saidVersion = runnerVersion();
321
331
  ws.send(encodeMessage({
322
332
  v: 1,
323
333
  type: "hello",
324
334
  ...options.hello,
335
+ runnerVersion: saidVersion,
325
336
  slots,
326
337
  rotatesToken
327
338
  }));
@@ -1470,7 +1481,7 @@ async function prepareIsolation(options) {
1470
1481
  image
1471
1482
  ], debug, true) === 0;
1472
1483
  const fail = (code, message) => new RunnerError(code, debug.path ? `${message} Details are in ${debug.path}.` : message);
1473
- const latest = latestRunnerVersion(log);
1484
+ const latest = options.runnerVersion ? Promise.resolve(options.runnerVersion) : latestRunnerVersion(log);
1474
1485
  latest.catch(() => {});
1475
1486
  const [status] = await Promise.all([tool(["system", "status"]), tool(["--version"])]);
1476
1487
  if (status === null) throw new RunnerError("ISOLATED_SETUP", `Running jobs in VMs needs Apple's container tool. Install it from ${RELEASES}, then run \`container system start\`.`);
@@ -1523,18 +1534,19 @@ async function prepareIsolation(options) {
1523
1534
  await tool(["builder", "delete"]);
1524
1535
  }
1525
1536
  }
1526
- await pruneImages(options.managed ?? managedImagesFile(), [base, image], mine, tool, log);
1527
- const size = vmSize(options.slots, options.size);
1528
- log(`Each job runs in its own Linux VM with ${size.cpus} CPUs and ${size.memoryGb} GB of memory.`);
1529
- if (localNetwork) log("Jobs can reach this Mac and your local network.");
1530
- if (debug.path) log(`If something goes wrong, ${debug.path} has the details.`);
1537
+ await pruneImages(options.managed ?? managedImagesFile(), [
1538
+ base,
1539
+ image,
1540
+ ...options.keep ?? []
1541
+ ], mine, tool, log);
1531
1542
  return {
1532
1543
  command,
1544
+ base,
1533
1545
  image,
1534
1546
  localNetwork,
1535
1547
  debug,
1536
1548
  runnerVersion,
1537
- ...size
1549
+ ...vmSize(options.slots, options.size)
1538
1550
  };
1539
1551
  }
1540
1552
  function managedImagesFile() {
@@ -1736,6 +1748,19 @@ const RATES = {
1736
1748
  macos: "runner"
1737
1749
  }
1738
1750
  };
1751
+ /**
1752
+ * The `runs-on` label GitHub's docs give each standard runner, the name people know it by. Where
1753
+ * one runner has several labels (`ubuntu-latest`, `ubuntu-24.04`), this is the first one listed.
1754
+ * macOS has none: one rate covers several images (`macos-latest`, `macos-15-intel`), so it stays
1755
+ * "macOS". https://docs.github.com/en/actions/reference/runners/github-hosted-runners
1756
+ */
1757
+ const GITHUB_LABELS = {
1758
+ "linux-1-core": "ubuntu-slim",
1759
+ "linux-2-core": "ubuntu-latest",
1760
+ "linux-arm-2-core": "ubuntu-24.04-arm",
1761
+ "windows-2-core": "windows-latest",
1762
+ "windows-arm-2-core": "windows-11-arm"
1763
+ };
1739
1764
  /** The one rate a provider operators added has: a minute of any of its runners. */
1740
1765
  const ADDED_RATE = "runner";
1741
1766
  /**
@@ -1913,6 +1938,7 @@ function priceBook(rows) {
1913
1938
  changes: [...changes].sort((a, b) => a - b)
1914
1939
  };
1915
1940
  }
1941
+ ({ ...GITHUB_LABELS });
1916
1942
  priceBook(BASE_PRICES);
1917
1943
  // ../../packages/providers/src/index.ts
1918
1944
  /**
@@ -2393,6 +2419,46 @@ async function defaultMachineName(run$1 = run, system = platform(), host = hostn
2393
2419
  names.push(host.replace(/\.local$/i, ""));
2394
2420
  return (names.find((name) => name?.trim()) ?? "").trim().slice(0, MAX_LENGTH);
2395
2421
  }
2422
+ // runner-update.ts
2423
+ const RUNNER_CHECK_MS = 216e5;
2424
+ const BUSY_RETRY_MS = 6e5;
2425
+ const MAX_WAIT_MS = 864e5;
2426
+ function keepRunnerUpdated(options) {
2427
+ const checkMs = options.checkMs ?? RUNNER_CHECK_MS;
2428
+ const busyRetryMs = options.busyRetryMs ?? BUSY_RETRY_MS;
2429
+ const maxWaitMs = options.maxWaitMs ?? MAX_WAIT_MS;
2430
+ const latest = options.latest ?? (() => latestRunnerVersion());
2431
+ let dueAt = Date.now() + checkMs;
2432
+ let timer;
2433
+ let stopped = false;
2434
+ const schedule = (ms) => {
2435
+ if (stopped) return;
2436
+ timer = setTimeout(check, ms);
2437
+ timer.unref();
2438
+ };
2439
+ const check = async () => {
2440
+ if (options.running() > 0 && Date.now() - dueAt < maxWaitMs) return schedule(busyRetryMs);
2441
+ try {
2442
+ const version = await latest();
2443
+ const current = options.current();
2444
+ if (!stopped && isNewerVersion(version, current)) {
2445
+ options.log(`Updating the runner to actions/runner ${version}…`);
2446
+ await options.update(version);
2447
+ const running = options.running();
2448
+ options.log(running > 0 ? `New jobs run on actions/runner ${version}. Jobs already running finish on ${current}.` : `Jobs now run on actions/runner ${version}.`);
2449
+ }
2450
+ } catch (error) {
2451
+ options.log(`Couldn't update the runner (${error instanceof Error ? error.message : String(error)}). Trying again later.`);
2452
+ }
2453
+ dueAt = Date.now() + checkMs;
2454
+ schedule(checkMs);
2455
+ };
2456
+ schedule(checkMs);
2457
+ return () => {
2458
+ stopped = true;
2459
+ clearTimeout(timer);
2460
+ };
2461
+ }
2396
2462
  // live.ts
2397
2463
  const INITIAL_STATE = {
2398
2464
  link: "connecting",
@@ -3718,37 +3784,47 @@ async function connectMachine(args) {
3718
3784
  const onHost = !isolated || args.macos ? ensureRunner({ log }) : void 0;
3719
3785
  onHost?.catch(() => {});
3720
3786
  let runnerVersion = "";
3787
+ let isolation;
3721
3788
  let launchers = [];
3722
3789
  let vmLauncher;
3723
3790
  let isolatedOnly;
3724
3791
  let vmSize;
3792
+ const useRunner = (runner) => {
3793
+ launchers = ensureSlots(runner, slots, log).map(hostLauncher);
3794
+ runnerVersion = runner.version;
3795
+ };
3796
+ const useIsolation = (next) => {
3797
+ const launcher = isolatedLauncher(next);
3798
+ if (args.macos) vmLauncher = launcher;
3799
+ else {
3800
+ launchers = Array.from({ length: slots }, () => isolatedOnly = launcher);
3801
+ runnerVersion = next.runnerVersion;
3802
+ }
3803
+ };
3804
+ const firewall = isolated && firewallInstalled();
3805
+ const isolationOptions = {
3806
+ slots,
3807
+ size: args.size,
3808
+ image: args.image,
3809
+ localNetwork: args["local-network"] && !firewall,
3810
+ log,
3811
+ debug: isolated ? debugLog() : void 0
3812
+ };
3725
3813
  if (isolated) {
3726
- const firewall = firewallInstalled();
3727
3814
  if (firewall) log(args["local-network"] ? "The firewall on this Mac is on, so --local-network has no effect. Turn it off with `relayrunner firewall off`." : "The firewall on this Mac is on.");
3728
- const isolation = await prepareIsolation({
3729
- slots,
3730
- size: args.size,
3731
- image: args.image,
3732
- localNetwork: args["local-network"] && !firewall,
3733
- log,
3734
- debug: debugLog()
3735
- });
3736
- runnerVersion = isolation.runnerVersion;
3815
+ isolation = await prepareIsolation(isolationOptions);
3816
+ useIsolation(isolation);
3737
3817
  vmSize = {
3738
3818
  cpus: isolation.cpus,
3739
3819
  memoryGb: isolation.memoryGb
3740
3820
  };
3741
- const launcher = isolatedLauncher(isolation);
3742
- if (args.macos) vmLauncher = launcher;
3743
- else {
3744
- launchers = Array.from({ length: slots }, () => isolatedOnly = launcher);
3745
- log("Jobs run in a Linux VM on this Mac. To take macOS jobs too, run `relayrunner connect --macos`.");
3746
- }
3821
+ log(`Each job runs in its own Linux VM with ${vmSize.cpus} CPUs and ${vmSize.memoryGb} GB of memory.`);
3822
+ if (isolation.localNetwork) log("Jobs can reach this Mac and your local network.");
3823
+ if (isolation.debug.path) log(`If something goes wrong, ${isolation.debug.path} has the details.`);
3824
+ if (!args.macos) log("Jobs run in a Linux VM on this Mac. To take macOS jobs too, run `relayrunner connect --macos`.");
3747
3825
  }
3748
3826
  if (onHost) {
3749
- const runner = await onHost;
3750
- runnerVersion = runner.version;
3751
- launchers = ensureSlots(runner, slots, log).map(hostLauncher);
3827
+ useRunner(await onHost);
3752
3828
  const hint = !isolated && state ? setupHint(state) : null;
3753
3829
  if (hint) clack.log.warn(hint);
3754
3830
  if (args.macos) clack.log.warn("Linux jobs run in a VM. macOS jobs run on this Mac itself, where they can read your files. Only take macOS jobs from repos you trust.");
@@ -3756,6 +3832,21 @@ async function connectMachine(args) {
3756
3832
  }
3757
3833
  clack.log.info(slots === 1 ? "Running 1 job at a time. Change with --concurrency." : `Running up to ${slots} jobs at once. Change with --concurrency.`);
3758
3834
  const device = await detectDevice();
3835
+ let running = 0;
3836
+ const stopUpdating = onHost || isolation && !args.image ? keepRunnerUpdated({
3837
+ current: () => runnerVersion,
3838
+ running: () => running,
3839
+ log,
3840
+ update: async (version) => {
3841
+ const [vm, runner] = await Promise.all([isolation && !args.image && prepareIsolation({
3842
+ ...isolationOptions,
3843
+ runnerVersion: version,
3844
+ keep: [isolation.base, isolation.image]
3845
+ }), onHost && ensureRunner({ log })]);
3846
+ if (vm) useIsolation(isolation = vm);
3847
+ if (runner) useRunner(runner);
3848
+ }
3849
+ }) : void 0;
3759
3850
  const stop = new AbortController();
3760
3851
  const enrolled = credentials;
3761
3852
  let toggling = false;
@@ -3791,6 +3882,7 @@ async function connectMachine(args) {
3791
3882
  device,
3792
3883
  ...vmSize && { vm: vmSize }
3793
3884
  },
3885
+ runnerVersion: () => runnerVersion,
3794
3886
  slots,
3795
3887
  runJob: async (run, slot, report) => {
3796
3888
  const prefixed = slots > 1 ? prefixLines(`[slot ${slot}] `, (chunk, stream) => (stream === "stdout" ? process.stdout : process.stderr).write(chunk)) : void 0;
@@ -3804,6 +3896,7 @@ async function connectMachine(args) {
3804
3896
  report(update);
3805
3897
  return update;
3806
3898
  }
3899
+ running++;
3807
3900
  try {
3808
3901
  return await runJob(run, {
3809
3902
  launcher,
@@ -3814,6 +3907,7 @@ async function connectMachine(args) {
3814
3907
  }
3815
3908
  });
3816
3909
  } finally {
3910
+ running--;
3817
3911
  prefixed?.flush();
3818
3912
  }
3819
3913
  },
@@ -3827,6 +3921,7 @@ async function connectMachine(args) {
3827
3921
  });
3828
3922
  } finally {
3829
3923
  clearInterval(updateTimer);
3924
+ stopUpdating?.();
3830
3925
  live.end();
3831
3926
  process.off("SIGINT", onInterrupt);
3832
3927
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "relayrunner",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Run GitHub Actions jobs on your machine through the RelayRunner gateway.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {