diff --git a/.github/workflows/check-all-services.yml b/.github/workflows/check-all-services.yml index f8c9c4cfda..fe2e806244 100644 --- a/.github/workflows/check-all-services.yml +++ b/.github/workflows/check-all-services.yml @@ -4139,22 +4139,6 @@ jobs: cd services cargo check --all-features -p azure_svc_blobstorage - azure_svc_codesigning: - if: always() - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true - - uses: Swatinem/rust-cache@v2 - - name: check all features - run: | - cd services - cargo check --all-features -p azure_svc_codesigning - azure_svc_confidentialledger: if: always() runs-on: ubuntu-latest diff --git a/services/Cargo.toml b/services/Cargo.toml index 49301ad2bf..3128d992b1 100644 --- a/services/Cargo.toml +++ b/services/Cargo.toml @@ -258,7 +258,6 @@ members = [ "svc/attestation", "svc/batch", "svc/blobstorage", - "svc/codesigning", "svc/confidentialledger", "svc/containerregistry", "svc/datalakeanalytics", diff --git a/services/autorust/azure-autorust/src/main.rs b/services/autorust/azure-autorust/src/main.rs index ea0f209e46..44cfa43daf 100644 --- a/services/autorust/azure-autorust/src/main.rs +++ b/services/autorust/azure-autorust/src/main.rs @@ -3,13 +3,14 @@ // cargo run --release -p azure-autorust -- -p azure_svc_queuestorage use autorust_codegen::{ - crates::{list_crate_names, list_dirs}, + crates::list_crates, gen, get_mgmt_readmes, get_svc_readmes, jinja::{CheckAllServicesYml, PublishSdksYml, PublishServicesYml, WorkspaceCargoToml}, Error, ErrorKind, Result, ResultExt, RunConfig, SpecReadme, }; use clap::Parser; use rayon::prelude::*; +use std::{collections::BTreeSet, path::PathBuf}; #[derive(Debug, clap::Parser)] struct Args { @@ -35,15 +36,34 @@ impl Args { fn main() -> Result<()> { let args = Args::parse(); let packages = &args.packages(); - gen_crates(packages)?; - gen_services_workspace(packages)?; + + let existing_crates = list_crates(&PathBuf::from("../"))?; + let generated = gen_crates(packages)?; + gen_services_workspace(&generated)?; + if packages.is_empty() { - gen_workflow_check_all_services()?; + gen_workflow_check_all_services(&generated)?; if args.publish { gen_workflow_publish_sdks()?; - gen_workflow_publish_services()?; + gen_workflow_publish_services(&generated)?; + } + + let removed = existing_crates.difference(&generated).collect::>(); + let added = generated.difference(&existing_crates).collect::>(); + if !removed.is_empty() { + println!("the following crates are no longer generated:"); + for name in removed { + println!("- {name}"); + } + } + if !added.is_empty() { + println!("the following crates are newly generated:"); + for name in added { + println!("- {name}"); + } } } + Ok(()) } @@ -63,7 +83,7 @@ fn gen_crate(only_packages: &[&str], crate_type: &str, spec: &SpecReadme) -> Res } } -fn gen_crates(only_packages: &[&str]) -> Result<()> { +fn gen_crates(only_packages: &[&str]) -> Result> { let svc = get_svc_readmes()?.into_iter().map(|x| ("svc".to_string(), x)); let mgmt = get_mgmt_readmes()?.into_iter().map(|x| ("mgmt".to_string(), x)); let crate_iters = svc.chain(mgmt).collect::>(); @@ -77,12 +97,17 @@ fn gen_crates(only_packages: &[&str]) -> Result<()> { let mut errors = vec![]; let mut completed = vec![]; + let mut skipped = vec![]; for result in results { match result { Ok(result) => { - if let Some(result) = result { - completed.push(result); + if let Some((name, tags)) = result { + if tags.is_empty() { + skipped.push(name); + } else { + completed.push((name, tags)); + } } } Err(err) => { @@ -98,40 +123,34 @@ fn gen_crates(only_packages: &[&str]) -> Result<()> { return Err(Error::new(ErrorKind::CodeGen, "Failed to generate some crates")); } - for (package_name, tags) in completed { + for (package_name, tags) in &completed { println!("{package_name}"); - if tags.is_empty() { - println!(" No tags"); - } else { - for tag in tags { - println!("- {tag}"); - } + for tag in tags { + println!("- {tag}"); } } - Ok(()) -} + if !skipped.is_empty() { + println!("the following crates were not generated due to configuration:"); + for name in &skipped { + println!("- {name}"); + } + } -fn gen_services_workspace(only_packages: &[&str]) -> Result<()> { - let dirs: Vec = if only_packages.is_empty() { - list_dirs()? - .iter() - .map(|dir| dir.as_str().replace('\\', "/").replace("../", "")) - .collect() - } else { - only_packages - .iter() - .map(|p| p.replace("azure_mgmt_", "mgmt/").replace("azure_svc_", "svc/")) - .collect() - }; + Ok(completed.into_iter().map(|(package_name, _)| package_name).collect()) +} +fn gen_services_workspace(only_packages: &BTreeSet) -> Result<()> { + let dirs = only_packages + .iter() + .map(|p| p.replace("azure_mgmt_", "mgmt/").replace("azure_svc_", "svc/")) + .collect(); let toml = WorkspaceCargoToml { dirs }; toml.create("../Cargo.toml")?; Ok(()) } -fn gen_workflow_check_all_services() -> Result<()> { - let packages = list_crate_names()?; +fn gen_workflow_check_all_services(packages: &BTreeSet) -> Result<()> { let packages = &packages.iter().map(String::as_str).collect(); let yml = CheckAllServicesYml { packages }; @@ -159,8 +178,7 @@ fn gen_workflow_publish_sdks() -> Result<()> { Ok(()) } -fn gen_workflow_publish_services() -> Result<()> { - let packages = list_crate_names()?; +fn gen_workflow_publish_services(packages: &BTreeSet) -> Result<()> { let packages = &packages.iter().map(String::as_str).collect(); let yml = PublishServicesYml { packages }; yml.create("../../.github/workflows/publish-services.yml")?; diff --git a/services/autorust/codegen/Cargo.toml b/services/autorust/codegen/Cargo.toml index 1b4bc170c5..f786a0bb7d 100644 --- a/services/autorust/codegen/Cargo.toml +++ b/services/autorust/codegen/Cargo.toml @@ -26,6 +26,7 @@ camino = "1.1" askama = "0.12" toml = "0.8" qstring = "0.7" +cargo_toml = "0.17" [dev-dependencies] thiserror = "1.0" diff --git a/services/autorust/codegen/src/crates.rs b/services/autorust/codegen/src/crates.rs index ef8c2c0778..43ce993d59 100644 --- a/services/autorust/codegen/src/crates.rs +++ b/services/autorust/codegen/src/crates.rs @@ -1,10 +1,12 @@ use crate::{ErrorKind, Result, ResultExt}; use camino::{Utf8Path, Utf8PathBuf}; +use cargo_toml::Manifest; use serde::Deserialize; -use std::io::BufRead; use std::{ + collections::BTreeSet, fs::{self, File}, - io::BufReader, + io::{BufRead, BufReader}, + path::Path, str::FromStr, }; @@ -22,6 +24,23 @@ fn list_dirs_in(dir: impl AsRef) -> Result> { Ok(dirs) } +pub fn list_crates(services_dir: &Path) -> Result> { + let mut package_names = BTreeSet::new(); + let base_path = services_dir.join("Cargo.toml"); + let manifest = Manifest::from_path(base_path)?; + if let Some(workspaces) = manifest.workspace { + for member in workspaces.members { + let member_path = services_dir.join(member).join("Cargo.toml"); + let Ok(manifest) = Manifest::from_path(member_path) else { continue }; + let Some(package) = manifest.package else { + continue; + }; + package_names.insert(package.name); + } + } + Ok(package_names) +} + pub fn list_dirs() -> Result> { let mut names: Vec<_> = list_dirs_in("../mgmt")?.into_iter().collect(); names.extend(list_dirs_in("../svc")?); @@ -29,20 +48,6 @@ pub fn list_dirs() -> Result> { Ok(names) } -pub fn list_crate_names() -> Result> { - let mut names: Vec<_> = list_dirs_in("../mgmt")? - .into_iter() - .filter_map(|d| d.file_name().map(|d| format!("azure_mgmt_{d}"))) - .collect(); - names.extend( - list_dirs_in("../svc")? - .into_iter() - .filter_map(|d| d.file_name().map(|d| format!("azure_svc_{d}"))), - ); - names.sort(); - Ok(names) -} - pub fn has_version(name: &str, version: &str) -> Result { Ok(get_versions(name)?.iter().any(|v| v.vers.as_str() == version)) } diff --git a/services/autorust/codegen/src/error.rs b/services/autorust/codegen/src/error.rs index 263013acbb..e67729c770 100644 --- a/services/autorust/codegen/src/error.rs +++ b/services/autorust/codegen/src/error.rs @@ -208,6 +208,12 @@ impl From for Error { } } +impl From for Error { + fn from(error: cargo_toml::Error) -> Self { + Self::new(ErrorKind::Parse, error) + } +} + impl From for Error { fn from(error: autorust_openapi::Error) -> Self { Self::new(ErrorKind::Parse, error)