-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsync.ts
More file actions
180 lines (156 loc) · 5.38 KB
/
sync.ts
File metadata and controls
180 lines (156 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* Repository sync tool - clones and updates Aztec repositories
*/
import { AZTEC_REPOS, getAztecRepos, DEFAULT_AZTEC_VERSION, RepoConfig } from "../repos/config.js";
import { cloneRepo, getReposStatus, getNoirCommitFromAztec, REPOS_DIR, Logger } from "../utils/git.js";
export interface SyncResult {
success: boolean;
message: string;
version: string;
repos: {
name: string;
status: string;
commit?: string;
}[];
}
/**
* Sync all repositories (clone if missing, update if exists)
* Syncs aztec-packages first to determine the correct Noir version
*/
export async function syncRepos(options: {
force?: boolean;
repos?: string[];
version?: string;
log?: Logger;
}): Promise<SyncResult> {
const { force = false, repos: repoNames, version, log } = options;
// Get repos configured for the specified version
const configuredRepos = version ? getAztecRepos(version) : AZTEC_REPOS;
const effectiveVersion = version || DEFAULT_AZTEC_VERSION;
// Filter repos if specific ones requested
let reposToSync = repoNames
? configuredRepos.filter((r) => repoNames.includes(r.name))
: configuredRepos;
if (reposToSync.length === 0) {
return {
success: false,
message: "No repositories matched the specified names",
version: effectiveVersion,
repos: [],
};
}
// Generate synthetic repo configs from sparsePathOverrides
const syntheticRepos: RepoConfig[] = [];
for (const repo of reposToSync) {
if (repo.sparsePathOverrides) {
for (const override of repo.sparsePathOverrides) {
syntheticRepos.push({
name: `${repo.name}-docs`,
url: repo.url,
branch: override.branch,
sparse: override.paths,
description: `${repo.description} (docs from ${override.branch})`,
});
}
}
}
// Include synthetic repos in total count
const totalRepos = reposToSync.length + syntheticRepos.length;
log?.(`Starting sync: ${totalRepos} repos, version=${effectiveVersion}, force=${force}`, "info");
const results: SyncResult["repos"] = [];
async function syncRepo(
config: RepoConfig,
index: number,
total: number,
statusTransform?: (s: string) => string,
): Promise<void> {
log?.(`Syncing ${index}/${total}: ${config.name}`, "info");
try {
const status = log ? await cloneRepo(config, force, log) : await cloneRepo(config, force);
results.push({ name: config.name, status: statusTransform ? statusTransform(status) : status });
} catch (error) {
log?.(`${config.name}: Failed: ${error instanceof Error ? error.message : String(error)}`, "error");
results.push({
name: config.name,
status: `Error: ${error instanceof Error ? error.message : String(error)}`,
});
}
}
// Clone aztec-packages first (blocking - needed to determine Noir version)
const aztecPackages = reposToSync.find((r) => r.name === "aztec-packages");
let nextIndex = 1;
if (aztecPackages) {
await syncRepo(aztecPackages, nextIndex++, totalRepos);
}
// Get the Noir commit from aztec-packages (if available)
const noirCommit = await getNoirCommitFromAztec();
if (noirCommit) {
log?.(`Resolved Noir commit from aztec-packages: ${noirCommit.substring(0, 7)}`, "info");
}
// Build list of all remaining repos to clone in parallel
const parallelBatch: { config: RepoConfig; index: number; statusTransform?: (s: string) => string }[] = [];
const noirRepos = reposToSync.filter((r) => r.url.includes("noir-lang"));
const otherRepos = reposToSync.filter(
(r) => r.name !== "aztec-packages" && !r.url.includes("noir-lang")
);
for (const config of noirRepos) {
const useAztecCommit = config.name === "noir" && noirCommit;
const noirConfig: RepoConfig = useAztecCommit
? { ...config, commit: noirCommit, branch: undefined }
: config;
parallelBatch.push({
config: noirConfig,
index: nextIndex++,
statusTransform: useAztecCommit ? (s) => s.replace("(commit", "(commit from aztec-packages") : undefined,
});
}
for (const config of otherRepos) {
parallelBatch.push({ config, index: nextIndex++ });
}
for (const config of syntheticRepos) {
parallelBatch.push({ config, index: nextIndex++ });
}
// Clone all remaining repos in parallel
await Promise.all(
parallelBatch.map((item) => syncRepo(item.config, item.index, totalRepos, item.statusTransform))
);
const allSuccess = results.every(
(r) => !r.status.toLowerCase().includes("error")
);
log?.(`Sync complete: ${results.length} repos, ${allSuccess ? "all succeeded" : "some failed"}`, "info");
return {
success: allSuccess,
message: allSuccess
? `Successfully synced ${results.length} repositories to ${REPOS_DIR}`
: "Some repositories failed to sync",
version: effectiveVersion,
repos: results,
};
}
/**
* Get status of all configured repositories
*/
export async function getStatus(): Promise<{
reposDir: string;
repos: {
name: string;
description: string;
cloned: boolean;
commit?: string;
}[];
}> {
const statusMap = await getReposStatus(AZTEC_REPOS);
const repos = AZTEC_REPOS.map((config) => {
const status = statusMap.get(config.name);
return {
name: config.name,
description: config.description,
cloned: status?.cloned || false,
commit: status?.commit,
};
});
return {
reposDir: REPOS_DIR,
repos,
};
}