Skip to content

Commit

Permalink
feat: assert whether generated and versioned schema are identical
Browse files Browse the repository at this point in the history
  • Loading branch information
raimundo-henriques committed Jun 6, 2024
1 parent 619a3b5 commit 97ad402
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ jobs:
cargo test
cargo clippy -- -Dwarnings
generate_schema:
validate_schema:
runs-on: ubuntu-latest
needs: build_and_test
if: github.ref == 'refs/heads/main'
# if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- name: Generate schema
- name: Test schema
run: |
cargo run
cargo run --release > schema.gen.json
# assert the generated and versioned file equal
diff -B schema/data-model-schema.json schema.gen.json
2 changes: 1 addition & 1 deletion schema/data-model-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,4 @@
"pattern": "^\\d+\\.\\d+\\.\\d+(-\\d{8})?$"
}
}
}
}
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ use std::io::{Error, Write};
fn main() -> Result<(), Error> {
let schema = schema_for!(ProductFootprint);

let schema_json = to_string_pretty(&schema).expect("Failed to serialize schema");
let mut schema_json = to_string_pretty(&schema).expect("Failed to serialize schema");

if !schema_json.ends_with('\n') {
schema_json.push('\n');
}

let mut file = File::create("./schema/data-model-schema.json")?;

Expand Down

0 comments on commit 97ad402

Please sign in to comment.