Skip to content

Commit

Permalink
ci: Regenerate and verify the types files (#350)
Browse files Browse the repository at this point in the history
* fix: Extend generation of types by Default macro

in order to match a change introduced in

commit eab4caa: "Rewrite the client to be async all the way through".

this resolves #349

* ci: Regenerate and verify the types files

in order to enforce congruence between them and the schema.

Furthermore drop the generated files from rustfmt ignore
as they're apparently currently formatted.
  • Loading branch information
AiyionPrime authored Jul 24, 2024
1 parent ed31810 commit 59094ff
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/ci_verify_clean_types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI verify cleanly generated types
'on':
workflow_call: null
jobs:
types:
runs-on: ubuntu-latest
steps:
- name: Checkout (GitHub)
uses: actions/checkout@v4
- name: Install dependencies
run: npm install
working-directory: tools/schema/
- name: Regenerate types
run: node gen_types
working-directory: tools/schema/
- name: Format generated code
run: rustfmt lib/src/types/service_types/mod.rs
- name: Verify generated code matches committed code
run: git status --porcelain
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ jobs:
verify-clean-supported-message:
uses: ./.github/workflows/ci_verify_clean_supported_message.yml

verify-clean-types:
uses: ./.github/workflows/ci_verify_clean_types.yml

verify-code-formatting:
uses: ./.github/workflows/ci_format_code.yml

Expand Down
1 change: 0 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ignore = [
"types/src/node_ids.rs",
"types/src/service_types",
]
7 changes: 7 additions & 0 deletions tools/schema/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ function makeImportLookupMap(import_map) {
return result;
}

// Types that will be marked as Default constructable
const DEFAULT_TYPES = ["ReadValueId", ];

// Types that will be marked as JSON serializable. Serialization is for pubsub, and debugging purposes
const JSON_SERIALIZED_TYPES = [
"ReadValueId", "DataChangeFilter", "EventFilter", "SimpleAttributeOperand", "ContentFilter",
Expand Down Expand Up @@ -623,12 +626,16 @@ use std::io::{Read, Write};
contents += `/// ${structured_type.documentation}\n`;
}

const is_default_constructable = _.includes(DEFAULT_TYPES, structured_type.name);
const is_json_serializable = _.includes(JSON_SERIALIZED_TYPES, structured_type.name);

let derivations = "Debug, Clone, PartialEq";
if (is_json_serializable) {
derivations += ", Serialize, Deserialize";
}
if (is_default_constructable) {
derivations += ", Default";
}
contents += `#[derive(${derivations})]
`;

Expand Down

0 comments on commit 59094ff

Please sign in to comment.