Skip to content

Commit

Permalink
feat: skip duplicated git fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Jun 12, 2024
1 parent aaa5c44 commit 6381e06
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
38 changes: 23 additions & 15 deletions buildit-utils/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub async fn open_pr(
archs,
} = openpr_request;

update_abbs(&git_ref, &abbs_path).await?;
update_abbs(&git_ref, &abbs_path, false).await?;

let abbs_path_clone = abbs_path.clone();
let commits = task::spawn_blocking(move || get_commits(&abbs_path_clone))
Expand Down Expand Up @@ -304,7 +304,11 @@ fn get_commits(path: &Path) -> anyhow::Result<Vec<Commit>> {

/// Update ABBS tree commit logs
#[tracing::instrument(skip(abbs_path))]
pub async fn update_abbs<P: AsRef<Path>>(git_ref: &str, abbs_path: P) -> anyhow::Result<()> {
pub async fn update_abbs<P: AsRef<Path>>(
git_ref: &str,
abbs_path: P,
skip_git_fetch: bool,
) -> anyhow::Result<()> {
info!("Running git checkout -b stable ...");

let abbs_path = abbs_path.as_ref();
Expand Down Expand Up @@ -332,21 +336,25 @@ pub async fn update_abbs<P: AsRef<Path>>(git_ref: &str, abbs_path: P) -> anyhow:

print_stdout_and_stderr(&output);

info!("Running git fetch origin {git_ref} ...");

let output = process::Command::new("git")
.arg("fetch")
.arg("origin")
.arg(git_ref)
.current_dir(abbs_path)
.output()
.instrument(info_span!("git_fetch_origin"))
.await?;
if skip_git_fetch {
info!("Skippping git fetch ...")
} else {
info!("Running git fetch origin {git_ref} ...");

let output = process::Command::new("git")
.arg("fetch")
.arg("origin")
.arg(git_ref)
.current_dir(abbs_path)
.output()
.instrument(info_span!("git_fetch_origin"))
.await?;

print_stdout_and_stderr(&output);
print_stdout_and_stderr(&output);

if !output.status.success() {
bail!("Failed to fetch origin git-ref: {git_ref}");
if !output.status.success() {
bail!("Failed to fetch origin git-ref: {git_ref}");
}
}

info!("Running git reset origin/stable --hard ...");
Expand Down
2 changes: 1 addition & 1 deletion buildit-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub async fn find_update_and_update_checksum(
let _lock = ABBS_REPO_LOCK.lock().await;

// switch to stable branch
update_abbs("stable", &abbs_path).await?;
update_abbs("stable", &abbs_path, false).await?;

info!("Running aosc-findupdate ...");

Expand Down
10 changes: 7 additions & 3 deletions server/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
github::{get_crab_github_installation, get_packages_from_pr},
models::{Job, NewJob, NewPipeline, Pipeline, User, Worker},
schema::jobs::github_check_run_id,
DbPool, ALL_ARCH, ARGS,
};
use anyhow::Context;
Expand Down Expand Up @@ -60,6 +59,7 @@ pub async fn pipeline_new(
packages: &str,
archs: &str,
source: &JobSource,
skip_git_fetch: bool,
) -> anyhow::Result<Pipeline> {
// sanitize archs arg
let mut archs: Vec<&str> = archs.split(',').collect();
Expand Down Expand Up @@ -103,7 +103,7 @@ pub async fn pipeline_new(
}

let lock = ABBS_REPO_LOCK.lock().await;
update_abbs(git_branch, &ARGS.abbs_path)
update_abbs(git_branch, &ARGS.abbs_path, skip_git_fetch)
.await
.context("Failed to update ABBS tree")?;

Expand Down Expand Up @@ -267,15 +267,18 @@ pub async fn pipeline_new_pr(
// find lines starting with #buildit
let packages = get_packages_from_pr(&pr);
if !packages.is_empty() {
let mut skip_git_fetch = false;
let archs = if let Some(archs) = archs {
archs.to_string()
} else {
let path = &ARGS.abbs_path;

let _lock = ABBS_REPO_LOCK.lock().await;
update_abbs(git_branch, &ARGS.abbs_path)
update_abbs(git_branch, &ARGS.abbs_path, false)
.await
.context("Failed to update ABBS tree")?;
// skip next git fetch in pipeline_new
skip_git_fetch = true;

let resolved_packages =
resolve_packages(&packages, path).context("Failed to resolve packages")?;
Expand All @@ -291,6 +294,7 @@ pub async fn pipeline_new_pr(
&packages.join(","),
&archs,
source,
skip_git_fetch,
)
.await
} else {
Expand Down
1 change: 1 addition & 0 deletions server/src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ async fn pipeline_new_and_report(
packages,
archs,
&JobSource::Telegram(msg.chat.id.0),
false,
)
.await
{
Expand Down
1 change: 1 addition & 0 deletions server/src/routes/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub async fn pipeline_new(
&payload.packages,
&payload.archs,
&JobSource::Manual,
false,
)
.await?;
Ok(Json(PipelineNewResponse { id: pipeline.id }))
Expand Down

0 comments on commit 6381e06

Please sign in to comment.