relayrunner 0.4.0 → 0.6.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 +26 -15
- package/dist/cli.js +512 -99
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# RelayRunner CLI
|
|
2
2
|
|
|
3
|
-
Connects a machine to the RelayRunner gateway so it can run
|
|
4
|
-
|
|
3
|
+
Connects a machine to the RelayRunner gateway so it can run GitHub Actions jobs
|
|
4
|
+
in your workspaces. It's published to npm as
|
|
5
5
|
[`relayrunner`](https://www.npmjs.com/package/relayrunner) and needs Node.js 22
|
|
6
6
|
or newer on macOS or Linux (x64 or ARM64).
|
|
7
7
|
|
|
@@ -20,7 +20,12 @@ npx relayrunner connect
|
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
The first run signs you in: it shows a code and opens the dashboard, where you
|
|
23
|
-
|
|
23
|
+
name this machine and approve. The machine is yours, and it's in every workspace
|
|
24
|
+
you're a member of (one per GitHub account or org RelayRunner is installed on),
|
|
25
|
+
so there's no workspace to pick. `connect` prints which ones it's in. If you
|
|
26
|
+
aren't in one yet, say because you skipped the install or an org owner hasn't
|
|
27
|
+
accepted your install request, it says so and links to the install. The
|
|
28
|
+
machine can still go online, and it takes jobs once you're in a workspace. The machine token is
|
|
24
29
|
saved to `~/.relayrunner/machine.json` (mode 0600); later runs reuse it. The
|
|
25
30
|
gateway sends a new token every time `connect` comes online and the old one
|
|
26
31
|
stops working, so a copy of `machine.json` from a backup or a synced dotfiles
|
|
@@ -29,7 +34,10 @@ folder can't sign in as the machine.
|
|
|
29
34
|
While it runs, the machine is online: it keeps a WebSocket open to the gateway,
|
|
30
35
|
runs the jobs it's sent (one at a time) and prints what happens, including the
|
|
31
36
|
repo each job is from. It reconnects on its own if the connection drops. Ctrl-C
|
|
32
|
-
takes it offline; a job that's running stops with it.
|
|
37
|
+
takes it offline; a job that's running stops with it. Press `p` to pause or
|
|
38
|
+
resume it without going offline (see `relayrunner pause`). The terminal tab's
|
|
39
|
+
title shows the machine and what it's doing, such as
|
|
40
|
+
`RelayRunner · M3P0 · Waiting for jobs`.
|
|
33
41
|
|
|
34
42
|
Before it starts a job, `connect` checks the job's runner config: it must hold
|
|
35
43
|
only the files GitHub's do, every server in it must be GitHub's, over https, and
|
|
@@ -46,7 +54,8 @@ approved the machine also gets an email, since someone else may have its token.
|
|
|
46
54
|
- `--server <url>` or `RELAYRUNNER_URL` points it at another gateway. Changing it signs in again.
|
|
47
55
|
It must be https, except for `localhost` while developing, since the token goes
|
|
48
56
|
out on every connect.
|
|
49
|
-
- `--name <name>` changes the suggested machine name (default: the hostname
|
|
57
|
+
- `--name <name>` changes the suggested machine name (default: the hostname if
|
|
58
|
+
one is set, otherwise the Mac's Computer Name from System Settings).
|
|
50
59
|
- `--share only-me|anyone` sets who can run jobs on this machine without asking.
|
|
51
60
|
It works on a machine that's already signed in too.
|
|
52
61
|
- If the machine is removed in the dashboard, `connect` deletes the saved token.
|
|
@@ -54,10 +63,10 @@ approved the machine also gets an email, since someone else may have its token.
|
|
|
54
63
|
straight away.
|
|
55
64
|
|
|
56
65
|
A new machine runs only jobs you started (`only-me`). Right after signing in,
|
|
57
|
-
if
|
|
58
|
-
machine?": Only me, or Anyone in
|
|
59
|
-
It doesn't ask in
|
|
60
|
-
answer. [`relayrunner share`](#relayrunner-share) changes it later.
|
|
66
|
+
if any of your workspaces has other members, `connect` asks "Who can run jobs on
|
|
67
|
+
this machine?": Only me, or Anyone in your workspaces (teammates' and bots' jobs
|
|
68
|
+
too). It doesn't ask when you're alone in all of them, on later runs, or without
|
|
69
|
+
a terminal to answer. [`relayrunner share`](#relayrunner-share) changes it later.
|
|
61
70
|
|
|
62
71
|
Run inside a checkout of a private repo where no job uses RelayRunner yet,
|
|
63
72
|
`connect` first asks whether to set it up (default no). Yes runs the same picker
|
|
@@ -66,7 +75,7 @@ as [`relayrunner init`](#relayrunner-init). No is remembered for that repo in
|
|
|
66
75
|
works there. It never asks outside a repo, in a public repo, in a repo that's
|
|
67
76
|
already set up, or without a terminal to answer.
|
|
68
77
|
|
|
69
|
-
Jobs run in `actions/runner`, which is downloaded into
|
|
78
|
+
Jobs run in `actions/runner`, GitHub's official self-hosted runner, which is downloaded into
|
|
70
79
|
`~/.relayrunner/runner/<version>` on first connect and checked against its
|
|
71
80
|
SHA-256. Set `RELAYRUNNER_HOME` to keep everything somewhere else.
|
|
72
81
|
|
|
@@ -93,10 +102,10 @@ npx relayrunner whoami
|
|
|
93
102
|
```
|
|
94
103
|
|
|
95
104
|
Asks the gateway who the saved machine token belongs to and prints the machine,
|
|
96
|
-
|
|
105
|
+
the workspaces it's in, who enrolled it (name and email) and whether it's online now.
|
|
97
106
|
|
|
98
107
|
- Not signed in: says so and exits 1.
|
|
99
|
-
- Removed
|
|
108
|
+
- Removed (or the token is no longer valid): says so and
|
|
100
109
|
exits 1. The saved token is left alone; the next `connect` replaces it.
|
|
101
110
|
- Gateway unreachable: prints what's saved locally, marked unverified, and exits 0.
|
|
102
111
|
- `--json` prints the same as JSON (never the token). `--server <url>` or
|
|
@@ -144,8 +153,9 @@ npx relayrunner resume
|
|
|
144
153
|
|
|
145
154
|
Pausing stops new jobs routing to this machine while it stays connected and
|
|
146
155
|
enrolled. A job it's already running finishes. `resume` lets jobs route here
|
|
147
|
-
again.
|
|
156
|
+
again. You can do the same from the machine's ⋯ menu on the
|
|
148
157
|
Runners page, and a running `relayrunner connect` prints when that happens.
|
|
158
|
+
In the terminal running `relayrunner connect`, `p` does the same.
|
|
149
159
|
Both exit 1 when not signed in or when the token is no longer valid.
|
|
150
160
|
|
|
151
161
|
## `relayrunner share`
|
|
@@ -153,11 +163,12 @@ Both exit 1 when not signed in or when the token is no longer valid.
|
|
|
153
163
|
```sh
|
|
154
164
|
npx relayrunner share # show the current setting
|
|
155
165
|
npx relayrunner share only-me # run only jobs you started
|
|
156
|
-
npx relayrunner share anyone # run any job in
|
|
166
|
+
npx relayrunner share anyone # run any job in your workspaces
|
|
157
167
|
```
|
|
158
168
|
|
|
159
169
|
Who can run jobs on this machine. `only-me` takes only jobs you started on
|
|
160
|
-
GitHub; `anyone` takes any job in
|
|
170
|
+
GitHub; `anyone` takes any job in your workspaces, including teammates' and
|
|
171
|
+
bots'. It's one setting for all of them.
|
|
161
172
|
It's the same setting as the sharing icon on the machine's card on the Runners
|
|
162
173
|
page, and only the machine's owner can change it there. `relayrunner whoami`
|
|
163
174
|
shows it too. Exits 1 when not signed in or when the token is no longer valid.
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { arch, cpus, homedir, hostname, platform, totalmem } from "node:os";
|
|
3
2
|
import * as clack from "@clack/prompts";
|
|
4
3
|
import { defineCommand, runMain } from "citty";
|
|
5
4
|
import { z } from "zod";
|
|
5
|
+
import { arch, cpus, homedir, hostname, platform, totalmem } from "node:os";
|
|
6
6
|
import { basename, dirname, join, resolve } from "node:path";
|
|
7
7
|
import { chmodSync, createWriteStream, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { execFile, spawn } from "node:child_process";
|
|
@@ -447,7 +447,7 @@ async function ensureRunner(options = {}) {
|
|
|
447
447
|
version: download.version,
|
|
448
448
|
dir
|
|
449
449
|
};
|
|
450
|
-
log(`Downloading actions/runner ${download.version}…`);
|
|
450
|
+
log(`Downloading GitHub's official runner (actions/runner ${download.version})…`);
|
|
451
451
|
await install(root, download);
|
|
452
452
|
log(`Installed actions/runner ${download.version} in ${dir}`);
|
|
453
453
|
return {
|
|
@@ -536,7 +536,7 @@ const Credentials = z.object({
|
|
|
536
536
|
id: z.string().min(1),
|
|
537
537
|
name: z.string(),
|
|
538
538
|
slug: z.string().nullish()
|
|
539
|
-
}),
|
|
539
|
+
}).optional(),
|
|
540
540
|
token: z.string().min(1)
|
|
541
541
|
});
|
|
542
542
|
function credentialsPath(home = relayrunnerHome()) {
|
|
@@ -902,9 +902,244 @@ async function repoVisibility(repo, fetcher = fetch) {
|
|
|
902
902
|
return "unknown";
|
|
903
903
|
}
|
|
904
904
|
}
|
|
905
|
+
// ../../packages/providers/src/prices.ts
|
|
906
|
+
/** A provider's rates, and what one minute of each is per. */
|
|
907
|
+
const RATES = {
|
|
908
|
+
blacksmith: {
|
|
909
|
+
linux: "vcpu",
|
|
910
|
+
arm: "vcpu",
|
|
911
|
+
windows: "vcpu",
|
|
912
|
+
macos: "vcpu"
|
|
913
|
+
},
|
|
914
|
+
depot: {
|
|
915
|
+
linux: "vcpu",
|
|
916
|
+
arm: "vcpu",
|
|
917
|
+
windows: "vcpu",
|
|
918
|
+
macos: "vcpu"
|
|
919
|
+
},
|
|
920
|
+
warpbuild: {
|
|
921
|
+
linux: "vcpu",
|
|
922
|
+
arm: "vcpu",
|
|
923
|
+
windows: "vcpu",
|
|
924
|
+
macos: "vcpu"
|
|
925
|
+
},
|
|
926
|
+
ubicloud: {
|
|
927
|
+
standard: "vcpu",
|
|
928
|
+
premium: "vcpu"
|
|
929
|
+
},
|
|
930
|
+
github: {
|
|
931
|
+
"linux-1-core": "runner",
|
|
932
|
+
"linux-2-core": "runner",
|
|
933
|
+
"linux-arm-2-core": "runner",
|
|
934
|
+
"windows-2-core": "runner",
|
|
935
|
+
"windows-arm-2-core": "runner",
|
|
936
|
+
macos: "runner"
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
const isRate = (provider, rate) => Object.hasOwn(RATES, provider) && Object.hasOwn(RATES[provider], rate);
|
|
940
|
+
const vcpu = (perRunner, vcpus) => perRunner / vcpus;
|
|
941
|
+
const BASE_PRICES = [
|
|
942
|
+
{
|
|
943
|
+
provider: "blacksmith",
|
|
944
|
+
rate: "linux",
|
|
945
|
+
usd: vcpu(.004, 2),
|
|
946
|
+
from: "2026-11-11"
|
|
947
|
+
},
|
|
948
|
+
{
|
|
949
|
+
provider: "blacksmith",
|
|
950
|
+
rate: "arm",
|
|
951
|
+
usd: vcpu(.0025, 2),
|
|
952
|
+
from: "2026-11-11"
|
|
953
|
+
},
|
|
954
|
+
{
|
|
955
|
+
provider: "blacksmith",
|
|
956
|
+
rate: "windows",
|
|
957
|
+
usd: vcpu(.008, 2),
|
|
958
|
+
from: "2026-11-11"
|
|
959
|
+
},
|
|
960
|
+
{
|
|
961
|
+
provider: "blacksmith",
|
|
962
|
+
rate: "macos",
|
|
963
|
+
usd: vcpu(.08, 6),
|
|
964
|
+
from: "2026-11-11"
|
|
965
|
+
},
|
|
966
|
+
{
|
|
967
|
+
provider: "depot",
|
|
968
|
+
rate: "linux",
|
|
969
|
+
usd: vcpu(.006, 2),
|
|
970
|
+
from: "2026-11-11"
|
|
971
|
+
},
|
|
972
|
+
{
|
|
973
|
+
provider: "depot",
|
|
974
|
+
rate: "arm",
|
|
975
|
+
usd: vcpu(.006, 2),
|
|
976
|
+
from: "2026-11-11"
|
|
977
|
+
},
|
|
978
|
+
{
|
|
979
|
+
provider: "depot",
|
|
980
|
+
rate: "windows",
|
|
981
|
+
usd: vcpu(.008, 2),
|
|
982
|
+
from: "2026-11-11"
|
|
983
|
+
},
|
|
984
|
+
{
|
|
985
|
+
provider: "depot",
|
|
986
|
+
rate: "macos",
|
|
987
|
+
usd: vcpu(.08, 8),
|
|
988
|
+
from: "2026-11-11"
|
|
989
|
+
},
|
|
990
|
+
{
|
|
991
|
+
provider: "warpbuild",
|
|
992
|
+
rate: "linux",
|
|
993
|
+
usd: vcpu(.004, 2),
|
|
994
|
+
from: "2026-11-11"
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
provider: "warpbuild",
|
|
998
|
+
rate: "arm",
|
|
999
|
+
usd: vcpu(.003, 2),
|
|
1000
|
+
from: "2026-11-11"
|
|
1001
|
+
},
|
|
1002
|
+
{
|
|
1003
|
+
provider: "warpbuild",
|
|
1004
|
+
rate: "windows",
|
|
1005
|
+
usd: vcpu(.016, 4),
|
|
1006
|
+
from: "2026-11-11"
|
|
1007
|
+
},
|
|
1008
|
+
{
|
|
1009
|
+
provider: "warpbuild",
|
|
1010
|
+
rate: "macos",
|
|
1011
|
+
usd: vcpu(.08, 6),
|
|
1012
|
+
from: "2026-11-11"
|
|
1013
|
+
},
|
|
1014
|
+
{
|
|
1015
|
+
provider: "ubicloud",
|
|
1016
|
+
rate: "standard",
|
|
1017
|
+
usd: vcpu(8e-4, 2),
|
|
1018
|
+
from: "2023-01-01"
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
provider: "ubicloud",
|
|
1022
|
+
rate: "standard",
|
|
1023
|
+
usd: vcpu(.001, 2),
|
|
1024
|
+
from: "2026-05-01"
|
|
1025
|
+
},
|
|
1026
|
+
{
|
|
1027
|
+
provider: "ubicloud",
|
|
1028
|
+
rate: "standard",
|
|
1029
|
+
usd: vcpu(.00125, 2),
|
|
1030
|
+
from: "2026-09-01"
|
|
1031
|
+
},
|
|
1032
|
+
{
|
|
1033
|
+
provider: "ubicloud",
|
|
1034
|
+
rate: "premium",
|
|
1035
|
+
usd: vcpu(.0016, 2),
|
|
1036
|
+
from: "2025-05-01"
|
|
1037
|
+
},
|
|
1038
|
+
{
|
|
1039
|
+
provider: "ubicloud",
|
|
1040
|
+
rate: "premium",
|
|
1041
|
+
usd: vcpu(.002, 2),
|
|
1042
|
+
from: "2026-09-01"
|
|
1043
|
+
},
|
|
1044
|
+
{
|
|
1045
|
+
provider: "github",
|
|
1046
|
+
rate: "linux-1-core",
|
|
1047
|
+
usd: .002,
|
|
1048
|
+
from: "2026-11-11"
|
|
1049
|
+
},
|
|
1050
|
+
{
|
|
1051
|
+
provider: "github",
|
|
1052
|
+
rate: "linux-2-core",
|
|
1053
|
+
usd: .006,
|
|
1054
|
+
from: "2026-11-11"
|
|
1055
|
+
},
|
|
1056
|
+
{
|
|
1057
|
+
provider: "github",
|
|
1058
|
+
rate: "linux-arm-2-core",
|
|
1059
|
+
usd: .005,
|
|
1060
|
+
from: "2026-11-11"
|
|
1061
|
+
},
|
|
1062
|
+
{
|
|
1063
|
+
provider: "github",
|
|
1064
|
+
rate: "windows-2-core",
|
|
1065
|
+
usd: .01,
|
|
1066
|
+
from: "2026-11-11"
|
|
1067
|
+
},
|
|
1068
|
+
{
|
|
1069
|
+
provider: "github",
|
|
1070
|
+
rate: "windows-arm-2-core",
|
|
1071
|
+
usd: .01,
|
|
1072
|
+
from: "2026-11-11"
|
|
1073
|
+
},
|
|
1074
|
+
{
|
|
1075
|
+
provider: "github",
|
|
1076
|
+
rate: "macos",
|
|
1077
|
+
usd: .062,
|
|
1078
|
+
from: "2026-11-11"
|
|
1079
|
+
}
|
|
1080
|
+
];
|
|
1081
|
+
/** A UTC day (YYYY-MM-DD) as epoch ms at its midnight. */
|
|
1082
|
+
const dayMs = (day) => Date.parse(`${day}T00:00:00Z`);
|
|
1083
|
+
/**
|
|
1084
|
+
* Looks up price rows, leaving out any for a rate RATES doesn't list. Rows for the same rate and
|
|
1085
|
+
* day replace earlier ones in the list, so rows added on top of BASE_PRICES win.
|
|
1086
|
+
*/
|
|
1087
|
+
function priceBook(rows) {
|
|
1088
|
+
const byRate = /* @__PURE__ */ new Map();
|
|
1089
|
+
for (const row of rows) {
|
|
1090
|
+
if (!isRate(row.provider, row.rate)) continue;
|
|
1091
|
+
const key = `${row.provider}:${row.rate}`;
|
|
1092
|
+
const days = byRate.get(key) ?? /* @__PURE__ */ new Map();
|
|
1093
|
+
days.set(row.from, row);
|
|
1094
|
+
byRate.set(key, days);
|
|
1095
|
+
}
|
|
1096
|
+
const histories = new Map([...byRate].map(([key, days]) => [key, [...days.values()].sort((a, b) => a.from.localeCompare(b.from))]));
|
|
1097
|
+
const changes = /* @__PURE__ */ new Set();
|
|
1098
|
+
for (const history of histories.values()) for (const row of history.slice(1)) changes.add(dayMs(row.from));
|
|
1099
|
+
const history = (provider, rate) => histories.get(`${provider}:${rate}`) ?? [];
|
|
1100
|
+
return {
|
|
1101
|
+
usd(provider, rate, at) {
|
|
1102
|
+
let usd = null;
|
|
1103
|
+
for (const [i, row] of history(provider, rate).entries()) if (i === 0 || dayMs(row.from) <= at) usd = row.usd;
|
|
1104
|
+
return usd;
|
|
1105
|
+
},
|
|
1106
|
+
history,
|
|
1107
|
+
changes: [...changes].sort((a, b) => a - b)
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
priceBook(BASE_PRICES);
|
|
1111
|
+
// ../../packages/providers/src/index.ts
|
|
1112
|
+
/**
|
|
1113
|
+
* The hosted runner services a relay can send a job to. Each runs a job under the customer's own
|
|
1114
|
+
* account through its own GitHub App, which picks up any job queued with one of its labels, so
|
|
1115
|
+
* routing to one only means answering one of its labels. Each is a step in the runner order and an
|
|
1116
|
+
* input on the relay, both named by its id.
|
|
1117
|
+
*/
|
|
1118
|
+
const HOSTED_PROVIDER_IDS = [
|
|
1119
|
+
"blacksmith",
|
|
1120
|
+
"depot",
|
|
1121
|
+
"namespace",
|
|
1122
|
+
"warpbuild",
|
|
1123
|
+
"ubicloud",
|
|
1124
|
+
"runs-on"
|
|
1125
|
+
];
|
|
1126
|
+
const LABEL_PREFIXES = {
|
|
1127
|
+
blacksmith: ["blacksmith-"],
|
|
1128
|
+
depot: ["depot-"],
|
|
1129
|
+
namespace: ["namespace-profile-", "nscloud-"],
|
|
1130
|
+
warpbuild: ["warp-"],
|
|
1131
|
+
ubicloud: ["ubicloud-"],
|
|
1132
|
+
"runs-on": ["runs-on=", "runs-on/"]
|
|
1133
|
+
};
|
|
1134
|
+
const matches = (provider, lower) => LABEL_PREFIXES[provider].some((prefix) => lower.startsWith(prefix) || prefix.endsWith("-") && lower === prefix.slice(0, -1));
|
|
1135
|
+
/** The hosted provider whose runners a label asks for, or null. */
|
|
1136
|
+
function hostedProviderOf(label) {
|
|
1137
|
+
const lower = label.toLowerCase();
|
|
1138
|
+
return HOSTED_PROVIDER_IDS.find((id) => matches(id, lower)) ?? null;
|
|
1139
|
+
}
|
|
905
1140
|
// workflows.ts
|
|
906
1141
|
/** The relay version `init` writes. Bump it with each relayrunner/actions release. */
|
|
907
|
-
const RELAY_REF = "v1.0.0-beta.
|
|
1142
|
+
const RELAY_REF = "v1.0.0-beta.5";
|
|
908
1143
|
const RELAY_WORKFLOW = "relayrunner/actions/.github/workflows/relay.yml";
|
|
909
1144
|
const DEPLOY_SECRET = /\bsecrets\.(?!GITHUB_TOKEN\b)[A-Za-z_][A-Za-z0-9_]*/;
|
|
910
1145
|
const LINUX_PACKAGE_MANAGER = /(^|[\s;&|(])(sudo\s+)?(apt-get|apt|yum|dnf|apk)\s+(install|update|add)\b/m;
|
|
@@ -973,14 +1208,17 @@ function judge(file, id, job, workflow, relays, reusableOnly, options) {
|
|
|
973
1208
|
const lower = label.toLowerCase();
|
|
974
1209
|
let provider;
|
|
975
1210
|
let machine = "self-hosted";
|
|
976
|
-
|
|
977
|
-
|
|
1211
|
+
const hosted = hostedProviderOf(lower);
|
|
1212
|
+
if (/(^|-)windows-/.test(lower)) return skip("Windows jobs can't run on machines yet");
|
|
1213
|
+
if (hosted) {
|
|
1214
|
+
provider = hosted;
|
|
1215
|
+
if (lower.includes("macos")) machine = "macOS";
|
|
1216
|
+
} else if (/^(ubuntu|macos)-/.test(lower)) {
|
|
978
1217
|
provider = "github";
|
|
979
1218
|
if (lower.startsWith("macos-")) machine = "macOS";
|
|
980
|
-
} else if (lower
|
|
981
|
-
else if (lower === "relayrunner") return skip("already runs on RelayRunner");
|
|
1219
|
+
} else if (lower === "relayrunner") return skip("already runs on RelayRunner");
|
|
982
1220
|
else if (lower === "self-hosted") return skip("already runs on a self-hosted runner");
|
|
983
|
-
else return skip(`${label} isn't a GitHub-hosted or
|
|
1221
|
+
else return skip(`${label} isn't a GitHub-hosted or hosted provider label`);
|
|
984
1222
|
const warnings = jobWarnings(job, options);
|
|
985
1223
|
return {
|
|
986
1224
|
...base,
|
|
@@ -1331,6 +1569,18 @@ function shortFile(file) {
|
|
|
1331
1569
|
function colorDiff(diff) {
|
|
1332
1570
|
return diff.split("\n").map((line) => line.startsWith("+") && !line.startsWith("+++") ? styleText("green", line) : line.startsWith("-") && !line.startsWith("---") ? styleText("red", line) : styleText("dim", line)).join("\n");
|
|
1333
1571
|
}
|
|
1572
|
+
// machine-name.ts
|
|
1573
|
+
const MAX_LENGTH = 64;
|
|
1574
|
+
async function defaultMachineName(run$1 = run, system = platform(), host = hostname()) {
|
|
1575
|
+
const names = [];
|
|
1576
|
+
if (system === "darwin") for (const key of [
|
|
1577
|
+
"HostName",
|
|
1578
|
+
"ComputerName",
|
|
1579
|
+
"LocalHostName"
|
|
1580
|
+
]) names.push(await run$1("scutil", ["--get", key]));
|
|
1581
|
+
names.push(host.replace(/\.local$/i, ""));
|
|
1582
|
+
return (names.find((name) => name?.trim()) ?? "").trim().slice(0, MAX_LENGTH);
|
|
1583
|
+
}
|
|
1334
1584
|
// jit-config.ts
|
|
1335
1585
|
const GITHUB_HOSTS = [
|
|
1336
1586
|
/^github\.com$/,
|
|
@@ -1560,6 +1810,151 @@ function isAlive(pid) {
|
|
|
1560
1810
|
return error.code === "EPERM";
|
|
1561
1811
|
}
|
|
1562
1812
|
}
|
|
1813
|
+
// live.ts
|
|
1814
|
+
const INITIAL_STATE = {
|
|
1815
|
+
link: "connecting",
|
|
1816
|
+
paused: false,
|
|
1817
|
+
job: null
|
|
1818
|
+
};
|
|
1819
|
+
/** The state after a connection event. */
|
|
1820
|
+
function nextState(state, event) {
|
|
1821
|
+
switch (event.type) {
|
|
1822
|
+
case "connecting": return {
|
|
1823
|
+
...state,
|
|
1824
|
+
link: state.link === "online" ? "reconnecting" : state.link
|
|
1825
|
+
};
|
|
1826
|
+
case "connected": return {
|
|
1827
|
+
...state,
|
|
1828
|
+
link: "online"
|
|
1829
|
+
};
|
|
1830
|
+
case "disconnected": return {
|
|
1831
|
+
...state,
|
|
1832
|
+
link: "reconnecting"
|
|
1833
|
+
};
|
|
1834
|
+
case "run": return {
|
|
1835
|
+
...state,
|
|
1836
|
+
job: event.routeId
|
|
1837
|
+
};
|
|
1838
|
+
case "job": return event.update.state === "started" || event.update.routeId !== state.job ? state : {
|
|
1839
|
+
...state,
|
|
1840
|
+
job: null
|
|
1841
|
+
};
|
|
1842
|
+
case "paused": return {
|
|
1843
|
+
...state,
|
|
1844
|
+
paused: event.paused
|
|
1845
|
+
};
|
|
1846
|
+
default: return state;
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
/**
|
|
1850
|
+
* The terminal title for a state, such as "RelayRunner · M3P0 · Waiting for jobs". It leads with
|
|
1851
|
+
* the product so the tab says what's running in it, and ends with the part that changes.
|
|
1852
|
+
*/
|
|
1853
|
+
function titleFor(state, machine) {
|
|
1854
|
+
return `RelayRunner · ${machine} · ${statusText(state)}`;
|
|
1855
|
+
}
|
|
1856
|
+
function statusText({ link, paused, job }) {
|
|
1857
|
+
if (link === "connecting") return "Connecting…";
|
|
1858
|
+
if (link === "reconnecting") return job ? "Running a job, reconnecting…" : "Reconnecting…";
|
|
1859
|
+
if (job) return paused ? "Running a job, then paused" : "Running a job";
|
|
1860
|
+
return paused ? "Paused" : "Waiting for jobs";
|
|
1861
|
+
}
|
|
1862
|
+
const ESC = "\x1B";
|
|
1863
|
+
const BEL = "\x07";
|
|
1864
|
+
const SAVE_TITLE = `${ESC}[22;0t`;
|
|
1865
|
+
const RESTORE_TITLE = `${ESC}[23;0t`;
|
|
1866
|
+
function titleSequence(title) {
|
|
1867
|
+
return `${ESC}]0;${title.replace(/[\u0000-\u001f\u007f]/g, "")}${BEL}`;
|
|
1868
|
+
}
|
|
1869
|
+
/** What a key pressed in the terminal asks for. */
|
|
1870
|
+
function keyAction(key) {
|
|
1871
|
+
if (key === "") return "interrupt";
|
|
1872
|
+
if (key === "p" || key === "P") return "toggle-pause";
|
|
1873
|
+
return null;
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* Starts the live title (when stdout is a terminal) and the keys (when stdin is one): `p` calls
|
|
1877
|
+
* onTogglePause, and Ctrl-C is sent on as SIGINT, since raw mode stops the terminal doing that.
|
|
1878
|
+
*/
|
|
1879
|
+
function startLive(options) {
|
|
1880
|
+
const { stdin, stdout } = process;
|
|
1881
|
+
const showTitle = stdout.isTTY;
|
|
1882
|
+
const keys = stdin.isTTY;
|
|
1883
|
+
let state = INITIAL_STATE;
|
|
1884
|
+
let title = titleFor(state, options.machine);
|
|
1885
|
+
let ended = false;
|
|
1886
|
+
if (showTitle) stdout.write(SAVE_TITLE + titleSequence(title));
|
|
1887
|
+
const onKey = (key) => {
|
|
1888
|
+
const action = keyAction(key);
|
|
1889
|
+
if (action === "toggle-pause") options.onTogglePause(state);
|
|
1890
|
+
else if (action === "interrupt") try {
|
|
1891
|
+
process.kill(0, "SIGINT");
|
|
1892
|
+
} catch {
|
|
1893
|
+
process.emit("SIGINT", "SIGINT");
|
|
1894
|
+
}
|
|
1895
|
+
};
|
|
1896
|
+
if (keys) {
|
|
1897
|
+
stdin.setRawMode(true);
|
|
1898
|
+
stdin.setEncoding("utf8");
|
|
1899
|
+
stdin.on("data", onKey);
|
|
1900
|
+
stdin.resume();
|
|
1901
|
+
}
|
|
1902
|
+
return {
|
|
1903
|
+
get state() {
|
|
1904
|
+
return state;
|
|
1905
|
+
},
|
|
1906
|
+
onEvent(event) {
|
|
1907
|
+
if (keys && event.type === "connected" && state.link === "connecting") clack.log.message("Press p to pause or resume, Ctrl-C to go offline.");
|
|
1908
|
+
state = nextState(state, event);
|
|
1909
|
+
const next = titleFor(state, options.machine);
|
|
1910
|
+
if (showTitle && next !== title) stdout.write(titleSequence(next));
|
|
1911
|
+
title = next;
|
|
1912
|
+
},
|
|
1913
|
+
end() {
|
|
1914
|
+
if (ended) return;
|
|
1915
|
+
ended = true;
|
|
1916
|
+
if (showTitle) stdout.write(RESTORE_TITLE);
|
|
1917
|
+
if (keys) {
|
|
1918
|
+
stdin.off("data", onKey);
|
|
1919
|
+
stdin.setRawMode(false);
|
|
1920
|
+
stdin.pause();
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
};
|
|
1924
|
+
}
|
|
1925
|
+
// workspaces.ts
|
|
1926
|
+
const Workspace = z.object({
|
|
1927
|
+
id: z.string().min(1),
|
|
1928
|
+
name: z.string(),
|
|
1929
|
+
slug: z.string().nullish(),
|
|
1930
|
+
memberCount: z.number().int().nonnegative().optional()
|
|
1931
|
+
});
|
|
1932
|
+
const WorkspaceFields = {
|
|
1933
|
+
workspace: Workspace.nullish(),
|
|
1934
|
+
workspaces: z.array(Workspace).optional()
|
|
1935
|
+
};
|
|
1936
|
+
/** The machine's workspaces, from the list or else the single `workspace` an older gateway sends. */
|
|
1937
|
+
function readWorkspaces(body) {
|
|
1938
|
+
return body.workspaces ?? (body.workspace ? [body.workspace] : []);
|
|
1939
|
+
}
|
|
1940
|
+
/** Whether anyone else is in one of them, so teammates' jobs could run on the machine. */
|
|
1941
|
+
function hasTeammates(workspaces) {
|
|
1942
|
+
return workspaces.some((workspace) => (workspace.memberCount ?? 0) > 1);
|
|
1943
|
+
}
|
|
1944
|
+
/** "Acme", "Acme and atticoos", "Acme, Beta and atticoos". */
|
|
1945
|
+
function workspaceNames(workspaces) {
|
|
1946
|
+
const names = workspaces.map((workspace) => workspace.name);
|
|
1947
|
+
if (names.length <= 1) return names.join("");
|
|
1948
|
+
return `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`;
|
|
1949
|
+
}
|
|
1950
|
+
/** What "anyone" reaches: the one workspace by name, or "your workspaces". */
|
|
1951
|
+
function sharingScope(workspaces) {
|
|
1952
|
+
return workspaces.length === 1 ? workspaces[0].name : "your workspaces";
|
|
1953
|
+
}
|
|
1954
|
+
/** Said after signing in when the machine isn't in any workspace yet. */
|
|
1955
|
+
function noWorkspaceYet(machine, server) {
|
|
1956
|
+
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");
|
|
1957
|
+
}
|
|
1563
1958
|
// login.ts
|
|
1564
1959
|
const CLIENT_ID = "relayrunner-cli";
|
|
1565
1960
|
const DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
@@ -1588,12 +1983,7 @@ const ClaimResponse = z.object({
|
|
|
1588
1983
|
id: z.string().min(1),
|
|
1589
1984
|
name: z.string()
|
|
1590
1985
|
}),
|
|
1591
|
-
|
|
1592
|
-
id: z.string().min(1),
|
|
1593
|
-
name: z.string(),
|
|
1594
|
-
slug: z.string().nullish(),
|
|
1595
|
-
memberCount: z.number().int().nonnegative().optional()
|
|
1596
|
-
}),
|
|
1986
|
+
...WorkspaceFields,
|
|
1597
1987
|
token: z.string().min(1)
|
|
1598
1988
|
});
|
|
1599
1989
|
async function login(options) {
|
|
@@ -1664,7 +2054,6 @@ async function login(options) {
|
|
|
1664
2054
|
}, { authorization: `Bearer ${accessToken}` });
|
|
1665
2055
|
if (!claimResponse.ok) throw new LoginError("CLAIM_FAILED", `The gateway approved the sign-in but wouldn't enroll this machine (HTTP ${claimResponse.status}).`);
|
|
1666
2056
|
const claimed = ClaimResponse.parse(await claimResponse.json());
|
|
1667
|
-
const { memberCount, ...workspace } = claimed.workspace;
|
|
1668
2057
|
return {
|
|
1669
2058
|
credentials: {
|
|
1670
2059
|
server: new URL(options.server).origin,
|
|
@@ -1672,10 +2061,9 @@ async function login(options) {
|
|
|
1672
2061
|
id: claimed.machine.id,
|
|
1673
2062
|
name: claimed.machine.name
|
|
1674
2063
|
},
|
|
1675
|
-
workspace,
|
|
1676
2064
|
token: claimed.token
|
|
1677
2065
|
},
|
|
1678
|
-
|
|
2066
|
+
workspaces: readWorkspaces(claimed)
|
|
1679
2067
|
};
|
|
1680
2068
|
}
|
|
1681
2069
|
function openBrowser(url) {
|
|
@@ -1735,6 +2123,14 @@ async function setPaused(options) {
|
|
|
1735
2123
|
busy: parsed.data.machine.status?.state === "busy"
|
|
1736
2124
|
};
|
|
1737
2125
|
}
|
|
2126
|
+
/** setPaused with the machine's saved token, retrying with a newer one if it was rotated. */
|
|
2127
|
+
function pauseMachine(credentials, paused) {
|
|
2128
|
+
return withCurrentToken(credentials, (token) => setPaused({
|
|
2129
|
+
server: credentials.server,
|
|
2130
|
+
token,
|
|
2131
|
+
paused
|
|
2132
|
+
}));
|
|
2133
|
+
}
|
|
1738
2134
|
// share.ts
|
|
1739
2135
|
const SHARE_CHOICES = ["only-me", "anyone"];
|
|
1740
2136
|
const MachineSharing = z.enum(["only_me", "anyone"]);
|
|
@@ -1743,11 +2139,11 @@ function parseShareChoice(value) {
|
|
|
1743
2139
|
}
|
|
1744
2140
|
const toSharing = (choice) => choice === "only-me" ? "only_me" : "anyone";
|
|
1745
2141
|
const toChoice = (sharing) => sharing === "only_me" ? "only-me" : "anyone";
|
|
1746
|
-
function sharingMeaning(sharing,
|
|
1747
|
-
return sharing === "only_me" ? "runs only jobs you started" : `runs any job in ${
|
|
2142
|
+
function sharingMeaning(sharing, scope = "your workspaces") {
|
|
2143
|
+
return sharing === "only_me" ? "runs only jobs you started" : `runs any job in ${scope}, including teammates' and bots'`;
|
|
1748
2144
|
}
|
|
1749
|
-
function describeSharing(sharing,
|
|
1750
|
-
return `${toChoice(sharing)}: ${sharingMeaning(sharing,
|
|
2145
|
+
function describeSharing(sharing, scope) {
|
|
2146
|
+
return `${toChoice(sharing)}: ${sharingMeaning(sharing, scope)}`;
|
|
1751
2147
|
}
|
|
1752
2148
|
const SharingResponse = z.object({ machine: z.object({ sharing: MachineSharing }) });
|
|
1753
2149
|
async function setSharing(options) {
|
|
@@ -1805,12 +2201,7 @@ const WhoamiResponse = z.object({
|
|
|
1805
2201
|
paused: z.object({ by: z.string().nullable() }).nullish(),
|
|
1806
2202
|
sharing: z.enum(["only_me", "anyone"]).optional()
|
|
1807
2203
|
}),
|
|
1808
|
-
|
|
1809
|
-
id: z.string().min(1),
|
|
1810
|
-
name: z.string(),
|
|
1811
|
-
slug: z.string().nullish(),
|
|
1812
|
-
memberCount: z.number().int().nonnegative().optional()
|
|
1813
|
-
}),
|
|
2204
|
+
...WorkspaceFields,
|
|
1814
2205
|
enrolledBy: z.object({
|
|
1815
2206
|
name: z.string(),
|
|
1816
2207
|
email: z.string()
|
|
@@ -1851,7 +2242,7 @@ const DEFAULT_SERVER = "https://app.relayrunner.app";
|
|
|
1851
2242
|
const connectCommand = defineCommand({
|
|
1852
2243
|
meta: {
|
|
1853
2244
|
name: "connect",
|
|
1854
|
-
description: "Put this machine online for your
|
|
2245
|
+
description: "Put this machine online for your workspaces and run the jobs the gateway sends it. Signs in on first run; Ctrl-C takes the machine offline."
|
|
1855
2246
|
},
|
|
1856
2247
|
args: {
|
|
1857
2248
|
server: {
|
|
@@ -1860,11 +2251,11 @@ const connectCommand = defineCommand({
|
|
|
1860
2251
|
},
|
|
1861
2252
|
name: {
|
|
1862
2253
|
type: "string",
|
|
1863
|
-
description: "Suggested machine name when signing in (default: this computer's
|
|
2254
|
+
description: "Suggested machine name when signing in (default: this computer's name)"
|
|
1864
2255
|
},
|
|
1865
2256
|
share: {
|
|
1866
2257
|
type: "string",
|
|
1867
|
-
description: "Who can run jobs on this machine: only-me (jobs you started) or anyone in
|
|
2258
|
+
description: "Who can run jobs on this machine: only-me (jobs you started) or anyone in your workspaces. Skips the question."
|
|
1868
2259
|
}
|
|
1869
2260
|
},
|
|
1870
2261
|
async run({ args }) {
|
|
@@ -1889,43 +2280,64 @@ async function connectMachine(args) {
|
|
|
1889
2280
|
}
|
|
1890
2281
|
if (!credentials) credentials = await enroll(server, args.name, platform, share);
|
|
1891
2282
|
else {
|
|
1892
|
-
clack.log.info(`Machine ${credentials.machine.name}
|
|
1893
|
-
if (share) await applySharing(credentials, share);
|
|
2283
|
+
clack.log.info(`Machine ${credentials.machine.name} (${credentials.server})`);
|
|
2284
|
+
if (share) await applySharing(credentials, share, null);
|
|
1894
2285
|
}
|
|
1895
2286
|
if (process.stdin.isTTY && process.stdout.isTTY) await offerSetup();
|
|
1896
2287
|
const runner = await ensureRunner({ log: (line) => clack.log.info(line) });
|
|
1897
2288
|
const device = await detectDevice();
|
|
1898
2289
|
const stop = new AbortController();
|
|
2290
|
+
const enrolled = credentials;
|
|
2291
|
+
let toggling = false;
|
|
2292
|
+
const live = startLive({
|
|
2293
|
+
machine: enrolled.machine.name,
|
|
2294
|
+
onTogglePause: async ({ paused }) => {
|
|
2295
|
+
if (toggling || stop.signal.aborted) return;
|
|
2296
|
+
toggling = true;
|
|
2297
|
+
const result = await pauseMachine(enrolled, !paused);
|
|
2298
|
+
toggling = false;
|
|
2299
|
+
if (result.status === "failed") clack.log.error(`Couldn't ${paused ? "resume" : "pause"}: ${result.reason}.`);
|
|
2300
|
+
}
|
|
2301
|
+
});
|
|
1899
2302
|
const onInterrupt = () => {
|
|
1900
|
-
if (stop.signal.aborted)
|
|
2303
|
+
if (stop.signal.aborted) {
|
|
2304
|
+
live.end();
|
|
2305
|
+
process.exit(130);
|
|
2306
|
+
}
|
|
1901
2307
|
stop.abort();
|
|
1902
2308
|
};
|
|
1903
2309
|
process.on("SIGINT", onInterrupt);
|
|
1904
2310
|
let online = false;
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
report,
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
2311
|
+
let end;
|
|
2312
|
+
try {
|
|
2313
|
+
end = await connect({
|
|
2314
|
+
server: credentials.server,
|
|
2315
|
+
token: credentials.token,
|
|
2316
|
+
hello: {
|
|
2317
|
+
machineId: credentials.machine.id,
|
|
2318
|
+
...platform,
|
|
2319
|
+
runnerVersion: runner.version,
|
|
2320
|
+
device
|
|
2321
|
+
},
|
|
2322
|
+
runJob: (run, report) => runJob(run, {
|
|
2323
|
+
runner,
|
|
2324
|
+
report,
|
|
2325
|
+
onChecked: (target) => {
|
|
2326
|
+
if (target) clack.log.info(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} Job ${run.routeId} is from ${target}`);
|
|
2327
|
+
}
|
|
2328
|
+
}),
|
|
2329
|
+
saveToken: (token) => saveRotatedToken(credentials, token),
|
|
2330
|
+
onEvent: (event) => {
|
|
2331
|
+
if (event.type === "connected") online = true;
|
|
2332
|
+
show(event);
|
|
2333
|
+
live.onEvent(event);
|
|
2334
|
+
},
|
|
2335
|
+
signal: stop.signal
|
|
2336
|
+
});
|
|
2337
|
+
} finally {
|
|
2338
|
+
live.end();
|
|
2339
|
+
process.off("SIGINT", onInterrupt);
|
|
2340
|
+
}
|
|
1929
2341
|
switch (end.reason) {
|
|
1930
2342
|
case "stopped":
|
|
1931
2343
|
clack.outro("Offline.");
|
|
@@ -1933,13 +2345,13 @@ async function connectMachine(args) {
|
|
|
1933
2345
|
case "revoked":
|
|
1934
2346
|
deleteCredentials();
|
|
1935
2347
|
if (!online) {
|
|
1936
|
-
clack.log.warn("This machine was removed
|
|
2348
|
+
clack.log.warn("This machine was removed or its token is no longer valid. If you didn't remove it, another copy of its token may have signed in elsewhere: check the Runners page. Signing in again.");
|
|
1937
2349
|
return connectMachine({
|
|
1938
2350
|
...args,
|
|
1939
2351
|
server: credentials.server
|
|
1940
2352
|
});
|
|
1941
2353
|
}
|
|
1942
|
-
clack.log.error("This machine was removed
|
|
2354
|
+
clack.log.error("This machine was removed or its token is no longer valid. If you didn't remove it, another copy of its token may have signed in elsewhere: check the Runners page and revoke it if so.");
|
|
1943
2355
|
clack.outro("Run `relayrunner connect` again to sign in.");
|
|
1944
2356
|
process.exitCode = 1;
|
|
1945
2357
|
break;
|
|
@@ -1954,7 +2366,7 @@ async function connectMachine(args) {
|
|
|
1954
2366
|
process.exitCode = 1;
|
|
1955
2367
|
}
|
|
1956
2368
|
}
|
|
1957
|
-
async function askSharing(
|
|
2369
|
+
async function askSharing(workspaces) {
|
|
1958
2370
|
const picked = await clack.select({
|
|
1959
2371
|
message: "Who can run jobs on this machine?",
|
|
1960
2372
|
options: [{
|
|
@@ -1963,7 +2375,7 @@ async function askSharing(workspace) {
|
|
|
1963
2375
|
hint: "jobs you started"
|
|
1964
2376
|
}, {
|
|
1965
2377
|
value: "anyone",
|
|
1966
|
-
label: `Anyone in ${
|
|
2378
|
+
label: `Anyone in ${sharingScope(workspaces)}`,
|
|
1967
2379
|
hint: "teammates' and bots' jobs too, from repos you can open"
|
|
1968
2380
|
}],
|
|
1969
2381
|
initialValue: "only-me"
|
|
@@ -1974,7 +2386,7 @@ async function askSharing(workspace) {
|
|
|
1974
2386
|
}
|
|
1975
2387
|
return picked;
|
|
1976
2388
|
}
|
|
1977
|
-
async function applySharing(credentials, choice) {
|
|
2389
|
+
async function applySharing(credentials, choice, workspaces) {
|
|
1978
2390
|
const result = await withCurrentToken(credentials, (token) => setSharing({
|
|
1979
2391
|
server: credentials.server,
|
|
1980
2392
|
token,
|
|
@@ -1982,7 +2394,7 @@ async function applySharing(credentials, choice) {
|
|
|
1982
2394
|
}));
|
|
1983
2395
|
switch (result.status) {
|
|
1984
2396
|
case "ok":
|
|
1985
|
-
clack.log.info(`Sharing: ${describeSharing(result.sharing,
|
|
2397
|
+
clack.log.info(`Sharing: ${describeSharing(result.sharing, workspaces ? sharingScope(workspaces) : void 0)}`);
|
|
1986
2398
|
break;
|
|
1987
2399
|
case "revoked": break;
|
|
1988
2400
|
case "failed": clack.log.warn(`Couldn't set sharing: ${result.reason}. Run \`relayrunner share ${choice}\` to try again.`);
|
|
@@ -1991,7 +2403,7 @@ async function applySharing(credentials, choice) {
|
|
|
1991
2403
|
const loginCommand = defineCommand({
|
|
1992
2404
|
meta: {
|
|
1993
2405
|
name: "login",
|
|
1994
|
-
description: "Sign this machine in
|
|
2406
|
+
description: "Sign this machine in without putting it online. It's in all your workspaces. Run `relayrunner connect` afterwards to take jobs."
|
|
1995
2407
|
},
|
|
1996
2408
|
args: {
|
|
1997
2409
|
server: {
|
|
@@ -2000,11 +2412,11 @@ const loginCommand = defineCommand({
|
|
|
2000
2412
|
},
|
|
2001
2413
|
name: {
|
|
2002
2414
|
type: "string",
|
|
2003
|
-
description: "Suggested machine name (default: this computer's
|
|
2415
|
+
description: "Suggested machine name (default: this computer's name)"
|
|
2004
2416
|
},
|
|
2005
2417
|
share: {
|
|
2006
2418
|
type: "string",
|
|
2007
|
-
description: "Who can run jobs on this machine: only-me (jobs you started) or anyone in
|
|
2419
|
+
description: "Who can run jobs on this machine: only-me (jobs you started) or anyone in your workspaces. Skips the question."
|
|
2008
2420
|
}
|
|
2009
2421
|
},
|
|
2010
2422
|
async run({ args }) {
|
|
@@ -2014,15 +2426,18 @@ const loginCommand = defineCommand({
|
|
|
2014
2426
|
const saved = readCredentials();
|
|
2015
2427
|
const server = serverFor(args.server, saved);
|
|
2016
2428
|
if (saved && saved.server === server) {
|
|
2017
|
-
|
|
2429
|
+
const result = await withCurrentToken(saved, (token) => whoami({
|
|
2018
2430
|
server,
|
|
2019
2431
|
token
|
|
2020
|
-
}))
|
|
2021
|
-
|
|
2022
|
-
|
|
2432
|
+
}));
|
|
2433
|
+
if (result.status !== "revoked") {
|
|
2434
|
+
const workspaces = result.status === "ok" ? readWorkspaces(result.identity) : null;
|
|
2435
|
+
if (share) await applySharing(saved, share, workspaces);
|
|
2436
|
+
const where = workspaces?.length ? ` in ${workspaceNames(workspaces)}` : "";
|
|
2437
|
+
clack.outro(`Already signed in as ${saved.machine.name}${where}. Run \`relayrunner connect\` to go online.`);
|
|
2023
2438
|
return;
|
|
2024
2439
|
}
|
|
2025
|
-
clack.log.warn(`${saved.machine.name} is no longer
|
|
2440
|
+
clack.log.warn(`${saved.machine.name} is no longer signed in. Signing in again.`);
|
|
2026
2441
|
} else if (saved) clack.log.warn(`This machine is enrolled with ${saved.server}, not ${server}. Signing in again.`);
|
|
2027
2442
|
await enroll(server, args.name, machinePlatform(), share);
|
|
2028
2443
|
clack.outro("Run `relayrunner connect` to put this machine online.");
|
|
@@ -2051,16 +2466,17 @@ function machinePlatform() {
|
|
|
2051
2466
|
}
|
|
2052
2467
|
/** Signs in through the browser, saves the machine token, and settles who can run jobs here. */
|
|
2053
2468
|
async function enroll(server, name, platform, share) {
|
|
2054
|
-
const
|
|
2055
|
-
const credentials = signedIn.credentials;
|
|
2469
|
+
const { credentials, workspaces } = await signIn(server, name || await defaultMachineName(), platform);
|
|
2056
2470
|
writeCredentials(credentials);
|
|
2057
|
-
|
|
2471
|
+
const where = workspaces.length ? ` in ${workspaceNames(workspaces)}` : "";
|
|
2472
|
+
clack.log.success(`Enrolled as ${credentials.machine.name}${where}. Token saved to ${credentialsPath()}.`);
|
|
2473
|
+
if (!workspaces.length) clack.log.warn(noWorkspaceYet(credentials.machine.name, server));
|
|
2058
2474
|
let choice = share;
|
|
2059
|
-
if (!choice && (
|
|
2060
|
-
if (process.stdin.isTTY && process.stdout.isTTY) choice = await askSharing(
|
|
2475
|
+
if (!choice && hasTeammates(workspaces)) {
|
|
2476
|
+
if (process.stdin.isTTY && process.stdout.isTTY) choice = await askSharing(workspaces);
|
|
2061
2477
|
else clack.log.info("Only jobs you started run here. `relayrunner share anyone` lets teammates' jobs run here too.");
|
|
2062
2478
|
}
|
|
2063
|
-
if (choice) await applySharing(credentials, choice);
|
|
2479
|
+
if (choice) await applySharing(credentials, choice, workspaces);
|
|
2064
2480
|
return credentials;
|
|
2065
2481
|
}
|
|
2066
2482
|
async function signIn(server, name, platform) {
|
|
@@ -2102,7 +2518,7 @@ function show(event) {
|
|
|
2102
2518
|
clack.log.step(`${at} Starting job ${event.routeId}`);
|
|
2103
2519
|
break;
|
|
2104
2520
|
case "paused":
|
|
2105
|
-
if (event.paused) clack.log.warn(`${at} Paused${event.by ? ` by ${event.by}` : ""}. Staying online, but new jobs skip this machine until it's resumed
|
|
2521
|
+
if (event.paused) clack.log.warn(`${at} Paused${event.by ? ` by ${event.by}` : ""}. Staying online, but new jobs skip this machine until it's resumed.${process.stdin.isTTY ? " Press p to resume." : ""}`);
|
|
2106
2522
|
else clack.log.success(`${at} Resumed${event.by ? ` by ${event.by}` : ""}. Waiting for jobs.`);
|
|
2107
2523
|
break;
|
|
2108
2524
|
case "token-not-saved":
|
|
@@ -2124,7 +2540,7 @@ function show(event) {
|
|
|
2124
2540
|
const whoamiCommand = defineCommand({
|
|
2125
2541
|
meta: {
|
|
2126
2542
|
name: "whoami",
|
|
2127
|
-
description: "Show which machine
|
|
2543
|
+
description: "Show which machine this computer is signed in as and the workspaces it's in, checked with the gateway."
|
|
2128
2544
|
},
|
|
2129
2545
|
args: {
|
|
2130
2546
|
server: {
|
|
@@ -2151,8 +2567,7 @@ const whoamiCommand = defineCommand({
|
|
|
2151
2567
|
}
|
|
2152
2568
|
const saved = {
|
|
2153
2569
|
server: credentials.server,
|
|
2154
|
-
machine: credentials.machine
|
|
2155
|
-
workspace: credentials.workspace
|
|
2570
|
+
machine: credentials.machine
|
|
2156
2571
|
};
|
|
2157
2572
|
const result = await withCurrentToken(credentials, (token) => whoami({
|
|
2158
2573
|
server: credentials.server,
|
|
@@ -2167,7 +2582,7 @@ const whoamiCommand = defineCommand({
|
|
|
2167
2582
|
});
|
|
2168
2583
|
break;
|
|
2169
2584
|
case "revoked":
|
|
2170
|
-
print(`${credentials.machine.name} was removed
|
|
2585
|
+
print(`${credentials.machine.name} was removed or its token is no longer valid.\nRun \`relayrunner connect\` to sign in again.`, {
|
|
2171
2586
|
status: "revoked",
|
|
2172
2587
|
...saved
|
|
2173
2588
|
});
|
|
@@ -2182,20 +2597,21 @@ const whoamiCommand = defineCommand({
|
|
|
2182
2597
|
}
|
|
2183
2598
|
});
|
|
2184
2599
|
function describeIdentity(server, identity) {
|
|
2185
|
-
const { machine,
|
|
2600
|
+
const { machine, enrolledBy } = identity;
|
|
2601
|
+
const workspaces = readWorkspaces(identity);
|
|
2186
2602
|
const status = (machine.status.online ? `online${machine.status.state ? `, ${machine.status.state}` : ""}` : "offline") + (machine.paused ? `, paused${machine.paused.by ? ` by ${machine.paused.by}` : ""}` : "");
|
|
2187
2603
|
const enrolled = [enrolledBy && `by ${enrolledBy.name} <${enrolledBy.email}>`, `on ${new Date(machine.createdAt).toLocaleDateString()}`].filter(Boolean).join(" ");
|
|
2188
2604
|
return table(`${machine.name} (${machine.id})`, [
|
|
2189
|
-
["
|
|
2605
|
+
["Workspaces", workspaces.length ? workspaceNames(workspaces) : "none yet: install RelayRunner on GitHub to get one"],
|
|
2190
2606
|
["Platform", [machine.os, machine.arch].filter(Boolean).join(" ") || "unknown"],
|
|
2191
2607
|
["Enrolled", enrolled],
|
|
2192
2608
|
["Status", status],
|
|
2193
|
-
...machine.sharing ? [["Sharing", describeSharing(machine.sharing,
|
|
2609
|
+
...machine.sharing ? [["Sharing", describeSharing(machine.sharing, sharingScope(workspaces))]] : [],
|
|
2194
2610
|
["Gateway", server]
|
|
2195
2611
|
]);
|
|
2196
2612
|
}
|
|
2197
2613
|
function describeSaved(saved) {
|
|
2198
|
-
return table(`${saved.machine.name} (${saved.machine.id})`, [["
|
|
2614
|
+
return table(`${saved.machine.name} (${saved.machine.id})`, [["Gateway", saved.server]]);
|
|
2199
2615
|
}
|
|
2200
2616
|
function table(title, rows) {
|
|
2201
2617
|
const width = Math.max(...rows.map(([label]) => label.length));
|
|
@@ -2214,18 +2630,14 @@ function pauseCommand(paused) {
|
|
|
2214
2630
|
process.exitCode = 1;
|
|
2215
2631
|
return;
|
|
2216
2632
|
}
|
|
2217
|
-
const result = await
|
|
2218
|
-
server: credentials.server,
|
|
2219
|
-
token,
|
|
2220
|
-
paused
|
|
2221
|
-
}));
|
|
2633
|
+
const result = await pauseMachine(credentials, paused);
|
|
2222
2634
|
const name = credentials.machine.name;
|
|
2223
2635
|
switch (result.status) {
|
|
2224
2636
|
case "ok":
|
|
2225
2637
|
console.log(paused ? `Paused ${name}. It stays connected, and new jobs will skip it.${result.busy ? "\nIt finishes the job it's running first." : ""}\nRun \`relayrunner resume\` to take jobs again.` : `Resumed ${name}. Jobs can route here again.`);
|
|
2226
2638
|
break;
|
|
2227
2639
|
case "revoked":
|
|
2228
|
-
console.error(`${name} was removed
|
|
2640
|
+
console.error(`${name} was removed or its token is no longer valid.\nRun \`relayrunner connect\` to sign in again.`);
|
|
2229
2641
|
process.exitCode = 1;
|
|
2230
2642
|
break;
|
|
2231
2643
|
case "failed":
|
|
@@ -2238,7 +2650,7 @@ function pauseCommand(paused) {
|
|
|
2238
2650
|
const shareCommand = defineCommand({
|
|
2239
2651
|
meta: {
|
|
2240
2652
|
name: "share",
|
|
2241
|
-
description: "Show or change who can run jobs on this machine: only-me (jobs you started) or anyone in
|
|
2653
|
+
description: "Show or change who can run jobs on this machine: only-me (jobs you started) or anyone in your workspaces."
|
|
2242
2654
|
},
|
|
2243
2655
|
args: { who: {
|
|
2244
2656
|
type: "positional",
|
|
@@ -2253,9 +2665,8 @@ const shareCommand = defineCommand({
|
|
|
2253
2665
|
return;
|
|
2254
2666
|
}
|
|
2255
2667
|
const { name } = credentials.machine;
|
|
2256
|
-
const workspace = credentials.workspace.name;
|
|
2257
2668
|
const revoked = () => {
|
|
2258
|
-
console.error(`${name} was removed
|
|
2669
|
+
console.error(`${name} was removed or its token is no longer valid.\nRun \`relayrunner connect\` to sign in again.`);
|
|
2259
2670
|
process.exitCode = 1;
|
|
2260
2671
|
};
|
|
2261
2672
|
if (args.who) {
|
|
@@ -2276,7 +2687,7 @@ const shareCommand = defineCommand({
|
|
|
2276
2687
|
process.exitCode = 1;
|
|
2277
2688
|
return;
|
|
2278
2689
|
}
|
|
2279
|
-
console.log(`${name} now ${sharingMeaning(result.sharing
|
|
2690
|
+
console.log(`${name} now ${sharingMeaning(result.sharing)}.`);
|
|
2280
2691
|
return;
|
|
2281
2692
|
}
|
|
2282
2693
|
const result = await withCurrentToken(credentials, (token) => whoami({
|
|
@@ -2296,8 +2707,10 @@ const shareCommand = defineCommand({
|
|
|
2296
2707
|
return;
|
|
2297
2708
|
}
|
|
2298
2709
|
const other = sharing === "only_me" ? "anyone" : "only-me";
|
|
2299
|
-
const
|
|
2300
|
-
|
|
2710
|
+
const workspaces = readWorkspaces(result.identity);
|
|
2711
|
+
const lines = [`${name} ${sharingMeaning(sharing, sharingScope(workspaces))} (${toChoice(sharing)}).`];
|
|
2712
|
+
if (!workspaces.length) lines.push(`${name} isn't in a workspace yet, so this matters once it is.`);
|
|
2713
|
+
else if (workspaces.every((workspace) => workspace.memberCount === 1)) lines.push(`Nobody else is in ${sharingScope(workspaces)} yet, so this matters once a teammate joins.`);
|
|
2301
2714
|
lines.push(`Change it with \`relayrunner share ${other}\`.`);
|
|
2302
2715
|
console.log(lines.join("\n"));
|
|
2303
2716
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "relayrunner",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Run GitHub Actions jobs on your machine through the RelayRunner gateway.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@relayrunner/machine-protocol": "0.0.0",
|
|
28
|
+
"@relayrunner/providers": "0.0.0",
|
|
28
29
|
"@types/ws": "^8.18.2",
|
|
29
30
|
"tsdown": "^0.23.5",
|
|
30
31
|
"ws": "^8.22.1"
|