@ricsam/r5d-worker 0.0.5 → 0.0.6
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 +1 -1
- package/dist/cjs/main.cjs +20 -11
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/main.mjs +20 -11
- package/dist/mjs/package.json +1 -1
- package/dist/types/git-identity.d.ts +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ r5d-worker --version
|
|
|
10
10
|
The worker uses the existing `r5dctl` config file and accepts `R5D_WORKER_TOKEN` or `R5D_API_KEY`. Project checkouts are managed under:
|
|
11
11
|
|
|
12
12
|
```text
|
|
13
|
-
~/.r5d/projects/<repo
|
|
13
|
+
~/.r5d/projects/<namespace-repo>/<branch-name>
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
Visible branch checkouts use GitHub `origin` remotes. r5d internal sync git metadata lives separately under `~/.r5d/sync`.
|
package/dist/cjs/main.cjs
CHANGED
|
@@ -28,6 +28,7 @@ var import_node_path = __toESM(require("node:path"), 1);
|
|
|
28
28
|
var import_node_crypto = require("node:crypto");
|
|
29
29
|
var import_node_os2 = require("node:os");
|
|
30
30
|
var import_node_child_process = require("node:child_process");
|
|
31
|
+
var import_git_identity = require("./git-identity.cjs");
|
|
31
32
|
const DEFAULT_BASE_URL = "https://r5d.dev";
|
|
32
33
|
const WORKER_PACKAGE_NAME = "@ricsam/r5d-worker";
|
|
33
34
|
const LABEL_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,62}$/;
|
|
@@ -35,10 +36,13 @@ const BRANCH_RE = /^[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9]$|^[A-Za-z0-9]$/;
|
|
|
35
36
|
const DEFAULT_READ_LIMIT = 2e3;
|
|
36
37
|
const MAX_LINE_LENGTH = 2e3;
|
|
37
38
|
const MAX_SYNC_DIFF_BYTES = 5 * 1024 * 1024;
|
|
39
|
+
const R5D_REMOTE_NAME = "r5d";
|
|
40
|
+
const LEGACY_BUILD_IT_NOW_REMOTE_NAME = "build-it-now";
|
|
38
41
|
const activeProcesses = /* @__PURE__ */ new Map();
|
|
39
42
|
const activePtys = /* @__PURE__ */ new Map();
|
|
40
43
|
const branchLocks = /* @__PURE__ */ new Map();
|
|
41
44
|
let containerRegistryCredential = null;
|
|
45
|
+
let visibleGitIdentity = null;
|
|
42
46
|
function defaultConfigPath() {
|
|
43
47
|
return import_node_path.default.join(import_node_os.default.homedir(), ".config", "r5d", "r5dctl", "config.json");
|
|
44
48
|
}
|
|
@@ -601,15 +605,19 @@ function ensureVisibleGitCheckout(input) {
|
|
|
601
605
|
}
|
|
602
606
|
ensureOriginRemote(branchPath, input.githubRemoteUrl);
|
|
603
607
|
configureVisibleGitHubAuth(branchPath, input.githubRemoteUrl, input.githubAuthHeader);
|
|
608
|
+
(0, import_git_identity.configureVisibleGitIdentity)(branchPath, visibleGitIdentity, runGit);
|
|
604
609
|
tryGit(["fetch", "origin", "--prune"], { cwd: branchPath, auth: input.githubAuth });
|
|
605
610
|
checkoutVisibleBranch({ branchPath, branchName: input.branchName, defaultBranch: input.defaultBranch });
|
|
606
611
|
return branchPath;
|
|
607
612
|
}
|
|
608
613
|
function configureInternalRepo(context, remoteUrl) {
|
|
609
|
-
if (tryInternalGit(context, ["remote", "get-url",
|
|
610
|
-
runInternalGit(context, ["remote", "set-url",
|
|
614
|
+
if (tryInternalGit(context, ["remote", "get-url", R5D_REMOTE_NAME])) {
|
|
615
|
+
runInternalGit(context, ["remote", "set-url", R5D_REMOTE_NAME, remoteUrl]);
|
|
611
616
|
} else {
|
|
612
|
-
runInternalGit(context, ["remote", "add",
|
|
617
|
+
runInternalGit(context, ["remote", "add", R5D_REMOTE_NAME, remoteUrl]);
|
|
618
|
+
}
|
|
619
|
+
if (tryInternalGit(context, ["remote", "get-url", LEGACY_BUILD_IT_NOW_REMOTE_NAME])) {
|
|
620
|
+
runInternalGit(context, ["remote", "remove", LEGACY_BUILD_IT_NOW_REMOTE_NAME]);
|
|
613
621
|
}
|
|
614
622
|
runInternalGitDir(context, ["config", "user.name", "r5d.dev Worker"]);
|
|
615
623
|
runInternalGitDir(context, ["config", "user.email", "worker@r5d.dev"]);
|
|
@@ -625,9 +633,9 @@ function ensureInternalSyncGit(input) {
|
|
|
625
633
|
const context = { gitDir, workTree: input.branchPath, auth };
|
|
626
634
|
const remoteUrl = internalRemoteUrlFor(input.baseUrl, input.projectId, input.manifest);
|
|
627
635
|
configureInternalRepo(context, remoteUrl);
|
|
628
|
-
runInternalGit(context, ["fetch",
|
|
629
|
-
const hasRemoteBranch = tryInternalGit(context, ["show-ref", "--verify", "--quiet", `refs/remotes
|
|
630
|
-
const target = hasRemoteBranch ? `refs/remotes
|
|
636
|
+
runInternalGit(context, ["fetch", R5D_REMOTE_NAME, "--prune", `+refs/heads/*:refs/remotes/${R5D_REMOTE_NAME}/*`]);
|
|
637
|
+
const hasRemoteBranch = tryInternalGit(context, ["show-ref", "--verify", "--quiet", `refs/remotes/${R5D_REMOTE_NAME}/${input.branchName}`]);
|
|
638
|
+
const target = hasRemoteBranch ? `refs/remotes/${R5D_REMOTE_NAME}/${input.branchName}` : `refs/remotes/${R5D_REMOTE_NAME}/main`;
|
|
631
639
|
const hasHead = tryInternalGit(context, ["rev-parse", "--verify", "HEAD"]);
|
|
632
640
|
if (!hasHead || !hasInternalWorktreeChanges(context)) {
|
|
633
641
|
runInternalGit(context, ["checkout", "-f", "-B", input.branchName, target]);
|
|
@@ -896,7 +904,7 @@ function syncBranch(input) {
|
|
|
896
904
|
});
|
|
897
905
|
runInternalGit(workspace.internalGit, ["commit", "-m", message]);
|
|
898
906
|
const commitHash = getInternalCommitHash(workspace.internalGit);
|
|
899
|
-
runInternalGit(workspace.internalGit, ["push",
|
|
907
|
+
runInternalGit(workspace.internalGit, ["push", R5D_REMOTE_NAME, `HEAD:refs/heads/${input.branchName}`]);
|
|
900
908
|
return {
|
|
901
909
|
type: "sync",
|
|
902
910
|
changed: true,
|
|
@@ -927,8 +935,8 @@ function confirmLargeDiff(input) {
|
|
|
927
935
|
}
|
|
928
936
|
function pullBranch(input) {
|
|
929
937
|
const workspace = ensureOperationBranch(input);
|
|
930
|
-
runInternalGit(workspace.internalGit, ["fetch",
|
|
931
|
-
const target = input.commitHash ??
|
|
938
|
+
runInternalGit(workspace.internalGit, ["fetch", R5D_REMOTE_NAME, "--prune", `+refs/heads/*:refs/remotes/${R5D_REMOTE_NAME}/*`]);
|
|
939
|
+
const target = input.commitHash ?? `${R5D_REMOTE_NAME}/${input.branchName}`;
|
|
932
940
|
runInternalGit(workspace.internalGit, ["reset", "--hard", target]);
|
|
933
941
|
runInternalGit(workspace.internalGit, ["clean", "-fd", "--", ".", ":(exclude).git"]);
|
|
934
942
|
return {
|
|
@@ -1254,8 +1262,8 @@ function openPty(input) {
|
|
|
1254
1262
|
...process.env,
|
|
1255
1263
|
...containerRegistryEnv(),
|
|
1256
1264
|
...input.message.env ?? {},
|
|
1257
|
-
|
|
1258
|
-
|
|
1265
|
+
R5D_PROJECT_ID: input.projectId,
|
|
1266
|
+
R5D_BRANCH_NAME: input.message.branchName
|
|
1259
1267
|
}
|
|
1260
1268
|
},
|
|
1261
1269
|
onOpened: () => {
|
|
@@ -1394,6 +1402,7 @@ async function startWorker(options) {
|
|
|
1394
1402
|
}
|
|
1395
1403
|
if (message.type === "project_manifest") {
|
|
1396
1404
|
configureContainerRegistryAuth(message.githubContainerRegistry);
|
|
1405
|
+
visibleGitIdentity = message.gitIdentity;
|
|
1397
1406
|
manifestByProjectId.clear();
|
|
1398
1407
|
for (const project of message.projects) {
|
|
1399
1408
|
manifestByProjectId.set(project.projectId, project);
|
package/dist/cjs/package.json
CHANGED
package/dist/mjs/main.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import path from "node:path";
|
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { hostname } from "node:os";
|
|
7
7
|
import { spawn as spawnChildProcess } from "node:child_process";
|
|
8
|
+
import { configureVisibleGitIdentity } from "./git-identity.mjs";
|
|
8
9
|
const DEFAULT_BASE_URL = "https://r5d.dev";
|
|
9
10
|
const WORKER_PACKAGE_NAME = "@ricsam/r5d-worker";
|
|
10
11
|
const LABEL_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,62}$/;
|
|
@@ -12,10 +13,13 @@ const BRANCH_RE = /^[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9]$|^[A-Za-z0-9]$/;
|
|
|
12
13
|
const DEFAULT_READ_LIMIT = 2e3;
|
|
13
14
|
const MAX_LINE_LENGTH = 2e3;
|
|
14
15
|
const MAX_SYNC_DIFF_BYTES = 5 * 1024 * 1024;
|
|
16
|
+
const R5D_REMOTE_NAME = "r5d";
|
|
17
|
+
const LEGACY_BUILD_IT_NOW_REMOTE_NAME = "build-it-now";
|
|
15
18
|
const activeProcesses = /* @__PURE__ */ new Map();
|
|
16
19
|
const activePtys = /* @__PURE__ */ new Map();
|
|
17
20
|
const branchLocks = /* @__PURE__ */ new Map();
|
|
18
21
|
let containerRegistryCredential = null;
|
|
22
|
+
let visibleGitIdentity = null;
|
|
19
23
|
function defaultConfigPath() {
|
|
20
24
|
return path.join(os.homedir(), ".config", "r5d", "r5dctl", "config.json");
|
|
21
25
|
}
|
|
@@ -578,15 +582,19 @@ function ensureVisibleGitCheckout(input) {
|
|
|
578
582
|
}
|
|
579
583
|
ensureOriginRemote(branchPath, input.githubRemoteUrl);
|
|
580
584
|
configureVisibleGitHubAuth(branchPath, input.githubRemoteUrl, input.githubAuthHeader);
|
|
585
|
+
configureVisibleGitIdentity(branchPath, visibleGitIdentity, runGit);
|
|
581
586
|
tryGit(["fetch", "origin", "--prune"], { cwd: branchPath, auth: input.githubAuth });
|
|
582
587
|
checkoutVisibleBranch({ branchPath, branchName: input.branchName, defaultBranch: input.defaultBranch });
|
|
583
588
|
return branchPath;
|
|
584
589
|
}
|
|
585
590
|
function configureInternalRepo(context, remoteUrl) {
|
|
586
|
-
if (tryInternalGit(context, ["remote", "get-url",
|
|
587
|
-
runInternalGit(context, ["remote", "set-url",
|
|
591
|
+
if (tryInternalGit(context, ["remote", "get-url", R5D_REMOTE_NAME])) {
|
|
592
|
+
runInternalGit(context, ["remote", "set-url", R5D_REMOTE_NAME, remoteUrl]);
|
|
588
593
|
} else {
|
|
589
|
-
runInternalGit(context, ["remote", "add",
|
|
594
|
+
runInternalGit(context, ["remote", "add", R5D_REMOTE_NAME, remoteUrl]);
|
|
595
|
+
}
|
|
596
|
+
if (tryInternalGit(context, ["remote", "get-url", LEGACY_BUILD_IT_NOW_REMOTE_NAME])) {
|
|
597
|
+
runInternalGit(context, ["remote", "remove", LEGACY_BUILD_IT_NOW_REMOTE_NAME]);
|
|
590
598
|
}
|
|
591
599
|
runInternalGitDir(context, ["config", "user.name", "r5d.dev Worker"]);
|
|
592
600
|
runInternalGitDir(context, ["config", "user.email", "worker@r5d.dev"]);
|
|
@@ -602,9 +610,9 @@ function ensureInternalSyncGit(input) {
|
|
|
602
610
|
const context = { gitDir, workTree: input.branchPath, auth };
|
|
603
611
|
const remoteUrl = internalRemoteUrlFor(input.baseUrl, input.projectId, input.manifest);
|
|
604
612
|
configureInternalRepo(context, remoteUrl);
|
|
605
|
-
runInternalGit(context, ["fetch",
|
|
606
|
-
const hasRemoteBranch = tryInternalGit(context, ["show-ref", "--verify", "--quiet", `refs/remotes
|
|
607
|
-
const target = hasRemoteBranch ? `refs/remotes
|
|
613
|
+
runInternalGit(context, ["fetch", R5D_REMOTE_NAME, "--prune", `+refs/heads/*:refs/remotes/${R5D_REMOTE_NAME}/*`]);
|
|
614
|
+
const hasRemoteBranch = tryInternalGit(context, ["show-ref", "--verify", "--quiet", `refs/remotes/${R5D_REMOTE_NAME}/${input.branchName}`]);
|
|
615
|
+
const target = hasRemoteBranch ? `refs/remotes/${R5D_REMOTE_NAME}/${input.branchName}` : `refs/remotes/${R5D_REMOTE_NAME}/main`;
|
|
608
616
|
const hasHead = tryInternalGit(context, ["rev-parse", "--verify", "HEAD"]);
|
|
609
617
|
if (!hasHead || !hasInternalWorktreeChanges(context)) {
|
|
610
618
|
runInternalGit(context, ["checkout", "-f", "-B", input.branchName, target]);
|
|
@@ -873,7 +881,7 @@ function syncBranch(input) {
|
|
|
873
881
|
});
|
|
874
882
|
runInternalGit(workspace.internalGit, ["commit", "-m", message]);
|
|
875
883
|
const commitHash = getInternalCommitHash(workspace.internalGit);
|
|
876
|
-
runInternalGit(workspace.internalGit, ["push",
|
|
884
|
+
runInternalGit(workspace.internalGit, ["push", R5D_REMOTE_NAME, `HEAD:refs/heads/${input.branchName}`]);
|
|
877
885
|
return {
|
|
878
886
|
type: "sync",
|
|
879
887
|
changed: true,
|
|
@@ -904,8 +912,8 @@ function confirmLargeDiff(input) {
|
|
|
904
912
|
}
|
|
905
913
|
function pullBranch(input) {
|
|
906
914
|
const workspace = ensureOperationBranch(input);
|
|
907
|
-
runInternalGit(workspace.internalGit, ["fetch",
|
|
908
|
-
const target = input.commitHash ??
|
|
915
|
+
runInternalGit(workspace.internalGit, ["fetch", R5D_REMOTE_NAME, "--prune", `+refs/heads/*:refs/remotes/${R5D_REMOTE_NAME}/*`]);
|
|
916
|
+
const target = input.commitHash ?? `${R5D_REMOTE_NAME}/${input.branchName}`;
|
|
909
917
|
runInternalGit(workspace.internalGit, ["reset", "--hard", target]);
|
|
910
918
|
runInternalGit(workspace.internalGit, ["clean", "-fd", "--", ".", ":(exclude).git"]);
|
|
911
919
|
return {
|
|
@@ -1231,8 +1239,8 @@ function openPty(input) {
|
|
|
1231
1239
|
...process.env,
|
|
1232
1240
|
...containerRegistryEnv(),
|
|
1233
1241
|
...input.message.env ?? {},
|
|
1234
|
-
|
|
1235
|
-
|
|
1242
|
+
R5D_PROJECT_ID: input.projectId,
|
|
1243
|
+
R5D_BRANCH_NAME: input.message.branchName
|
|
1236
1244
|
}
|
|
1237
1245
|
},
|
|
1238
1246
|
onOpened: () => {
|
|
@@ -1371,6 +1379,7 @@ async function startWorker(options) {
|
|
|
1371
1379
|
}
|
|
1372
1380
|
if (message.type === "project_manifest") {
|
|
1373
1381
|
configureContainerRegistryAuth(message.githubContainerRegistry);
|
|
1382
|
+
visibleGitIdentity = message.gitIdentity;
|
|
1374
1383
|
manifestByProjectId.clear();
|
|
1375
1384
|
for (const project of message.projects) {
|
|
1376
1385
|
manifestByProjectId.set(project.projectId, project);
|
package/dist/mjs/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type WorkerGitIdentity = {
|
|
2
|
+
name: string;
|
|
3
|
+
email: string;
|
|
4
|
+
};
|
|
5
|
+
type RunGit = (args: string[], options?: {
|
|
6
|
+
cwd?: string;
|
|
7
|
+
}) => string | void;
|
|
8
|
+
export declare function configureVisibleGitIdentity(branchPath: string, identity: WorkerGitIdentity | null | undefined, runGit: RunGit): void;
|
|
9
|
+
export {};
|