Skip to content

Commit 14ba750

Browse files
authored
Add information about the CLI version to generated code. (#2673)
1 parent dc3dd68 commit 14ba750

File tree

442 files changed

+1190
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

442 files changed

+1190
-5
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ jobs:
102102
run: cargo test --all
103103

104104
- name: Check that the test outputs are up-to-date
105-
run: git diff --exit-code
105+
run: bash tools/check-diff.sh
106106

107107
- name: Ensure C# autogen bindings are up-to-date
108108
run: |
109109
cargo run -p spacetimedb-codegen --example regen-csharp-moduledef
110-
git diff --exit-code -- crates/bindings-csharp
110+
bash tools/check-diff.sh crates/bindings-csharp
111111
112112
- name: C# bindings tests
113113
working-directory: crates/bindings-csharp

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ hyper-util = { version = "0.1", features = ["tokio"] }
185185
imara-diff = "0.1.3"
186186
indexmap = "2.0.0"
187187
indicatif = "0.17"
188-
insta = { version = "1.21.0", features = ["toml"] }
188+
insta = { version = "1.21.0", features = ["toml", "filters"] }
189189
is-terminal = "0.4"
190190
itertools = "0.12"
191191
itoa = "1"

crates/bindings-csharp/Runtime/Internal/Autogen/IndexType.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/Lifecycle.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/MiscModuleExport.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawColumnDefV8.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawConstraintDataV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawConstraintDefV8.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawConstraintDefV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawIndexAlgorithm.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawIndexDefV8.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawIndexDefV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawMiscModuleExportV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawModuleDef.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawModuleDefV8.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawModuleDefV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawReducerDefV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawRowLevelSecurityDefV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawScheduleDefV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawScopedTypeNameV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawSequenceDefV8.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawSequenceDefV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawTableDefV8.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawTableDefV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawTypeDefV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/RawUniqueConstraintDataV9.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/ReducerDef.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/TableAccess.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/TableDesc.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/TableType.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/TypeAlias.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-csharp/Runtime/Internal/Autogen/Typespace.g.cs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/src/version.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub const CLI_VERSION: &str = env!("CARGO_PKG_VERSION");
2+
pub const CLI_GIT_HASH: &str = env!("GIT_HASH");
23

34
pub fn long_version() -> String {
45
format!(
@@ -7,7 +8,7 @@ Path: {path}
78
Commit: {commit}
89
spacetimedb tool version {CLI_VERSION}; spacetimedb-lib version {lib_ver};",
910
path = std::env::current_exe().unwrap_or_else(|_| "<unknown>".into()).display(),
10-
commit = env!("GIT_HASH"),
11+
commit = CLI_GIT_HASH,
1112
lib_ver = spacetimedb_lib::version::spacetimedb_lib_version()
1213
)
1314
}

crates/codegen/src/typescript.rs

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use spacetimedb_schema::type_for_generate::{AlgebraicTypeDef, AlgebraicTypeUse,
1616

1717
use super::code_indenter::{CodeIndenter, Indenter};
1818
use super::Lang;
19+
use spacetimedb_lib::version::spacetimedb_lib_version;
1920

2021
type Imports = BTreeSet<AlgebraicTypeRef>;
2122

@@ -357,6 +358,11 @@ removeOnUpdate = (cb: (ctx: EventContext, onRow: {row_type}, newRow: {row_type})
357358
}
358359
out.dedent(1);
359360
writeln!(out, "}},");
361+
writeln!(out, "versionInfo: {{");
362+
out.indent(1);
363+
writeln!(out, "cliVersion: \"{}\",", spacetimedb_lib_version());
364+
out.dedent(1);
365+
writeln!(out, "}},");
360366
writeln!(
361367
out,
362368
"// Constructors which are used by the DbConnectionImpl to

crates/codegen/src/util.rs

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::{
88
use super::code_indenter::Indenter;
99
use convert_case::{Case, Casing};
1010
use itertools::Itertools;
11+
use spacetimedb_lib::version;
1112
use spacetimedb_lib::{db::raw_def::v9::Lifecycle, sats::AlgebraicTypeRef};
1213
use spacetimedb_primitives::ColList;
1314
use spacetimedb_schema::schema::TableSchema;
@@ -53,6 +54,13 @@ const AUTO_GENERATED_FILE_COMMENT: &[&str] = &[
5354

5455
pub(super) fn print_auto_generated_file_comment(output: &mut Indenter) {
5556
print_lines(output, AUTO_GENERATED_FILE_COMMENT);
57+
writeln!(
58+
output,
59+
"// This was generated using spacetimedb cli version {} (commit {}).",
60+
version::spacetimedb_lib_version(),
61+
version::GIT_HASH
62+
);
63+
writeln!(output);
5664
}
5765

5866
pub(super) fn type_ref_name(module: &ModuleDef, typeref: AlgebraicTypeRef) -> String {

crates/codegen/tests/codegen.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ macro_rules! declare_tests {
1717
fn $name() {
1818
let module = extract_descriptions(compiled_module()).unwrap().try_into().unwrap();
1919
let outfiles = HashMap::<_, _>::from_iter(generate(&module, &$lang));
20-
insta::with_settings!({ sort_maps => true }, {
20+
let mut settings = insta::Settings::clone_current();
21+
settings.set_sort_maps(true);
22+
// Ignore the autogenerated comments with version info, since it changes with every
23+
// build.
24+
settings.add_filter(r"// This was generated using spacetimedb cli version \d+\.\d+\.\d+ .*", "VERSION_COMMENT");
25+
// Ignore the place where the CLI version is put in the typescript REMOTE_MODULE info,
26+
// so it isn't constantly changing.
27+
settings.add_filter(r#"cliVersion: "\d+\.\d+\.\d+","#, r#"cliVersion: "X.Y.Z","#);
28+
settings.bind(|| {
2129
insta::assert_toml_snapshot!(outfiles);
2230
});
2331
}

0 commit comments

Comments
 (0)