Skip to content

Commit bf1d20e

Browse files
committed
refactor
1 parent d639be0 commit bf1d20e

1 file changed

Lines changed: 90 additions & 85 deletions

File tree

tools/ci/src/main.rs

Lines changed: 90 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,91 @@ fn tracked_rs_files_under(path: &str) -> Result<Vec<PathBuf>> {
299299
.collect())
300300
}
301301

302+
fn run_dlls() -> Result<()> {
303+
ensure_repo_root()?;
304+
305+
cmd!(
306+
"dotnet",
307+
"pack",
308+
"crates/bindings-csharp/BSATN.Runtime",
309+
"-c",
310+
"Release"
311+
)
312+
.run()?;
313+
cmd!("dotnet", "pack", "crates/bindings-csharp/Runtime", "-c", "Release").run()?;
314+
315+
let repo_root = env::current_dir()?;
316+
let bsatn_source = repo_root.join("crates/bindings-csharp/BSATN.Runtime/bin/Release");
317+
let runtime_source = repo_root.join("crates/bindings-csharp/Runtime/bin/Release");
318+
319+
let nuget_config_dir = tempfile::tempdir()?;
320+
let nuget_config_path = nuget_config_dir.path().join("nuget.config");
321+
let nuget_config_contents = format!(
322+
r#"<?xml version="1.0" encoding="utf-8"?>
323+
<configuration>
324+
<packageSources>
325+
<clear />
326+
<add key="Local SpacetimeDB.BSATN.Runtime" value="{}" />
327+
<add key="Local SpacetimeDB.Runtime" value="{}" />
328+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
329+
</packageSources>
330+
<packageSourceMapping>
331+
<packageSource key="Local SpacetimeDB.BSATN.Runtime">
332+
<package pattern="SpacetimeDB.BSATN.Runtime" />
333+
</packageSource>
334+
<packageSource key="Local SpacetimeDB.Runtime">
335+
<package pattern="SpacetimeDB.Runtime" />
336+
</packageSource>
337+
<packageSource key="nuget.org">
338+
<package pattern="*" />
339+
</packageSource>
340+
</packageSourceMapping>
341+
</configuration>
342+
"#,
343+
bsatn_source.display(),
344+
runtime_source.display(),
345+
);
346+
fs::write(&nuget_config_path, nuget_config_contents)?;
347+
348+
let nuget_config_path_str = nuget_config_path.to_string_lossy().to_string();
349+
350+
clear_restored_package_dirs("spacetimedb.bsatn.runtime")?;
351+
clear_restored_package_dirs("spacetimedb.runtime")?;
352+
353+
cmd!(
354+
"dotnet",
355+
"restore",
356+
"SpacetimeDB.ClientSDK.csproj",
357+
"--configfile",
358+
&nuget_config_path_str,
359+
)
360+
.dir("sdks/csharp")
361+
.run()?;
362+
363+
overlay_unity_meta_skeleton("spacetimedb.bsatn.runtime")?;
364+
overlay_unity_meta_skeleton("spacetimedb.runtime")?;
365+
366+
cmd!(
367+
"dotnet",
368+
"pack",
369+
"SpacetimeDB.ClientSDK.csproj",
370+
"-c",
371+
"Release",
372+
"--no-restore"
373+
)
374+
.dir("sdks/csharp")
375+
.run()?;
376+
377+
Ok(())
378+
}
379+
302380
fn main() -> Result<()> {
303381
env_logger::init();
304382

305383
let cli = Cli::parse();
306384

307385
match cli.cmd {
308386
Some(CiCmd::Test) => {
309-
cmd!("pnpm", "build").dir("crates/bindings-typescript").run()?;
310-
311387
// TODO: This doesn't work on at least user Linux machines, because something here apparently uses `sudo`?
312388

313389
// Exclude smoketests from `cargo test --all` since they require pre-built binaries.
@@ -461,83 +537,10 @@ fn main() -> Result<()> {
461537
}
462538

463539
Some(CiCmd::Dlls) => {
464-
ensure_repo_root()?;
465-
466-
cmd!(
467-
"dotnet",
468-
"pack",
469-
"crates/bindings-csharp/BSATN.Runtime",
470-
"-c",
471-
"Release"
472-
)
473-
.run()?;
474-
cmd!("dotnet", "pack", "crates/bindings-csharp/Runtime", "-c", "Release").run()?;
475-
476-
let repo_root = env::current_dir()?;
477-
let bsatn_source = repo_root.join("crates/bindings-csharp/BSATN.Runtime/bin/Release");
478-
let runtime_source = repo_root.join("crates/bindings-csharp/Runtime/bin/Release");
479-
480-
let nuget_config_dir = tempfile::tempdir()?;
481-
let nuget_config_path = nuget_config_dir.path().join("nuget.config");
482-
let nuget_config_contents = format!(
483-
r#"<?xml version="1.0" encoding="utf-8"?>
484-
<configuration>
485-
<packageSources>
486-
<clear />
487-
<add key="Local SpacetimeDB.BSATN.Runtime" value="{}" />
488-
<add key="Local SpacetimeDB.Runtime" value="{}" />
489-
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
490-
</packageSources>
491-
<packageSourceMapping>
492-
<packageSource key="Local SpacetimeDB.BSATN.Runtime">
493-
<package pattern="SpacetimeDB.BSATN.Runtime" />
494-
</packageSource>
495-
<packageSource key="Local SpacetimeDB.Runtime">
496-
<package pattern="SpacetimeDB.Runtime" />
497-
</packageSource>
498-
<packageSource key="nuget.org">
499-
<package pattern="*" />
500-
</packageSource>
501-
</packageSourceMapping>
502-
</configuration>
503-
"#,
504-
bsatn_source.display(),
505-
runtime_source.display(),
506-
);
507-
fs::write(&nuget_config_path, nuget_config_contents)?;
508-
509-
let nuget_config_path_str = nuget_config_path.to_string_lossy().to_string();
510-
511-
clear_restored_package_dirs("spacetimedb.bsatn.runtime")?;
512-
clear_restored_package_dirs("spacetimedb.runtime")?;
513-
514-
cmd!(
515-
"dotnet",
516-
"restore",
517-
"SpacetimeDB.ClientSDK.csproj",
518-
"--configfile",
519-
&nuget_config_path_str,
520-
)
521-
.dir("sdks/csharp")
522-
.run()?;
523-
524-
overlay_unity_meta_skeleton("spacetimedb.bsatn.runtime")?;
525-
overlay_unity_meta_skeleton("spacetimedb.runtime")?;
526-
527-
cmd!(
528-
"dotnet",
529-
"pack",
530-
"SpacetimeDB.ClientSDK.csproj",
531-
"-c",
532-
"Release",
533-
"--no-restore"
534-
)
535-
.dir("sdks/csharp")
536-
.run()?;
540+
run_dlls()?;
537541
}
538542

539543
Some(CiCmd::Smoketests(args)) => {
540-
ensure_repo_root()?;
541544
smoketest::run(args)?;
542545
}
543546

@@ -548,7 +551,7 @@ fn main() -> Result<()> {
548551
let mut common_args = vec![];
549552
if let Some(target) = target.as_ref() {
550553
common_args.push("--target");
551-
common_args.push(target);
554+
common_args.push(target.as_str());
552555
log::info!("checking update flow for target: {target}");
553556
} else {
554557
log::info!("checking update flow");
@@ -562,24 +565,26 @@ fn main() -> Result<()> {
562565
"cargo",
563566
["build", "-p", "spacetimedb-update"]
564567
.into_iter()
565-
.chain(common_args.clone()),
568+
.chain(common_args.iter().copied()),
566569
)
567570
.run()?;
568-
// NOTE(bfops): We need the `github-token-auth` feature because we otherwise tend to get ratelimited when we try to fetch `/releases/latest`.
569-
// 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
570-
// happens very frequently on the `macos-runner`, but we haven't seen it on any others).
571+
571572
let root_dir = tempfile::tempdir()?;
572-
let root_dir_string = root_dir.path().to_string_lossy().to_string();
573-
let root_arg = format!("--root-dir={}", root_dir_string);
573+
let root_arg = format!("--root-dir={}", root_dir.path().display());
574574
cmd(
575575
"cargo",
576576
["run", "-p", "spacetimedb-update"]
577577
.into_iter()
578-
.chain(common_args.clone())
578+
.chain(common_args.iter().copied())
579579
.chain(["--", "self-install", &root_arg, "--yes"].into_iter()),
580580
)
581581
.run()?;
582-
cmd!(format!("{}/spacetime", root_dir_string), &root_arg, "help",).run()?;
582+
583+
let mut spacetime_path = root_dir.path().join("spacetime");
584+
if !std::env::consts::EXE_EXTENSION.is_empty() {
585+
spacetime_path.set_extension(std::env::consts::EXE_EXTENSION);
586+
}
587+
cmd(spacetime_path, [&root_arg, "help"]).run()?;
583588
}
584589

585590
Some(CiCmd::CliDocs { spacetime_path }) => {

0 commit comments

Comments
 (0)