-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathmain.rs
More file actions
779 lines (709 loc) · 27.4 KB
/
main.rs
File metadata and controls
779 lines (709 loc) · 27.4 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
#![allow(clippy::disallowed_macros)]
use anyhow::{bail, Result};
use clap::{CommandFactory, Parser, Subcommand};
use duct::cmd;
use serde_json::Value;
use std::ffi::OsStr;
use std::ffi::OsString;
use std::path::Path;
use std::path::PathBuf;
use std::{env, fs};
const README_PATH: &str = "tools/ci/README.md";
mod ci_docs;
mod keynote_bench;
mod smoketest;
mod util;
use util::ensure_repo_root;
/// SpacetimeDB CI tasks
///
/// This tool provides several subcommands for automating CI workflows in SpacetimeDB.
///
/// It may be invoked via `cargo ci <subcommand>`, or simply `cargo ci` to run all subcommands in
/// sequence. It is mostly designed to be run in CI environments via the github workflows, but can
/// also be run locally
#[derive(Parser)]
#[command(name = "cargo ci", subcommand_required = false, arg_required_else_help = false)]
struct Cli {
#[command(subcommand)]
cmd: Option<CiCmd>,
/// Skip specified subcommands when running all
///
/// When no subcommand is specified, all subcommands are run in sequence. This option allows
/// specifying subcommands to skip when running all. For example, to skip the `unreal-tests`
/// subcommand, use `--skip unreal-tests`.
#[arg(long)]
skip: Vec<String>,
}
fn check_global_json_policy() -> Result<()> {
ensure_repo_root()?;
let root_json = Path::new("global.json");
let root_contents = fs::read_to_string(root_json)?;
fn find_all_global_json(dir: &Path) -> Result<Vec<PathBuf>> {
let mut out = Vec::new();
for entry in fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
let ft = entry.file_type()?;
if ft.is_dir() {
out.extend(find_all_global_json(&path)?);
} else if path.file_name() == Some(OsStr::new("global.json")) {
out.push(path);
}
}
Ok(out)
}
let globals = find_all_global_json(Path::new("."))?;
let mut ok = true;
for p in globals {
let meta = fs::symlink_metadata(&p)?;
let is_symlink = meta.file_type().is_symlink();
let is_template_global_json = p.strip_prefix(".").unwrap_or(&p).starts_with(Path::new("templates"));
if is_template_global_json && is_symlink {
eprintln!(
"Error: {} is a symlink. Template files must not be symlinks; they are copied literally and this will break if the CLI is built under Windows where symlinks are not supported.",
p.display()
);
ok = false;
}
let contents = fs::read_to_string(&p)?;
if contents != root_contents {
eprintln!("Error: {} does not match the root global.json contents", p.display());
ok = false;
} else if !is_template_global_json || !is_symlink {
println!("OK: {}", p.display());
}
}
if !ok {
bail!("global.json policy check failed");
}
Ok(())
}
fn package_json_pnpm_version(package_manager: &str) -> Option<&str> {
package_manager.strip_prefix("pnpm@")
}
fn git_tracked_files(pathspec: &str) -> Result<Vec<PathBuf>> {
let output = cmd!("git", "ls-files", pathspec).read()?;
Ok(output.lines().map(PathBuf::from).collect())
}
fn package_json_string_value(package_json: &Value, key: &str) -> Option<String> {
package_json.get(key)?.as_str().map(str::to_owned)
}
fn package_json_engines_pnpm(package_json: &Value) -> Option<String> {
package_json.get("engines")?.get("pnpm")?.as_str().map(str::to_owned)
}
fn read_package_json(path: &Path) -> Result<Value> {
let contents = fs::read_to_string(path)?;
Ok(serde_json::from_str(&contents)?)
}
fn is_npm_package_json(package_json: &Value) -> bool {
[
"bin",
"dependencies",
"devDependencies",
"exports",
"main",
"optionalDependencies",
"packageManager",
"peerDependencies",
"scripts",
"type",
]
.iter()
.any(|key| package_json.get(key).is_some())
}
fn is_template_path(path: &Path) -> bool {
path.starts_with("templates")
}
fn minimum_release_age(path: &Path) -> Result<u64> {
let workspace = fs::read_to_string(path)?;
workspace
.lines()
.find_map(|line| {
let line = line.trim();
let value = line.strip_prefix("minimumReleaseAge:")?.trim();
value.parse::<u64>().ok()
})
.ok_or_else(|| anyhow::anyhow!("{} is missing minimumReleaseAge", path.display()))
}
fn npmrc_minimum_release_age(path: &Path, expected_minimum_release_age: u64) -> Result<u64> {
let contents = fs::read_to_string(path).map_err(|err| {
if err.kind() == std::io::ErrorKind::NotFound {
anyhow::anyhow!(
"{} is tracked but missing from the working tree. Restore it with:\nminimum-release-age={}",
path.display(),
expected_minimum_release_age
)
} else {
anyhow::anyhow!(
"failed to read {} while checking pnpm minimum package age: {err}",
path.display()
)
}
})?;
contents
.lines()
.find_map(|line| {
let line = line.trim();
let value = line.strip_prefix("minimum-release-age=")?.trim();
value.parse::<u64>().ok()
})
.ok_or_else(|| {
anyhow::anyhow!(
"{} must contain `minimum-release-age={}` to match root pnpm-workspace.yaml",
path.display(),
expected_minimum_release_age
)
})
}
fn check_pnpm_release_age_policy() -> Result<()> {
ensure_repo_root()?;
let root_package_json_path = Path::new("package.json");
let root_package_json = read_package_json(root_package_json_path)?;
let package_manager = package_json_string_value(&root_package_json, "packageManager")
.ok_or_else(|| anyhow::anyhow!("package.json is missing packageManager"))?;
let package_manager_version = package_json_pnpm_version(&package_manager)
.ok_or_else(|| anyhow::anyhow!("packageManager must be pnpm@<version>, found {package_manager:?}"))?;
let expected_engine_pnpm = format!(">={package_manager_version}");
let engine_pnpm = package_json_engines_pnpm(&root_package_json)
.ok_or_else(|| anyhow::anyhow!("package.json engines is missing pnpm"))?;
if engine_pnpm != expected_engine_pnpm {
bail!("package.json engines.pnpm must be {expected_engine_pnpm:?}, found {engine_pnpm:?}");
}
for package_json_path in git_tracked_files(":(glob)**/package.json")? {
let package_json = read_package_json(&package_json_path)?;
let Some(found_package_manager) = package_json_string_value(&package_json, "packageManager") else {
continue;
};
if found_package_manager != package_manager {
bail!(
"{} packageManager must match root package.json: expected {:?}, found {:?}",
package_json_path.display(),
package_manager,
found_package_manager
);
}
}
let root_workspace_path = Path::new("pnpm-workspace.yaml");
let root_minimum_release_age = minimum_release_age(root_workspace_path)?;
for workspace_path in git_tracked_files(":(glob)**/pnpm-workspace.yaml")? {
let found_minimum_release_age = minimum_release_age(&workspace_path)?;
if found_minimum_release_age != root_minimum_release_age {
bail!(
"{} minimumReleaseAge must match root pnpm-workspace.yaml: expected {}, found {}",
workspace_path.display(),
root_minimum_release_age,
found_minimum_release_age
);
}
}
for npmrc_path in git_tracked_files(":(glob)**/.npmrc")? {
// Template package roots are copied into projects created by `spacetime init`.
// They must not embed this repo's package-age policy; smoketests enforce it
// at the pnpm process boundary instead.
if is_template_path(&npmrc_path) {
continue;
}
let found_minimum_release_age = npmrc_minimum_release_age(&npmrc_path, root_minimum_release_age)?;
if found_minimum_release_age != root_minimum_release_age {
bail!(
"{} minimum-release-age must match root pnpm-workspace.yaml: expected {}, found {}",
npmrc_path.display(),
root_minimum_release_age,
found_minimum_release_age
);
}
}
for package_json_path in git_tracked_files(":(glob)**/package.json")? {
// Template package roots are copied into projects created by `spacetime init`.
// They must not require adjacent .npmrc files for this repo's package-age
// policy; smoketests enforce it at the pnpm process boundary instead.
if is_template_path(&package_json_path) {
continue;
}
let package_json = read_package_json(&package_json_path)?;
if !is_npm_package_json(&package_json) {
continue;
}
let package_dir = package_json_path
.parent()
.expect("git-tracked package.json path should have a parent");
let npmrc_path = package_dir.join(".npmrc");
if !npmrc_path.is_file() {
bail!(
"{} is required because {} is an npm/pnpm package manifest.\nAdd {} containing:\nminimum-release-age={}",
npmrc_path.display(),
package_json_path.display(),
npmrc_path.display(),
root_minimum_release_age
);
}
let found_minimum_release_age = npmrc_minimum_release_age(&npmrc_path, root_minimum_release_age)?;
if found_minimum_release_age != root_minimum_release_age {
bail!(
"{} minimum-release-age must match root pnpm-workspace.yaml: expected {}, found {}",
npmrc_path.display(),
root_minimum_release_age,
found_minimum_release_age
);
}
}
for workflow_path in git_tracked_files(".github/workflows/*")? {
let contents = fs::read_to_string(&workflow_path)?;
if contents.contains("pnpm/action-setup@v4") {
bail!(
"{} must use ./.github/actions/setup-pnpm instead of pnpm/action-setup@v4",
workflow_path.display()
);
}
}
Ok(())
}
#[derive(Subcommand)]
enum CiCmd {
/// Runs tests
///
/// Runs rust tests, codegens csharp sdk and runs csharp tests.
/// This does not include Unreal tests.
/// This expects to run in a clean git state.
Test,
/// Lints the codebase
///
/// Runs rustfmt, clippy, csharpier, TypeScript lint, and generates rust docs to ensure there
/// are no warnings.
Lint,
/// Tests Wasm bindings
///
/// Runs tests for the codegen crate and builds a test module with the wasm bindings.
WasmBindings,
/// Deprecated; use `cargo regen csharp dlls`.
///
/// Builds and packs C# DLLs and NuGet packages for local Unity workflows.
Dlls,
/// Runs smoketests
///
/// Executes the smoketests suite with some default exclusions.
Smoketests(smoketest::SmoketestsArgs),
/// Runs the keynote benchmark as a CI performance regression gate.
///
/// Assumes release SpacetimeDB binaries and the TypeScript SDK are already built, runs the
/// keynote SpacetimeDB benchmark for 60 seconds against the TypeScript and Rust modules, and
/// fails if throughput is below 275K TPS for TypeScript or 300K TPS for Rust.
KeynoteBench,
/// Tests the update flow
///
/// Tests the self-update flow by building the spacetimedb-update binary for the specified
/// target, by default the current target, and performing a self-install into a temporary
/// directory.
UpdateFlow {
#[arg(
long,
long_help = "Target triple to build for, by default the current target. Used by github workflows to check the update flow on multiple platforms."
)]
target: Option<String>,
#[arg(
long,
default_value = "false",
long_help = "Whether to enable github token authentication feature when building the update binary. By default this is disabled."
)]
github_token_auth: bool,
},
/// Generates CLI documentation and checks for changes
CliDocs {
#[arg(
long,
long_help = "specify a custom path to the SpacetimeDB repository root (where the main Cargo.toml is located)"
)]
spacetime_path: Option<String>,
},
SelfDocs {
#[arg(
long,
default_value_t = false,
long_help = "Only check for changes, do not generate the docs"
)]
check: bool,
},
/// Verify that any non-root global.json files are symlinks to the root global.json.
GlobalJsonPolicy,
/// Checks that publishable crates satisfy publish constraints.
PublishChecks,
/// Runs TypeScript workspace tests and template build checks.
TypescriptTest,
/// Verifies that the repository version upgrade tool still works.
VersionUpgradeCheck,
/// Builds the docs site.
Docs,
}
fn run_all_clap_subcommands(skips: &[String]) -> Result<()> {
let subcmds = Cli::command()
.get_subcommands()
.map(|sc| sc.get_name().to_string())
.collect::<Vec<_>>();
for subcmd in subcmds {
if skips.contains(&subcmd) {
log::info!("skipping {subcmd} as requested");
continue;
}
log::info!("executing cargo ci {subcmd}");
cmd!("cargo", "ci", &subcmd).run()?;
}
Ok(())
}
fn tracked_rs_files_under(path: &str) -> Result<Vec<PathBuf>> {
let output = cmd!("git", "ls-files", "--", path).read()?;
Ok(output
.lines()
.filter(|line| line.ends_with(".rs"))
.map(PathBuf::from)
.collect())
}
fn run_publish_checks() -> Result<()> {
cmd!("bash", "-lc", "test -d venv || python3 -m venv venv").run()?;
cmd!("venv/bin/pip3", "install", "argparse", "toml").run()?;
let crates = cmd!(
"venv/bin/python3",
"tools/find-publish-list.py",
"--recursive",
"--directories",
"--quiet",
"spacetimedb",
"spacetimedb-sdk"
)
.read()?;
let mut failed = Vec::new();
for crate_dir in crates.split_whitespace() {
if let Err(err) = cmd!("venv/bin/python3", "tools/crate-publish-checks.py", crate_dir).run() {
eprintln!("crate publish checks failed for {crate_dir}: {err}");
failed.push(crate_dir.to_string());
}
}
if !failed.is_empty() {
bail!("crate publish checks failed for: {}", failed.join(", "));
}
Ok(())
}
fn run_typescript_tests() -> Result<()> {
cmd!("pnpm", "build").dir("crates/bindings-typescript").run()?;
cmd!("pnpm", "test").dir("crates/bindings-typescript").run()?;
cmd!("pnpm", "generate").dir("templates/chat-react-ts").run()?;
let diff_status = cmd!(
"bash",
"tools/check-diff.sh",
"templates/chat-react-ts/src/module_bindings"
)
.run()?;
if !diff_status.status.success() {
bail!("Bindings are dirty. Please generate bindings again and commit them to this branch.");
}
cmd!("pnpm", "build").dir("templates/chat-react-ts").run()?;
cmd!("pnpm", "-r", "--filter", "./**", "run", "build")
.dir("templates")
.run()?;
cmd!("pnpm", "-r", "--filter", "./**", "run", "build")
.dir("crates/bindings-typescript")
.run()?;
Ok(())
}
fn run_docs_build() -> Result<()> {
cmd!("pnpm", "install").dir("docs").run()?;
cmd!("pnpm", "build").dir("docs").run()?;
Ok(())
}
fn run_version_upgrade_check() -> Result<()> {
cmd!(
"cargo",
"bump-versions",
"123.456.789",
"--rust-and-cli",
"--csharp",
"--typescript",
"--cpp",
"--accept-snapshots"
)
.run()?;
Ok(())
}
fn main() -> Result<()> {
env_logger::init();
let cli = Cli::parse();
match cli.cmd {
Some(CiCmd::Test) => {
cmd!("pnpm", "build").dir("crates/bindings-typescript").run()?;
// TODO: This doesn't work on at least user Linux machines, because something here apparently uses `sudo`?
// Exclude smoketests from `cargo test --all` since they require pre-built binaries.
// Smoketests have their own dedicated command: `cargo ci smoketests`
cmd!(
"cargo",
"test",
"--all",
"--exclude",
"spacetimedb-smoketests",
"--exclude",
"spacetimedb-sdk",
"--exclude",
"spacetimedb",
"--",
"--test-threads=2",
"--skip",
"unreal"
)
.run()?;
// Bindings snapshot tests rely on the unstable feature,
// as they compile and test APIs which are gated behind that feature,
// e.g. procedures, HTTP handlers.
cmd!(
"cargo",
"test",
"-p",
"spacetimedb",
"--features",
"unstable",
"--",
"--test-threads=2",
)
.run()?;
// SDK procedure tests intentionally make localhost HTTP requests.
cmd!(
"cargo",
"test",
"-p",
"spacetimedb-sdk",
"--features",
"allow_loopback_http_for_tests",
"--",
"--test-threads=2",
"--skip",
"unreal"
)
.run()?;
// Run the same SDK suite against wasm/browser test clients.
cmd!(
"cargo",
"test",
"-p",
"spacetimedb-sdk",
"--features",
"allow_loopback_http_for_tests,browser",
"--",
"--test-threads=2",
"--skip",
"unreal"
)
.run()?;
// TODO: This should check for a diff at the start. If there is one, we should alert the user
// that we're disabling diff checks because they have a dirty git repo, and to re-run in a clean one
// if they want those checks.
// The fallocate tests have been flakely when running in parallel
cmd!(
"cargo",
"test",
"-p",
"spacetimedb-durability",
"--features",
"fallocate",
"--",
"--test-threads=1",
)
.run()?;
cmd!("bash", "tools/check-diff.sh").run()?;
cmd!(
"cargo",
"run",
"-p",
"spacetimedb-codegen",
"--example",
"regen-csharp-moduledef",
)
.run()?;
cmd!("bash", "tools/check-diff.sh", "crates/bindings-csharp").run()?;
cmd!("dotnet", "test", "-warnaserror")
.dir("crates/bindings-csharp")
.run()?;
}
Some(CiCmd::Lint) => {
ensure_repo_root()?;
check_pnpm_release_age_policy()?;
// `cargo fmt --all` only checks files that Cargo discovers through workspace/package targets.
// However, we also keep Rust sources in a locations that are tracked but not part of our workspace,
// so this approach properly catches all the files, where `cargo fmt` does not.
let mut files = Vec::new();
files.extend(tracked_rs_files_under(".")?);
const RUSTFMT_BATCH_SIZE: usize = 200;
for batch in files.chunks(RUSTFMT_BATCH_SIZE) {
let mut args = Vec::<OsString>::with_capacity(batch.len() + 1);
args.push("--check".into());
args.extend(batch.iter().map(|path| path.as_os_str().to_os_string()));
cmd("rustfmt", args).run()?;
}
cmd!(
"cargo",
"clippy",
"--all",
"--tests",
"--benches",
"--",
"-D",
"warnings",
)
.run()?;
cmd!(
"cargo",
"clippy",
"--no-default-features",
"--features=browser",
"-pspacetimedb-sdk",
"--tests",
"--benches",
"--",
"-D",
"warnings",
)
.run()?;
cmd!("dotnet", "tool", "restore").dir("crates/bindings-csharp").run()?;
cmd!("dotnet", "csharpier", "--check", ".")
.dir("crates/bindings-csharp")
.run()?;
cmd!("pnpm", "lint").run()?;
cmd!("cargo", "test", "--doc", "--target", "wasm32-unknown-unknown")
.dir("crates/bindings")
.run()?;
cmd!("cargo", "test", "--doc").dir("crates/bindings").run()?;
// `bindings` is the only crate we care strongly about documenting,
// since we link to its docs.rs from our website.
// We won't pass `--no-deps`, though,
// since we want everything reachable through it to also work.
// This includes `sats` and `lib`.
cmd!("cargo", "doc")
.dir("crates/bindings")
// Make `cargo doc` exit with error on warnings, most notably broken links
.env("RUSTDOCFLAGS", "--deny warnings")
.run()?;
}
Some(CiCmd::WasmBindings) => {
cmd!("cargo", "test", "-p", "spacetimedb-codegen").run()?;
// Pre-build the CLI so that it _doesn't_ get `cargo update`d, since that may break the build.
cmd!("cargo", "build", "-p", "spacetimedb-cli").run()?;
// Make sure the `Cargo.lock` file reflects the latest available versions.
// This is what users would end up with on a fresh module, so we want to
// catch any compile errors arising from a different transitive closure
// of dependencies than what is in the workspace lock file.
//
// For context see also: https://github.com/clockworklabs/SpacetimeDB/pull/2714
cmd!("cargo", "update").run()?;
let cli_path = Path::new(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(2)
.unwrap()
.join("target/debug/spacetimedb-cli")
.with_extension(std::env::consts::EXE_EXTENSION);
cmd!(cli_path, "build", "--module-path", "modules/module-test",).run()?;
}
Some(CiCmd::Dlls) => {
eprintln!("warning: `cargo ci dlls` is deprecated; use `cargo regen csharp dlls` instead");
cmd!("cargo", "regen", "csharp", "dlls").run()?;
}
Some(CiCmd::Smoketests(args)) => {
ensure_repo_root()?;
smoketest::run(args)?;
}
Some(CiCmd::KeynoteBench) => {
ensure_repo_root()?;
keynote_bench::run()?;
}
Some(CiCmd::UpdateFlow {
target,
github_token_auth,
}) => {
let mut common_args = vec![];
if let Some(target) = target.as_ref() {
common_args.push("--target");
common_args.push(target);
log::info!("checking update flow for target: {target}");
} else {
log::info!("checking update flow");
}
if github_token_auth {
common_args.push("--features");
common_args.push("github-token-auth");
}
cmd(
"cargo",
["build", "-p", "spacetimedb-update"]
.into_iter()
.chain(common_args.clone()),
)
.run()?;
// NOTE(bfops): We need the `github-token-auth` feature because we otherwise tend to get ratelimited when we try to fetch `/releases/latest`.
// My best guess is that, on the GitHub runners, the "anonymous" ratelimit is shared by *all* users of that runner (I think this because it
// happens very frequently on the `macos-runner`, but we haven't seen it on any others).
let root_dir = tempfile::tempdir()?;
let root_dir_string = root_dir.path().to_string_lossy().to_string();
let root_arg = format!("--root-dir={}", root_dir_string);
cmd(
"cargo",
["run", "-p", "spacetimedb-update"]
.into_iter()
.chain(common_args.clone())
.chain(["--", "self-install", &root_arg, "--yes"].into_iter()),
)
.run()?;
let mut spacetime_path = root_dir.path().join("spacetime");
if !std::env::consts::EXE_EXTENSION.is_empty() {
spacetime_path.set_extension(std::env::consts::EXE_EXTENSION);
}
cmd(spacetime_path, [&root_arg, "help"]).run()?;
}
Some(CiCmd::CliDocs { spacetime_path }) => {
if let Some(path) = spacetime_path {
env::set_current_dir(path).ok();
}
let current_dir = env::current_dir().expect("No current directory!");
let dir_name = current_dir.file_name().expect("No current directory!");
if dir_name != "SpacetimeDB" && dir_name != "public" {
anyhow::bail!(
"You must execute this binary from inside of the SpacetimeDB directory, or use --spacetime-path"
);
}
cmd!("pnpm", "install", "--recursive").run()?;
cmd!("pnpm", "generate-cli-docs").dir("docs").run()?;
let out = cmd!("git", "status", "--porcelain", "--", "docs").read()?;
if out.is_empty() {
log::info!("No docs changes detected");
} else {
anyhow::bail!("CLI docs are out of date:\n{out}");
}
}
Some(CiCmd::SelfDocs { check }) => {
let readme_content = ci_docs::generate_cli_docs();
let path = Path::new(README_PATH);
if check {
let existing = fs::read_to_string(path).unwrap_or_default();
if existing != readme_content {
bail!("README.md is out of date. Please run `cargo ci self-docs` to update it.");
} else {
log::info!("README.md is up to date.");
}
} else {
fs::write(path, readme_content)?;
log::info!("Wrote CLI docs to {}", path.display());
}
}
Some(CiCmd::GlobalJsonPolicy) => {
check_global_json_policy()?;
}
Some(CiCmd::PublishChecks) => {
run_publish_checks()?;
}
Some(CiCmd::TypescriptTest) => {
run_typescript_tests()?;
}
Some(CiCmd::VersionUpgradeCheck) => {
run_version_upgrade_check()?;
}
Some(CiCmd::Docs) => {
run_docs_build()?;
}
None => run_all_clap_subcommands(&cli.skip)?,
}
Ok(())
}