Skip to content

Commit

Permalink
feat: update worksapce idl (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
LYF1999 authored Aug 15, 2023
1 parent fad8d4e commit 815ccdf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion volo-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 22 additions & 0 deletions volo-build/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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
}
Expand All @@ -61,6 +72,17 @@ pub struct GitSource {
pub lock: Option<String>,
}

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()
Expand Down
6 changes: 6 additions & 0 deletions volo-build/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ pub struct WorkspaceConfig {
pub(crate) services: Vec<Service>,
}

impl WorkspaceConfig {
pub fn update_idls(&mut self) -> anyhow::Result<()> {
self.services.iter_mut().try_for_each(|s| s.idl.update())
}
}

impl<MkB, P> Builder<MkB, P>
where
MkB: pilota_build::MakeBackend + Send,
Expand Down
2 changes: 1 addition & 1 deletion volo-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 4 additions & 23 deletions volo-cli/src/idl/update.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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(())
})
Expand Down

0 comments on commit 815ccdf

Please sign in to comment.