Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add azure-autorust bin #896

Merged
merged 2 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions services/autorust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
members = [
"codegen",
"openapi",
"azure-autorust",
]
10 changes: 10 additions & 0 deletions services/autorust/azure-autorust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "azure-autorust"
version = "0.1.0"
authors = ["Cameron Taggart <[email protected]>"]
edition = "2021"
publish = false

[dependencies]
autorust_codegen = { path = "../codegen" }
clap = { version = "3.2.7", features = ["derive"] }
112 changes: 112 additions & 0 deletions services/autorust/azure-autorust/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<String> = 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(())
}
Comment on lines +86 to +104
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels weird that configs for the SDK crates are written by azure-autorust.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. It is behind a --publish arg and I'm the only one who runs it. It would be nice to keep the creation of the workflows together. It just saves me time. I can move this back into an example if you would prefer that.


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(())
}
23 changes: 0 additions & 23 deletions services/autorust/codegen/examples/gen_mgmt.rs

This file was deleted.

23 changes: 0 additions & 23 deletions services/autorust/codegen/examples/gen_svc.rs

This file was deleted.

55 changes: 0 additions & 55 deletions services/autorust/codegen/examples/gen_workspace.rs

This file was deleted.