diff --git a/services/autorust/Cargo.toml b/services/autorust/Cargo.toml index 435a4d80b1..53561b55df 100644 --- a/services/autorust/Cargo.toml +++ b/services/autorust/Cargo.toml @@ -2,4 +2,5 @@ members = [ "codegen", "openapi", + "azure-autorust", ] diff --git a/services/autorust/azure-autorust/Cargo.toml b/services/autorust/azure-autorust/Cargo.toml new file mode 100644 index 0000000000..61101272cd --- /dev/null +++ b/services/autorust/azure-autorust/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "azure-autorust" +version = "0.1.0" +authors = ["Cameron Taggart "] +edition = "2021" +publish = false + +[dependencies] +autorust_codegen = { path = "../codegen" } +clap = { version = "3.2.7", features = ["derive"] } diff --git a/services/autorust/azure-autorust/src/main.rs b/services/autorust/azure-autorust/src/main.rs new file mode 100644 index 0000000000..6b637a87c1 --- /dev/null +++ b/services/autorust/azure-autorust/src/main.rs @@ -0,0 +1,112 @@ +// cargo run --release -p azure-autorust + +use autorust_codegen::{ + crates::{list_crate_names, list_dirs}, + gen::gen_crate, + get_mgmt_readmes, get_svc_readmes, + jinja::{CargoToml, CheckAllServicesYml, PublishSdksYml, PublishServicesYml}, + Result, RunConfig, +}; +use clap::Parser; + +#[derive(Debug, clap::Parser)] +struct Args { + /// Generate the publish GitHub workflows + #[clap(long)] + publish: bool, +} + +fn main() -> Result<()> { + let args = Args::parse(); + gen_mgmt()?; + gen_svc()?; + gen_services_workspace()?; + gen_workflow_check_all_services()?; + if args.publish { + gen_workflow_publish_sdks()?; + gen_workflow_publish_services()?; + } + Ok(()) +} + +fn gen_mgmt() -> Result<()> { + const OUTPUT_FOLDER: &str = "../mgmt"; + const ONLY_SERVICES: &[&str] = &[]; + let run_config = &mut RunConfig::new("azure_mgmt_"); + for (i, spec) in get_mgmt_readmes()?.iter().enumerate() { + if !ONLY_SERVICES.is_empty() { + if ONLY_SERVICES.contains(&spec.spec()) { + println!("{} {}", i + 1, spec.spec()); + gen_crate(spec, run_config, OUTPUT_FOLDER)?; + } + } else { + println!("{} {}", i + 1, spec.spec()); + gen_crate(spec, run_config, OUTPUT_FOLDER)?; + } + } + Ok(()) +} + +fn gen_svc() -> Result<()> { + const OUTPUT_FOLDER: &str = "../svc"; + const ONLY_SERVICES: &[&str] = &[]; + let run_config = &mut RunConfig::new("azure_svc_"); + for (i, spec) in get_svc_readmes()?.iter().enumerate() { + if !ONLY_SERVICES.is_empty() { + if ONLY_SERVICES.contains(&spec.spec()) { + println!("{} {}", i + 1, spec.spec()); + gen_crate(spec, run_config, OUTPUT_FOLDER)?; + } + } else { + println!("{} {}", i + 1, spec.spec()); + gen_crate(spec, run_config, OUTPUT_FOLDER)?; + } + } + Ok(()) +} + +fn gen_services_workspace() -> Result<()> { + let dirs = list_dirs()?; + let dirs: Vec = dirs.iter().map(|dir| dir.as_str().replace('\\', "/").replace("../", "")).collect(); + + let yml = CargoToml { dirs }; + yml.create("../Cargo.toml")?; + Ok(()) +} + +fn gen_workflow_check_all_services() -> Result<()> { + let packages = list_crate_names()?; + let packages = &packages.iter().map(String::as_str).collect(); + + let yml = CheckAllServicesYml { packages }; + yml.create("../../.github/workflows/check-all-services.yml")?; + Ok(()) +} + +fn gen_workflow_publish_sdks() -> Result<()> { + let packages = &vec![ + "azure_core", + "azure_data_cosmos", + "azure_data_tables", + "azure_identity", + "azure_iot_hub", + "azure_messaging_eventgrid", + "azure_messaging_servicebus", + "azure_security_keyvault", + "azure_storage", + "azure_storage_blobs", + "azure_storage_datalake", + "azure_storage_queues", + ]; + let yml = PublishSdksYml { packages }; + yml.create("../../.github/workflows/publish-sdks.yml")?; + Ok(()) +} + +fn gen_workflow_publish_services() -> Result<()> { + let packages = list_crate_names()?; + let packages = &packages.iter().map(String::as_str).collect(); + let yml = PublishServicesYml { packages }; + yml.create("../../.github/workflows/publish-services.yml")?; + Ok(()) +} diff --git a/services/autorust/codegen/examples/gen_mgmt.rs b/services/autorust/codegen/examples/gen_mgmt.rs deleted file mode 100644 index 4cdda8a0b6..0000000000 --- a/services/autorust/codegen/examples/gen_mgmt.rs +++ /dev/null @@ -1,23 +0,0 @@ -// cargo run --example gen_mgmt --release -// https://github.com/Azure/azure-rest-api-specs/blob/master/specification/compute/resource-manager -use autorust_codegen::{self, gen::gen_crate, get_mgmt_readmes, Result, RunConfig}; - -const OUTPUT_FOLDER: &str = "../mgmt"; - -const ONLY_SERVICES: &[&str] = &[]; - -fn main() -> Result<()> { - let run_config = &mut RunConfig::new("azure_mgmt_"); - for (i, spec) in get_mgmt_readmes()?.iter().enumerate() { - if !ONLY_SERVICES.is_empty() { - if ONLY_SERVICES.contains(&spec.spec()) { - println!("{} {}", i + 1, spec.spec()); - gen_crate(spec, run_config, OUTPUT_FOLDER)?; - } - } else { - println!("{} {}", i + 1, spec.spec()); - gen_crate(spec, run_config, OUTPUT_FOLDER)?; - } - } - Ok(()) -} diff --git a/services/autorust/codegen/examples/gen_svc.rs b/services/autorust/codegen/examples/gen_svc.rs deleted file mode 100644 index 82394e0261..0000000000 --- a/services/autorust/codegen/examples/gen_svc.rs +++ /dev/null @@ -1,23 +0,0 @@ -// cargo run --example gen_svc --release -// https://github.com/Azure/azure-rest-api-specs/blob/master/specification/batch/data-plane -use autorust_codegen::{self, gen::gen_crate, get_svc_readmes, Result, RunConfig}; - -const OUTPUT_FOLDER: &str = "../svc"; - -const ONLY_SERVICES: &[&str] = &[]; - -fn main() -> Result<()> { - let run_config = &mut RunConfig::new("azure_svc_"); - for (i, spec) in get_svc_readmes()?.iter().enumerate() { - if !ONLY_SERVICES.is_empty() { - if ONLY_SERVICES.contains(&spec.spec()) { - println!("{} {}", i + 1, spec.spec()); - gen_crate(spec, run_config, OUTPUT_FOLDER)?; - } - } else { - println!("{} {}", i + 1, spec.spec()); - gen_crate(spec, run_config, OUTPUT_FOLDER)?; - } - } - Ok(()) -} diff --git a/services/autorust/codegen/examples/gen_workspace.rs b/services/autorust/codegen/examples/gen_workspace.rs deleted file mode 100644 index 14edb5e173..0000000000 --- a/services/autorust/codegen/examples/gen_workspace.rs +++ /dev/null @@ -1,55 +0,0 @@ -// cargo run --example gen_workspace - -use autorust_codegen::{ - crates::{list_crate_names, list_dirs}, - jinja::{CargoToml, CheckAllServicesYml, PublishSdksYml, PublishServicesYml}, - Result, -}; - -fn main() -> Result<()> { - let dirs = list_dirs()?; - let dirs: Vec = dirs.iter().map(|dir| dir.as_str().replace("\\", "/").replace("../", "")).collect(); - - let yml = CargoToml { dirs }; - yml.create("../Cargo.toml")?; - - let packages = list_crate_names()?; - let packages = &packages.iter().map(String::as_str).collect(); - - let yml = CheckAllServicesYml { packages }; - yml.create("../../.github/workflows/check-all-services.yml")?; - - if std::env::args().any(|arg| arg == "publish") { - publish_sdks()?; - publish_services()?; - } - Ok(()) -} - -fn publish_sdks() -> Result<()> { - let packages = &vec![ - "azure_core", - "azure_data_cosmos", - "azure_data_tables", - "azure_identity", - "azure_iot_hub", - "azure_messaging_eventgrid", - "azure_messaging_servicebus", - "azure_security_keyvault", - "azure_storage", - "azure_storage_blobs", - "azure_storage_datalake", - "azure_storage_queues", - ]; - let yml = PublishSdksYml { packages }; - yml.create("../../.github/workflows/publish-sdks.yml")?; - Ok(()) -} - -fn publish_services() -> Result<()> { - let packages = list_crate_names()?; - let packages = &packages.iter().map(String::as_str).collect(); - let yml = PublishServicesYml { packages }; - yml.create("../../.github/workflows/publish-services.yml")?; - Ok(()) -}