mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Factor vergen stuff to a build-info crate
This commit is contained in:
parent
86ce843f3d
commit
c608b3f9b5
15 changed files with 396 additions and 159 deletions
|
@ -1,58 +1,4 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use time::OffsetDateTime;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Source {
|
||||
pub repo_url: Option<String>,
|
||||
pub branch_or_tag: String,
|
||||
pub commit_id: String,
|
||||
pub commit_msg: String,
|
||||
pub author_name: String,
|
||||
pub author_email: String,
|
||||
pub committer_name: String,
|
||||
pub committer_email: String,
|
||||
}
|
||||
|
||||
impl Source {
|
||||
pub fn from_repo(
|
||||
path: impl AsRef<std::path::Path>,
|
||||
) -> Result<(Self, OffsetDateTime), git2::Error> {
|
||||
use git2::Repository;
|
||||
|
||||
let repo = Repository::open(path)?;
|
||||
let remote = repo.remotes()?;
|
||||
let remote = remote.get(0).expect("No remote associated to the repo");
|
||||
let remote = repo.find_remote(remote)?;
|
||||
|
||||
let head = repo.head()?;
|
||||
|
||||
let commit = head.peel_to_commit()?;
|
||||
|
||||
let time = OffsetDateTime::from_unix_timestamp(commit.time().seconds()).unwrap();
|
||||
|
||||
let author = commit.author();
|
||||
let committer = commit.committer();
|
||||
|
||||
Ok((
|
||||
Self {
|
||||
repo_url: remote.url().map(|s| s.to_string()),
|
||||
branch_or_tag: head.name().unwrap().to_string(),
|
||||
commit_id: commit.id().to_string(),
|
||||
commit_msg: String::from_utf8_lossy(commit.message_bytes())
|
||||
.to_string()
|
||||
.lines()
|
||||
.next()
|
||||
.map_or(String::new(), |s| s.to_string()),
|
||||
author_name: author.name().unwrap().to_string(),
|
||||
author_email: author.email().unwrap().to_string(),
|
||||
committer_name: committer.name().unwrap().to_string(),
|
||||
committer_email: committer.email().unwrap().to_string(),
|
||||
},
|
||||
time,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
|
|
@ -292,8 +292,7 @@ pub fn run(args: BenchDeriveArgs) -> anyhow::Result<()> {
|
|||
args.log_filter.parse().context("invalid --log-filter")?;
|
||||
|
||||
let env = env_info::Environment::generate_from_current_config();
|
||||
let (source, commit_date) =
|
||||
env_info::Source::from_repo(".").context("could not get repository information")?;
|
||||
let build_info = build_info::BuildInfo::from_build();
|
||||
|
||||
let subscriber = tracing_subscriber::registry().with(
|
||||
tracing_subscriber::fmt::layer()
|
||||
|
@ -344,17 +343,18 @@ pub fn run(args: BenchDeriveArgs) -> anyhow::Result<()> {
|
|||
);
|
||||
}
|
||||
|
||||
let commit_message = source.commit_msg.split('\n').next().unwrap();
|
||||
let commit_message = build_info.commit_msg.context("missing commit message")?.split('\n').next().unwrap();
|
||||
let max_workloads = args.workload_file.len();
|
||||
let reason: Option<&str> = args.reason.as_deref();
|
||||
let response = dashboard_client
|
||||
.put("invocation")
|
||||
.json(&json!({
|
||||
"commit": {
|
||||
"sha1": source.commit_id,
|
||||
"sha1": build_info.commit_sha1,
|
||||
"message": commit_message,
|
||||
"commit_date": commit_date,
|
||||
"branch": source.branch_or_tag
|
||||
"commit_date": build_info.commit_timestamp,
|
||||
"branch": build_info.branch,
|
||||
"tag": build_info.describe.and_then(|describe| describe.as_tag()),
|
||||
},
|
||||
"machine_hostname": env.hostname,
|
||||
"max_workloads": max_workloads,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue