relayrunner 0.10.0 → 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.
- package/README.md +11 -2
- package/dist/cli.js +399 -43
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -11,7 +11,8 @@ npm install --global relayrunner # or use npx relayrunner
|
|
|
11
11
|
|
|
12
12
|
Machines only take jobs from private repositories. To opt jobs in, see the
|
|
13
13
|
[root README](../../README.md#how-it-works) or
|
|
14
|
-
[docs/agent-install.md](../../docs/agent-install.md).
|
|
14
|
+
[docs/agent-install.md](../../docs/agent-install.md). To teach your coding
|
|
15
|
+
agent the CLI, see the [agent skills](../../skills).
|
|
15
16
|
|
|
16
17
|
## `relayrunner connect`
|
|
17
18
|
|
|
@@ -39,6 +40,13 @@ resume it without going offline (see `relayrunner pause`). The terminal tab's
|
|
|
39
40
|
title shows the machine and what it's doing, such as
|
|
40
41
|
`RelayRunner · M3P0 · Waiting for jobs`.
|
|
41
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
|
+
|
|
42
50
|
Before it starts a job, `connect` checks the job's runner config: it must hold
|
|
43
51
|
only the files GitHub's do, every server in it must be GitHub's, over https, and
|
|
44
52
|
the runner must be named for that job. Anything else is refused and reported as
|
|
@@ -88,7 +96,8 @@ approved the machine also gets an email, since someone else may have its token.
|
|
|
88
96
|
- `--no-isolated` runs jobs on the Mac itself, where they can read your
|
|
89
97
|
files. `--isolated` stops with an error when jobs can't run in VMs.
|
|
90
98
|
- `connect` removes the images it downloaded or built for older runner
|
|
91
|
-
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.
|
|
92
101
|
- `~/.relayrunner/isolated.log` records each `container` command and its
|
|
93
102
|
result, never a job's output or credentials. Send it along when you report
|
|
94
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.
|
|
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
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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(), [
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
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",
|
|
@@ -2604,6 +2670,261 @@ function sharingScope(workspaces) {
|
|
|
2604
2670
|
function noWorkspaceYet(machine, server) {
|
|
2605
2671
|
return [`${machine} isn't in a workspace yet. It takes jobs once RelayRunner is installed on a GitHub account or org you belong to, or once an org owner accepts your install request.`, `Install: ${new URL("/api/github/install", server)}`].join("\n");
|
|
2606
2672
|
}
|
|
2673
|
+
// ../../packages/errors/src/codes.ts
|
|
2674
|
+
/**
|
|
2675
|
+
* Every error code the API can return. A code never changes once it ships; its message can.
|
|
2676
|
+
* Feature-specific codes read `DOMAIN_FAILURE`, so the code alone names the feature and what
|
|
2677
|
+
* went wrong. Add a code here before returning it: apps/site builds the errors page and the
|
|
2678
|
+
* OpenAPI enum from this list.
|
|
2679
|
+
*/
|
|
2680
|
+
const ERRORS = {
|
|
2681
|
+
INVALID_REQUEST: {
|
|
2682
|
+
status: 400,
|
|
2683
|
+
message: "The request isn't valid."
|
|
2684
|
+
},
|
|
2685
|
+
PAYLOAD_TOO_LARGE: {
|
|
2686
|
+
status: 413,
|
|
2687
|
+
message: "The request body is too large."
|
|
2688
|
+
},
|
|
2689
|
+
NOT_FOUND: {
|
|
2690
|
+
status: 404,
|
|
2691
|
+
message: "Not found."
|
|
2692
|
+
},
|
|
2693
|
+
METHOD_NOT_ALLOWED: {
|
|
2694
|
+
status: 405,
|
|
2695
|
+
message: "That method isn't allowed here."
|
|
2696
|
+
},
|
|
2697
|
+
RATE_LIMITED: {
|
|
2698
|
+
status: 429,
|
|
2699
|
+
message: "Too many requests. Try again shortly."
|
|
2700
|
+
},
|
|
2701
|
+
INTERNAL_ERROR: {
|
|
2702
|
+
status: 500,
|
|
2703
|
+
message: "Something went wrong on our side."
|
|
2704
|
+
},
|
|
2705
|
+
UNAUTHENTICATED: {
|
|
2706
|
+
status: 401,
|
|
2707
|
+
message: "Sign in first."
|
|
2708
|
+
},
|
|
2709
|
+
INVALID_TOKEN: {
|
|
2710
|
+
status: 401,
|
|
2711
|
+
message: "The token is invalid, expired or revoked."
|
|
2712
|
+
},
|
|
2713
|
+
FORBIDDEN: {
|
|
2714
|
+
status: 403,
|
|
2715
|
+
message: "You don't have access to that."
|
|
2716
|
+
},
|
|
2717
|
+
AGENT_NOT_ALLOWED: {
|
|
2718
|
+
status: 403,
|
|
2719
|
+
message: "Agent tokens can't call this route."
|
|
2720
|
+
},
|
|
2721
|
+
NOT_A_MEMBER: {
|
|
2722
|
+
status: 403,
|
|
2723
|
+
message: "You aren't a member of that workspace."
|
|
2724
|
+
},
|
|
2725
|
+
LEGAL_TERMS_OUTDATED: {
|
|
2726
|
+
status: 409,
|
|
2727
|
+
message: "The terms changed since you opened this page. Reload it to read the new version."
|
|
2728
|
+
},
|
|
2729
|
+
NO_ACTIVE_WORKSPACE: {
|
|
2730
|
+
status: 409,
|
|
2731
|
+
message: "Pick a workspace first."
|
|
2732
|
+
},
|
|
2733
|
+
WORKSPACE_REQUIRED: {
|
|
2734
|
+
status: 409,
|
|
2735
|
+
message: "This token reads more than one workspace. Name one with the x-relayrunner-workspace header."
|
|
2736
|
+
},
|
|
2737
|
+
CANNOT_DEMOTE_SELF: {
|
|
2738
|
+
status: 400,
|
|
2739
|
+
message: "You can't remove your own operator role."
|
|
2740
|
+
},
|
|
2741
|
+
CANNOT_DELETE_SELF: {
|
|
2742
|
+
status: 400,
|
|
2743
|
+
message: "You can't delete your own account here."
|
|
2744
|
+
},
|
|
2745
|
+
USER_HAS_SHARED_WORKSPACES: {
|
|
2746
|
+
status: 409,
|
|
2747
|
+
message: "The user is in workspaces with other members. Remove them from those first."
|
|
2748
|
+
},
|
|
2749
|
+
MACHINE_NOT_OWNED: {
|
|
2750
|
+
status: 403,
|
|
2751
|
+
message: "Only a machine with an owner can do this."
|
|
2752
|
+
},
|
|
2753
|
+
DEVICE_CODE_INVALID: {
|
|
2754
|
+
status: 400,
|
|
2755
|
+
message: "That code doesn't match a sign-in request. Check it against your terminal."
|
|
2756
|
+
},
|
|
2757
|
+
DEVICE_CODE_EXPIRED: {
|
|
2758
|
+
status: 400,
|
|
2759
|
+
message: "That code has expired. Run `relayrunner connect` again for a new one."
|
|
2760
|
+
},
|
|
2761
|
+
DEVICE_CODE_USED: {
|
|
2762
|
+
status: 409,
|
|
2763
|
+
message: "That code has already been used."
|
|
2764
|
+
},
|
|
2765
|
+
DEVICE_CODE_CLAIMED: {
|
|
2766
|
+
status: 403,
|
|
2767
|
+
message: "Another account already approved or denied this request. Run `relayrunner connect` again for a new code."
|
|
2768
|
+
},
|
|
2769
|
+
WEBSOCKET_REQUIRED: {
|
|
2770
|
+
status: 426,
|
|
2771
|
+
message: "Connect with a WebSocket upgrade."
|
|
2772
|
+
},
|
|
2773
|
+
RUNNER_ORDER_INVALID: {
|
|
2774
|
+
status: 400,
|
|
2775
|
+
message: "The runner order isn't valid."
|
|
2776
|
+
},
|
|
2777
|
+
PROVIDER_UNKNOWN: {
|
|
2778
|
+
status: 400,
|
|
2779
|
+
message: "There's no provider with that id."
|
|
2780
|
+
},
|
|
2781
|
+
PROVIDER_INVALID: {
|
|
2782
|
+
status: 400,
|
|
2783
|
+
message: "Fill in a name, summary and labels, and use https:// links."
|
|
2784
|
+
},
|
|
2785
|
+
PROVIDER_ID_INVALID: {
|
|
2786
|
+
status: 400,
|
|
2787
|
+
message: "Use lowercase letters, numbers and dashes for the id."
|
|
2788
|
+
},
|
|
2789
|
+
PROVIDER_PREFIXES_INVALID: {
|
|
2790
|
+
status: 400,
|
|
2791
|
+
message: "Add at least one label prefix, three or more characters each."
|
|
2792
|
+
},
|
|
2793
|
+
PROVIDER_EXISTS: {
|
|
2794
|
+
status: 409,
|
|
2795
|
+
message: "There's already a provider with that id."
|
|
2796
|
+
},
|
|
2797
|
+
PROVIDER_PREFIX_TAKEN: {
|
|
2798
|
+
status: 409,
|
|
2799
|
+
message: "Another provider, or GitHub's own runners, already use labels like that."
|
|
2800
|
+
},
|
|
2801
|
+
PROVIDER_NOT_CONNECTED: {
|
|
2802
|
+
status: 404,
|
|
2803
|
+
message: "That provider isn't connected."
|
|
2804
|
+
},
|
|
2805
|
+
PROVIDER_TOKEN_REJECTED: {
|
|
2806
|
+
status: 400,
|
|
2807
|
+
message: "The provider didn't accept that token. Check it and its scope."
|
|
2808
|
+
},
|
|
2809
|
+
PROVIDER_UNREACHABLE: {
|
|
2810
|
+
status: 502,
|
|
2811
|
+
message: "The provider's API didn't answer. Try again shortly."
|
|
2812
|
+
},
|
|
2813
|
+
PRICE_INVALID: {
|
|
2814
|
+
status: 400,
|
|
2815
|
+
message: "Check the price and date."
|
|
2816
|
+
},
|
|
2817
|
+
PRICE_EXISTS: {
|
|
2818
|
+
status: 409,
|
|
2819
|
+
message: "That rate already has a price from that day. Remove it first to correct it."
|
|
2820
|
+
},
|
|
2821
|
+
TOKEN_STORAGE_UNAVAILABLE: {
|
|
2822
|
+
status: 503,
|
|
2823
|
+
message: "Saving provider tokens isn't set up on this server yet."
|
|
2824
|
+
},
|
|
2825
|
+
TELEMETRY_ENDPOINT_INVALID: {
|
|
2826
|
+
status: 400,
|
|
2827
|
+
message: "Use an https URL on the internet, like https://api.honeycomb.io."
|
|
2828
|
+
},
|
|
2829
|
+
TELEMETRY_HEADER_MISSING: {
|
|
2830
|
+
status: 400,
|
|
2831
|
+
message: "Enter a value for each header."
|
|
2832
|
+
},
|
|
2833
|
+
TELEMETRY_NOT_CONFIGURED: {
|
|
2834
|
+
status: 404,
|
|
2835
|
+
message: "Telemetry isn't set up for this workspace."
|
|
2836
|
+
},
|
|
2837
|
+
WEBHOOK_SIGNATURE_INVALID: {
|
|
2838
|
+
status: 401,
|
|
2839
|
+
message: "The webhook signature is missing or doesn't match the App's secret."
|
|
2840
|
+
},
|
|
2841
|
+
WEBHOOK_SECRET_NOT_CONFIGURED: {
|
|
2842
|
+
status: 500,
|
|
2843
|
+
message: "The webhook secret for this App isn't set up on this server."
|
|
2844
|
+
},
|
|
2845
|
+
WEBHOOK_ENQUEUE_FAILED: {
|
|
2846
|
+
status: 503,
|
|
2847
|
+
message: "The delivery couldn't be queued. Redeliver it from the App's settings."
|
|
2848
|
+
},
|
|
2849
|
+
GITHUB_UNAVAILABLE: {
|
|
2850
|
+
status: 502,
|
|
2851
|
+
message: "GitHub didn't answer. Try again shortly."
|
|
2852
|
+
},
|
|
2853
|
+
GITHUB_RATE_LIMITED: {
|
|
2854
|
+
status: 503,
|
|
2855
|
+
message: "GitHub's API limit was reached. Try again shortly."
|
|
2856
|
+
},
|
|
2857
|
+
GITHUB_APP_NOT_CONFIGURED: {
|
|
2858
|
+
status: 500,
|
|
2859
|
+
message: "The GitHub App isn't set up."
|
|
2860
|
+
}
|
|
2861
|
+
};
|
|
2862
|
+
function isErrorCode(code) {
|
|
2863
|
+
return typeof code === "string" && Object.hasOwn(ERRORS, code);
|
|
2864
|
+
}
|
|
2865
|
+
// ../../packages/errors/src/app-error.ts
|
|
2866
|
+
/**
|
|
2867
|
+
* A failure with a stable code. Throw it from an API route and the API's error handler answers
|
|
2868
|
+
* with the code's status and an {@link ErrorBody}; clients get one back from {@link parseError}.
|
|
2869
|
+
*/
|
|
2870
|
+
var AppError = class extends Error {
|
|
2871
|
+
/** A string rather than ErrorCode: a client can receive codes added after it was built. */
|
|
2872
|
+
code;
|
|
2873
|
+
status;
|
|
2874
|
+
details;
|
|
2875
|
+
retryAfter;
|
|
2876
|
+
constructor(code, options = {}) {
|
|
2877
|
+
super(options.message ?? ERRORS[code].message, { cause: options.cause });
|
|
2878
|
+
this.name = "AppError";
|
|
2879
|
+
this.code = code;
|
|
2880
|
+
this.status = ERRORS[code].status;
|
|
2881
|
+
this.details = options.details;
|
|
2882
|
+
this.retryAfter = options.retryAfter;
|
|
2883
|
+
}
|
|
2884
|
+
toJSON() {
|
|
2885
|
+
return { error: {
|
|
2886
|
+
code: this.code,
|
|
2887
|
+
message: this.message,
|
|
2888
|
+
...this.details === void 0 ? {} : { details: this.details }
|
|
2889
|
+
} };
|
|
2890
|
+
}
|
|
2891
|
+
};
|
|
2892
|
+
/** Whether a response body is an {@link ErrorBody}. */
|
|
2893
|
+
function isErrorBody(body) {
|
|
2894
|
+
const error = body?.error;
|
|
2895
|
+
return typeof error === "object" && error !== null && typeof error.code === "string" && typeof error.message === "string";
|
|
2896
|
+
}
|
|
2897
|
+
/**
|
|
2898
|
+
* Reads a non-2xx response body as an AppError. Never throws: a body that isn't an
|
|
2899
|
+
* {@link ErrorBody} (a proxy's HTML page, an empty body) keeps the status with a generic message.
|
|
2900
|
+
*/
|
|
2901
|
+
function parseError(body, status) {
|
|
2902
|
+
const { code, message, details } = isErrorBody(body) ? body.error : {
|
|
2903
|
+
code: "INTERNAL_ERROR",
|
|
2904
|
+
message: `The request failed with status ${status}.`,
|
|
2905
|
+
details: void 0
|
|
2906
|
+
};
|
|
2907
|
+
const parsed = new AppError(isErrorCode(code) ? code : "INTERNAL_ERROR", {
|
|
2908
|
+
message,
|
|
2909
|
+
details
|
|
2910
|
+
});
|
|
2911
|
+
return Object.assign(parsed, {
|
|
2912
|
+
status,
|
|
2913
|
+
code
|
|
2914
|
+
});
|
|
2915
|
+
}
|
|
2916
|
+
/** An error in one line for an agent or a terminal: "Not found (NOT_FOUND)". */
|
|
2917
|
+
function describeError(error) {
|
|
2918
|
+
return `${error.message.replace(/\.$/, "")} (${error.code})`;
|
|
2919
|
+
}
|
|
2920
|
+
// api-error.ts
|
|
2921
|
+
/**
|
|
2922
|
+
* Why a request to the gateway failed, for "Couldn't …: <reason>.": the API's message and error
|
|
2923
|
+
* code when it sent one (@relayrunner/errors), else the HTTP status.
|
|
2924
|
+
*/
|
|
2925
|
+
function failureReason(server, status, body) {
|
|
2926
|
+
return isErrorBody(body) ? describeError(parseError(body, status)) : `${server} answered HTTP ${status}`;
|
|
2927
|
+
}
|
|
2607
2928
|
// login.ts
|
|
2608
2929
|
const CLIENT_ID = "relayrunner-cli";
|
|
2609
2930
|
const DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
@@ -2701,7 +3022,10 @@ async function login(options) {
|
|
|
2701
3022
|
deviceCode: code.device_code,
|
|
2702
3023
|
...options.platform
|
|
2703
3024
|
}, { authorization: `Bearer ${accessToken}` });
|
|
2704
|
-
if (!claimResponse.ok)
|
|
3025
|
+
if (!claimResponse.ok) {
|
|
3026
|
+
const body = await claimResponse.json().catch(() => null);
|
|
3027
|
+
throw new LoginError("CLAIM_FAILED", `The gateway approved the sign-in but wouldn't enroll this machine: ${failureReason(options.server, claimResponse.status, body)}.`);
|
|
3028
|
+
}
|
|
2705
3029
|
const claimed = ClaimResponse.parse(await claimResponse.json());
|
|
2706
3030
|
return {
|
|
2707
3031
|
credentials: {
|
|
@@ -2757,11 +3081,12 @@ async function setPaused(options) {
|
|
|
2757
3081
|
};
|
|
2758
3082
|
}
|
|
2759
3083
|
if (response.status === 401) return { status: "revoked" };
|
|
3084
|
+
const body = await response.json().catch(() => null);
|
|
2760
3085
|
if (!response.ok) return {
|
|
2761
3086
|
status: "failed",
|
|
2762
|
-
reason:
|
|
3087
|
+
reason: failureReason(options.server, response.status, body)
|
|
2763
3088
|
};
|
|
2764
|
-
const parsed = PauseResponse.safeParse(
|
|
3089
|
+
const parsed = PauseResponse.safeParse(body);
|
|
2765
3090
|
if (!parsed.success) return {
|
|
2766
3091
|
status: "failed",
|
|
2767
3092
|
reason: `${options.server} sent an unexpected response`
|
|
@@ -2876,11 +3201,12 @@ async function setSharing(options) {
|
|
|
2876
3201
|
status: "failed",
|
|
2877
3202
|
reason: `${options.server} doesn't support sharing yet`
|
|
2878
3203
|
};
|
|
3204
|
+
const body = await response.json().catch(() => null);
|
|
2879
3205
|
if (!response.ok) return {
|
|
2880
3206
|
status: "failed",
|
|
2881
|
-
reason:
|
|
3207
|
+
reason: failureReason(options.server, response.status, body)
|
|
2882
3208
|
};
|
|
2883
|
-
const parsed = SharingResponse.safeParse(
|
|
3209
|
+
const parsed = SharingResponse.safeParse(body);
|
|
2884
3210
|
if (!parsed.success) return {
|
|
2885
3211
|
status: "failed",
|
|
2886
3212
|
reason: `${options.server} sent an unexpected response`
|
|
@@ -3046,11 +3372,12 @@ async function whoami(options) {
|
|
|
3046
3372
|
};
|
|
3047
3373
|
}
|
|
3048
3374
|
if (response.status === 401) return { status: "revoked" };
|
|
3375
|
+
const body = await response.json().catch(() => null);
|
|
3049
3376
|
if (!response.ok) return {
|
|
3050
3377
|
status: "unverified",
|
|
3051
|
-
reason:
|
|
3378
|
+
reason: failureReason(options.server, response.status, body)
|
|
3052
3379
|
};
|
|
3053
|
-
const parsed = WhoamiResponse.safeParse(
|
|
3380
|
+
const parsed = WhoamiResponse.safeParse(body);
|
|
3054
3381
|
if (!parsed.success) return {
|
|
3055
3382
|
status: "unverified",
|
|
3056
3383
|
reason: `${options.server} sent an unexpected response`
|
|
@@ -3098,7 +3425,7 @@ async function machineWorkspaces(options) {
|
|
|
3098
3425
|
}
|
|
3099
3426
|
if (response.status === 401) return { status: "revoked" };
|
|
3100
3427
|
const body = await response.json().catch(() => null);
|
|
3101
|
-
if (change && response.status === 404 && body
|
|
3428
|
+
if (change && response.status === 404 && isErrorBody(body) && body.error.code === "NOT_FOUND") return { status: "not_found" };
|
|
3102
3429
|
if (response.status === 404 || response.status === 405) return {
|
|
3103
3430
|
status: "failed",
|
|
3104
3431
|
reason: `${options.server} doesn't support choosing workspaces yet`
|
|
@@ -3109,7 +3436,7 @@ async function machineWorkspaces(options) {
|
|
|
3109
3436
|
};
|
|
3110
3437
|
if (!response.ok) return {
|
|
3111
3438
|
status: "failed",
|
|
3112
|
-
reason:
|
|
3439
|
+
reason: failureReason(options.server, response.status, body)
|
|
3113
3440
|
};
|
|
3114
3441
|
const parsed = MachineWorkspaces.safeParse(body);
|
|
3115
3442
|
if (!parsed.success) return {
|
|
@@ -3457,37 +3784,47 @@ async function connectMachine(args) {
|
|
|
3457
3784
|
const onHost = !isolated || args.macos ? ensureRunner({ log }) : void 0;
|
|
3458
3785
|
onHost?.catch(() => {});
|
|
3459
3786
|
let runnerVersion = "";
|
|
3787
|
+
let isolation;
|
|
3460
3788
|
let launchers = [];
|
|
3461
3789
|
let vmLauncher;
|
|
3462
3790
|
let isolatedOnly;
|
|
3463
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
|
+
};
|
|
3464
3813
|
if (isolated) {
|
|
3465
|
-
const firewall = firewallInstalled();
|
|
3466
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.");
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
size: args.size,
|
|
3470
|
-
image: args.image,
|
|
3471
|
-
localNetwork: args["local-network"] && !firewall,
|
|
3472
|
-
log,
|
|
3473
|
-
debug: debugLog()
|
|
3474
|
-
});
|
|
3475
|
-
runnerVersion = isolation.runnerVersion;
|
|
3815
|
+
isolation = await prepareIsolation(isolationOptions);
|
|
3816
|
+
useIsolation(isolation);
|
|
3476
3817
|
vmSize = {
|
|
3477
3818
|
cpus: isolation.cpus,
|
|
3478
3819
|
memoryGb: isolation.memoryGb
|
|
3479
3820
|
};
|
|
3480
|
-
|
|
3481
|
-
if (
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
log("Jobs run in a Linux VM on this Mac. To take macOS jobs too, run `relayrunner connect --macos`.");
|
|
3485
|
-
}
|
|
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`.");
|
|
3486
3825
|
}
|
|
3487
3826
|
if (onHost) {
|
|
3488
|
-
|
|
3489
|
-
runnerVersion = runner.version;
|
|
3490
|
-
launchers = ensureSlots(runner, slots, log).map(hostLauncher);
|
|
3827
|
+
useRunner(await onHost);
|
|
3491
3828
|
const hint = !isolated && state ? setupHint(state) : null;
|
|
3492
3829
|
if (hint) clack.log.warn(hint);
|
|
3493
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.");
|
|
@@ -3495,6 +3832,21 @@ async function connectMachine(args) {
|
|
|
3495
3832
|
}
|
|
3496
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.`);
|
|
3497
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;
|
|
3498
3850
|
const stop = new AbortController();
|
|
3499
3851
|
const enrolled = credentials;
|
|
3500
3852
|
let toggling = false;
|
|
@@ -3530,6 +3882,7 @@ async function connectMachine(args) {
|
|
|
3530
3882
|
device,
|
|
3531
3883
|
...vmSize && { vm: vmSize }
|
|
3532
3884
|
},
|
|
3885
|
+
runnerVersion: () => runnerVersion,
|
|
3533
3886
|
slots,
|
|
3534
3887
|
runJob: async (run, slot, report) => {
|
|
3535
3888
|
const prefixed = slots > 1 ? prefixLines(`[slot ${slot}] `, (chunk, stream) => (stream === "stdout" ? process.stdout : process.stderr).write(chunk)) : void 0;
|
|
@@ -3543,6 +3896,7 @@ async function connectMachine(args) {
|
|
|
3543
3896
|
report(update);
|
|
3544
3897
|
return update;
|
|
3545
3898
|
}
|
|
3899
|
+
running++;
|
|
3546
3900
|
try {
|
|
3547
3901
|
return await runJob(run, {
|
|
3548
3902
|
launcher,
|
|
@@ -3553,6 +3907,7 @@ async function connectMachine(args) {
|
|
|
3553
3907
|
}
|
|
3554
3908
|
});
|
|
3555
3909
|
} finally {
|
|
3910
|
+
running--;
|
|
3556
3911
|
prefixed?.flush();
|
|
3557
3912
|
}
|
|
3558
3913
|
},
|
|
@@ -3566,6 +3921,7 @@ async function connectMachine(args) {
|
|
|
3566
3921
|
});
|
|
3567
3922
|
} finally {
|
|
3568
3923
|
clearInterval(updateTimer);
|
|
3924
|
+
stopUpdating?.();
|
|
3569
3925
|
live.end();
|
|
3570
3926
|
process.off("SIGINT", onInterrupt);
|
|
3571
3927
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "relayrunner",
|
|
3
|
-
"version": "0.
|
|
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": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"zod": "^4.6.7"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
+
"@relayrunner/errors": "0.0.0",
|
|
28
29
|
"@relayrunner/machine-protocol": "0.0.0",
|
|
29
30
|
"@relayrunner/providers": "0.0.0",
|
|
30
31
|
"@types/ws": "^8.18.2",
|