From 815ccdf23f76271127ca5ad081bad39eb6388811 Mon Sep 17 00:00:00 2001 From: Yifei Date: Tue, 15 Aug 2023 15:51:12 +0800 Subject: [PATCH] feat: update worksapce idl (#218) --- Cargo.lock | 4 ++-- volo-build/Cargo.toml | 2 +- volo-build/src/model.rs | 22 ++++++++++++++++++++++ volo-build/src/workspace.rs | 6 ++++++ volo-cli/Cargo.toml | 2 +- volo-cli/src/idl/update.rs | 27 ++++----------------------- 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a86be88..374bebac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2522,7 +2522,7 @@ dependencies = [ [[package]] name = "volo-build" -version = "0.6.1" +version = "0.6.2" dependencies = [ "anyhow", "async-trait", @@ -2549,7 +2549,7 @@ dependencies = [ [[package]] name = "volo-cli" -version = "0.6.1" +version = "0.6.2" dependencies = [ "anyhow", "clap", diff --git a/volo-build/Cargo.toml b/volo-build/Cargo.toml index 9fb738b4..a135e098 100644 --- a/volo-build/Cargo.toml +++ b/volo-build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "volo-build" -version = "0.6.1" +version = "0.6.2" edition.workspace = true homepage.workspace = true repository.workspace = true diff --git a/volo-build/src/model.rs b/volo-build/src/model.rs index 895b8d1f..b2f9babd 100644 --- a/volo-build/src/model.rs +++ b/volo-build/src/model.rs @@ -2,6 +2,8 @@ use std::{collections::HashMap, path::PathBuf}; use serde::{Deserialize, Serialize}; +use crate::util::get_repo_latest_commit_id; + pub const DEFAULT_ENTRY_NAME: &str = "default"; pub const DEFAULT_FILENAME: &str = "volo_gen.rs"; @@ -39,6 +41,15 @@ pub struct Idl { pub keep_unknown_fields: bool, } +impl Idl { + pub fn update(&mut self) -> anyhow::Result<()> { + match &mut self.source { + Source::Git(git_source) => git_source.update(), + Source::Local => Ok(()), + } + } +} + fn default_keep_unknown_fields() -> bool { false } @@ -61,6 +72,17 @@ pub struct GitSource { pub lock: Option, } +impl GitSource { + pub fn update(&mut self) -> anyhow::Result<()> { + let commit_id = + get_repo_latest_commit_id(&self.repo, self.r#ref.as_deref().unwrap_or("HEAD"))?; + + let _ = self.lock.insert(commit_id); + + Ok::<(), anyhow::Error>(()) + } +} + impl Config { pub fn new() -> Self { Default::default() diff --git a/volo-build/src/workspace.rs b/volo-build/src/workspace.rs index 080342bd..771b282b 100644 --- a/volo-build/src/workspace.rs +++ b/volo-build/src/workspace.rs @@ -27,6 +27,12 @@ pub struct WorkspaceConfig { pub(crate) services: Vec, } +impl WorkspaceConfig { + pub fn update_idls(&mut self) -> anyhow::Result<()> { + self.services.iter_mut().try_for_each(|s| s.idl.update()) + } +} + impl Builder where MkB: pilota_build::MakeBackend + Send, diff --git a/volo-cli/Cargo.toml b/volo-cli/Cargo.toml index dad2a13e..6e86a51a 100644 --- a/volo-cli/Cargo.toml +++ b/volo-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "volo-cli" -version = "0.6.1" +version = "0.6.2" edition.workspace = true homepage.workspace = true repository.workspace = true diff --git a/volo-cli/src/idl/update.rs b/volo-cli/src/idl/update.rs index 938c95d8..7bc5e78e 100644 --- a/volo-cli/src/idl/update.rs +++ b/volo-cli/src/idl/update.rs @@ -1,10 +1,7 @@ use std::collections::HashSet; use clap::Parser; -use volo_build::{ - model::{GitSource, Source}, - util::get_repo_latest_commit_id, -}; +use volo_build::model::{GitSource, Source}; use crate::{command::CliCommand, context::Context}; @@ -69,25 +66,9 @@ impl CliCommand for Update { } }; - should_update_gits.into_iter().try_for_each(|git_source| { - let commit_id = unsafe { - get_repo_latest_commit_id( - &git_source.as_ref().unwrap().repo, - git_source - .as_ref() - .unwrap() - .r#ref - .as_deref() - .unwrap_or("HEAD"), - ) - }?; - - unsafe { - let _ = git_source.as_mut().unwrap().lock.insert(commit_id); - } - - Ok::<(), anyhow::Error>(()) - })?; + should_update_gits + .into_iter() + .try_for_each(|git_source| unsafe { git_source.as_mut().unwrap().update() })?; Ok(()) })