diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..fbeac10 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,24 @@ +# build and publish rust crate +name: Rust + +on: + push: + branches: [ main ] + +jobs: + release: + name: Rust + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable + override: true + - uses: katyo/publish-crates@v2 + with: + registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} + path: crates/openapi-client + check-repo: true + ignore-unpublished-changes: true + dry-run: true diff --git a/.gitignore b/.gitignore index 37b5772..47b2468 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ dist/ /exports www/venv www/.cache + +Cargo.lock +target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..723ba4e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,4 @@ +[workspace] +members = ["crates/openapi-client"] +resolver = "2" +edition = "2021" diff --git a/crates/openapi-client/Cargo.toml b/crates/openapi-client/Cargo.toml new file mode 100644 index 0000000..3f0ad9f --- /dev/null +++ b/crates/openapi-client/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "process-compose-openapi-client" +version = "1.46.0" +description = "OpenAPI client for Process Compose" +license = "Apache-2.0" +edition = "2021" +include = [ + "src/**", + "Cargo.toml", + "build.rs", + "../../src/docs/swagger.json", + "../../README.md", +] + +[lib] +crate-type = ["rlib"] + +[dependencies] +progenitor-client = { version = "0.9" } +reqwest = { version = "0.12", default-features = false, features = [ + "json", + "stream", +] } +serde = { version = "1.0", default-features = false, features = ["derive"] } +serde_json = { version = "1.0", default-features = false } + +[dev-dependencies] +tokio = { version = "1.41", features = ["macros"] } + +[build-dependencies] +progenitor = { version = "0.9" } +syn = { version = "2.0.85" } +prettyplease = { version = "0.2.25" } +serde_json = { version = "1.0", default-features = false } diff --git a/crates/openapi-client/build.rs b/crates/openapi-client/build.rs new file mode 100644 index 0000000..90851ec --- /dev/null +++ b/crates/openapi-client/build.rs @@ -0,0 +1,19 @@ +fn main() { + let spec = if option_env!("CARGO_MANIFEST_DIR").is_some() + && option_env!("CARGO_REGISTRY_TOKEN").is_some() + { + println!("cargo:rerun-if-changed=../../../src/docs/swagger.json"); + std::fs::read_to_string("../../../src/docs/swagger.json").unwrap() + } else { + println!("cargo:rerun-if-changed=../../src/docs/swagger.json"); + std::fs::read_to_string("../../src/docs/swagger.json").unwrap() + }; + let spec = serde_json::from_str(&spec).unwrap(); + let mut generator = progenitor::Generator::default(); + let tokens = generator.generate_tokens(&spec).unwrap(); + let ast = syn::parse2(tokens).unwrap(); + let content = prettyplease::unparse(&ast); + let mut out_file = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).to_path_buf(); + out_file.push("lib.rs"); + std::fs::write(out_file, content).unwrap(); +} diff --git a/crates/openapi-client/src/lib.rs b/crates/openapi-client/src/lib.rs new file mode 100644 index 0000000..f7072f6 --- /dev/null +++ b/crates/openapi-client/src/lib.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/lib.rs")); diff --git a/crates/openapi-client/tests/mod.rs b/crates/openapi-client/tests/mod.rs new file mode 100644 index 0000000..7618798 --- /dev/null +++ b/crates/openapi-client/tests/mod.rs @@ -0,0 +1,13 @@ +use process_compose_openapi_client; + +#[tokio::test] +async fn compiles_but_errors_with_bad_url() { + let client = process_compose_openapi_client::Client::new("locahost:8080"); + match client.get_process_info("process-compose").await { + Ok(response) => { + let _name = &response.name; + unreachable!("errors on bad url"); + } + Err(_) => {} + } +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..1de01fa --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.81.0"