From ab4d83bf345da8b561fe504a81e1edb8ab555530 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Apr 2022 16:25:55 +0200 Subject: [PATCH 1/5] Add initial version of validator This initial version just exports each model, failing if there's an error. Eventually, it should also validate the exported 3MF file. But the current version is already useful, and can replace the manually specified model export steps in the CI build. --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + tools/validator/Cargo.toml | 7 +++++++ tools/validator/src/main.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 tools/validator/Cargo.toml create mode 100644 tools/validator/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 660d0fb11..cfc8c07e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2789,6 +2789,13 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "validator" +version = "0.1.0" +dependencies = [ + "anyhow", +] + [[package]] name = "valuable" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 1b41354cd..0802afc10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ members = [ "models/star", "tools/release-operator", + "tools/validator", ] default-members = [ "crates/fj-app", diff --git a/tools/validator/Cargo.toml b/tools/validator/Cargo.toml new file mode 100644 index 000000000..cf6ae2fee --- /dev/null +++ b/tools/validator/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "validator" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1.0.56" diff --git a/tools/validator/src/main.rs b/tools/validator/src/main.rs new file mode 100644 index 000000000..06cb4096a --- /dev/null +++ b/tools/validator/src/main.rs @@ -0,0 +1,27 @@ +use std::{fs, process::Command}; + +use anyhow::{anyhow, bail}; + +fn main() -> anyhow::Result<()> { + for model in fs::read_dir("models")? { + let model = model?; + let model = model.file_name().into_string().map_err(|err| { + anyhow!("Failed to convert directory name to `String`: {:?}", err) + })?; + + let export_file = format!("{model}.3mf"); + + let exit_status = Command::new("cargo") + .arg("run") + .arg("--") + .args(["--model", &model]) + .args(["--export", &export_file]) + .status()?; + + if !exit_status.success() { + bail!("Exporting model failed with error status: {}", exit_status); + } + } + + Ok(()) +} From c401377dbba4c6a5ce96154e6393a0822e6b5b23 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Apr 2022 16:26:20 +0200 Subject: [PATCH 2/5] Prevent tools from accidentally being published --- tools/release-operator/Cargo.toml | 1 + tools/validator/Cargo.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/tools/release-operator/Cargo.toml b/tools/release-operator/Cargo.toml index 0b0344b81..a657e75da 100644 --- a/tools/release-operator/Cargo.toml +++ b/tools/release-operator/Cargo.toml @@ -2,6 +2,7 @@ name = "release-operator" version = "0.3.1" edition = "2021" +publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tools/validator/Cargo.toml b/tools/validator/Cargo.toml index cf6ae2fee..ad750353c 100644 --- a/tools/validator/Cargo.toml +++ b/tools/validator/Cargo.toml @@ -2,6 +2,7 @@ name = "validator" version = "0.1.0" edition = "2021" +publish = false [dependencies] anyhow = "1.0.56" From 5b73f76412fff54b3fe439db37e36aa58d8c7446 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Apr 2022 16:32:10 +0200 Subject: [PATCH 3/5] Update order of jobs in CI config I think having first the Linux-only jobs, then the more complex matrix job, is a bit more readable. --- .github/workflows/ci.yml | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 12417b0dd..b62db2d93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,6 +42,26 @@ jobs: command: fmt args: --all -- --check + clippy: + name: Clippy Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup Toolchain + uses: oxidecomputer/actions-rs_toolchain@oxide/master + # see https://github.com/actions-rs/toolchain/pull/209 + # uses: actions-rs/toolchain@v1 + with: + override: true + profile: minimal + target: ${{ matrix.target }} + - run: rustup component add clippy + - uses: Swatinem/rust-cache@1232abb8968faf344409165de17cbf9e7f340fd8 + - uses: actions-rs/clippy-check@9d09632661e31982c0be8af59aeb96b680641bc4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-features + test: name: Test strategy: @@ -84,23 +104,3 @@ jobs: with: command: run args: -- --model star --export star.3mf - - clippy: - name: Clippy Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup Toolchain - uses: oxidecomputer/actions-rs_toolchain@oxide/master - # see https://github.com/actions-rs/toolchain/pull/209 - # uses: actions-rs/toolchain@v1 - with: - override: true - profile: minimal - target: ${{ matrix.target }} - - run: rustup component add clippy - - uses: Swatinem/rust-cache@1232abb8968faf344409165de17cbf9e7f340fd8 - - uses: actions-rs/clippy-check@9d09632661e31982c0be8af59aeb96b680641bc4 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features From bca6881dfd2dae4cf26cbabf9ee16d66273e51c1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Apr 2022 16:46:02 +0200 Subject: [PATCH 4/5] Include validator in CI build --- .github/workflows/ci.yml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b62db2d93..49d2fed1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,16 +91,4 @@ jobs: - uses: actions-rs/cargo@4ff6ec2846f6e7217c1a9b0b503506665f134c4b with: command: run - args: -- --model cuboid --export cuboid.3mf - - uses: actions-rs/cargo@4ff6ec2846f6e7217c1a9b0b503506665f134c4b - with: - command: run - args: -- --model group --export group.3mf - - uses: actions-rs/cargo@4ff6ec2846f6e7217c1a9b0b503506665f134c4b - with: - command: run - args: -- --model spacer --export spacer.3mf - - uses: actions-rs/cargo@4ff6ec2846f6e7217c1a9b0b503506665f134c4b - with: - command: run - args: -- --model star --export star.3mf + args: --package validator From 0eb5a6e74c25df73679f2dc6e292ab730fbc1a98 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Apr 2022 16:49:00 +0200 Subject: [PATCH 5/5] Add README for validator --- tools/validator/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tools/validator/README.md diff --git a/tools/validator/README.md b/tools/validator/README.md new file mode 100644 index 000000000..6130f2213 --- /dev/null +++ b/tools/validator/README.md @@ -0,0 +1,3 @@ +# Validator + +Used by the CI build to export (and in the future, validate) 3MF files.