Skip to content

Commit

Permalink
Move generating_json_schema to generate crate (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
wkazmierczak authored Jul 10, 2024
1 parent 3903a26 commit ef56167
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ jobs:
cargo build --no-default-features
- name: 📄 Generate JSON schema
working-directory: ./generate
run: |
cargo run --bin generate_json_schema --features decklink
cargo run --bin generate_docs --features decklink
cargo run --bin generate_from_types -- --check
- name: 🧪 Run tests
run: |
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/deploy_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
paths:
- "docs/**"
- "schemas/**"
- "src/bin/generate_docs/**"
- "generate/src/bin/generate_from_types/**"
- ".github/workflows/deploy_docs.yml"

permissions:
Expand Down Expand Up @@ -49,7 +49,8 @@ jobs:
uses: dtolnay/rust-toolchain@stable

- name: 📄 Generate docs from JSON schema
run: cargo run --bin generate_docs --features decklink
working-directory: ./generate
run: cargo run --bin generate_from_types

- name: 🛠 Install dependencies
run: npm ci
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ rubato = "0.15.0"
futures-util = "0.3.30"
tokio = { version = "1", features = ["full"] }
wgpu = { version = "0.19.1", features = ["naga-ir"] }
schemars = { git = "https://github.com/membraneframework-labs/schemars", rev = "a5ad1f9", features = [
"preserve_order",
] }

[dependencies]
compositor_render = { workspace = true }
Expand All @@ -63,9 +66,7 @@ log = { workspace = true }
signal-hook = { workspace = true }
shared_memory = { workspace = true }
fs_extra = "1.3.0"
schemars = { git = "https://github.com/membraneframework-labs/schemars", rev = "a5ad1f9", features = [
"preserve_order",
] }
schemars = { workspace = true}
image = { workspace = true }
thiserror = { workspace = true }
rtp = { workspace = true }
Expand Down
2 changes: 0 additions & 2 deletions build_tools/nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ rustPlatform.buildRustPackage {

postFixup =
''
rm -f $out/bin/generate_docs
rm -f $out/bin/generate_json_schema
rm -f $out/bin/live_compositor
rm -f $out/bin/package_for_release
rm -f $out/bin/update_snapshots
Expand Down
6 changes: 6 additions & 0 deletions generate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ license = "BUSL-1.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
decklink = ["live_compositor/decklink"]

[dependencies]
live_compositor = { path = ".." }
reqwest = { workspace = true }
anyhow = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
ffmpeg-next = { workspace = true }
compositor_render = { workspace = true }
Expand All @@ -23,3 +27,5 @@ tracing = { workspace = true }
opus = { workspace = true }
pitch-detection = "0.3.0"
rand = { workspace = true }
schemars = { workspace = true}
tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] }
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
use docs_config::DocsConfig;
use document::generate;
use super::docs_config::DocsConfig;
use super::document::generate;
use super::markdown::overrides;
use live_compositor::types::{
DeckLink, Image, ImageSpec, InputStream, Mp4, Rescaler, RtpInputStream, RtpOutputStream,
Shader, ShaderSpec, Text, Tiles, View, WebRendererSpec, WebView,
};
use markdown::overrides;
use std::{fs, path::PathBuf};

mod definition;
mod docs_config;
mod document;
mod markdown;
mod schema_parser;

fn main() {
tracing_subscriber::fmt().init();
let docs_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("docs/pages/api/generated");
pub fn generate_docs() {
let docs_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../docs/pages/api/generated");
if docs_path.exists() {
fs::remove_dir_all(&docs_path).unwrap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ enum ApiTypes {
UpdateOutput(types::UpdateOutputRequest),
}

fn main() {
let update_flag = std::env::args().any(|arg| &arg == "--update");

let (scene_schema_action, api_schema_action) = match update_flag {
true => (SchemaAction::Update, SchemaAction::Update),
false => (SchemaAction::CheckIfChanged, SchemaAction::Nothing),
pub fn generate_json_schema(check_flag: bool) {
let (scene_schema_action, api_schema_action) = match check_flag {
true => (SchemaAction::CheckIfChanged, SchemaAction::Nothing),
false => (SchemaAction::Update, SchemaAction::Update),
};
generate_schema(
schema_for!(types::UpdateOutputRequest),
Expand Down Expand Up @@ -79,7 +77,7 @@ fn generate_schema(mut current_schema: RootSchema, name: &'static str, action: S
flatten_definitions_with_one_of(&mut current_schema);

let root_dir: PathBuf = ROOT_DIR.into();
let schema_path = root_dir.join(format!("schemas/{}.schema.json", name));
let schema_path = root_dir.join(format!("../schemas/{}.schema.json", name));
fs::create_dir_all(schema_path.parent().unwrap()).unwrap();

let json_from_disk = match fs::read_to_string(&schema_path) {
Expand All @@ -93,7 +91,7 @@ fn generate_schema(mut current_schema: RootSchema, name: &'static str, action: S
match action {
SchemaAction::Update => fs::write(schema_path, &json_current).unwrap(),
SchemaAction::CheckIfChanged => {
panic!("Schema changed. Rerun with --update to regenerate it.")
panic!("Schema changed. Rerun without --check arg to regenerate it.")
}
SchemaAction::Nothing => (),
};
Expand Down
14 changes: 14 additions & 0 deletions generate/src/bin/generate_from_types/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mod definition;
mod docs_config;
mod document;
mod generate_docs;
mod generate_json_schema;
mod markdown;
mod schema_parser;

fn main() {
tracing_subscriber::fmt().init();
let check_flag = std::env::args().any(|arg| &arg == "--check");
generate_docs::generate_docs();
generate_json_schema::generate_json_schema(check_flag);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit ef56167

Please sign in to comment.