Skip to content

Commit

Permalink
fix: set current directory properly and switch to stable branch first
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed May 7, 2024
1 parent 26cadf0 commit 7b4e702
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
49 changes: 39 additions & 10 deletions buildit-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::{
use anyhow::{bail, Context};
use walkdir::WalkDir;

use crate::github::update_abbs;

pub mod github;

pub const AMD64: &str = "AMD64 `amd64`";
Expand Down Expand Up @@ -35,15 +37,23 @@ pub struct FindUpdate {
pub title: String,
}

pub fn find_update_and_update_checksum(pkg: &str, abbs_path: &Path) -> anyhow::Result<FindUpdate> {
pub async fn find_update_and_update_checksum(
pkg: &str,
abbs_path: &Path,
) -> anyhow::Result<FindUpdate> {
// switch to stable branch
update_abbs("stable", &abbs_path).await?;

Command::new("aosc-findupdate")
.arg("-i")
.arg(format!("^{pkg}$"))
.current_dir(&abbs_path)
.output()?;

let status = Command::new("git")
.arg("status")
.arg("--porcelain")
.current_dir(&abbs_path)
.output()?;

let status = BufReader::new(&*status.stdout).lines().flatten().next();
Expand All @@ -62,11 +72,9 @@ pub fn find_update_and_update_checksum(pkg: &str, abbs_path: &Path) -> anyhow::R
.arg("acbs-build")
.arg("-gw")
.arg(pkg)
.current_dir(&abbs_path)
.output()?;

let path = std::env::current_dir()?;
std::env::set_current_dir(abbs_path)?;

let mut ver = None;

for i in WalkDir::new(".").max_depth(3).min_depth(3) {
Expand All @@ -78,7 +86,9 @@ pub fn find_update_and_update_checksum(pkg: &str, abbs_path: &Path) -> anyhow::R
.flatten()
.next()
.context(format!("Failed to open file: {}", i.path().display()))?;
let (_, v) = line.split_once('=').context(format!("Failed to open file: {}", i.path().display()))?;
let (_, v) = line
.split_once('=')
.context(format!("Failed to open file: {}", i.path().display()))?;
ver = Some(v.trim().to_string());
}
}
Expand All @@ -87,17 +97,36 @@ pub fn find_update_and_update_checksum(pkg: &str, abbs_path: &Path) -> anyhow::R
let branch = format!("{pkg}-{ver}");
let title = format!("{pkg}: update to {ver}");

Command::new("git").arg("checkout").arg("-b").arg(&branch).output()?;
Command::new("git").arg("add").arg(".").output()?;
Command::new("git")
.arg("checkout")
.arg("-b")
.arg(&branch)
.current_dir(&abbs_path)
.output()?;
Command::new("git")
.arg("add")
.arg(".")
.current_dir(&abbs_path)
.output()?;
Command::new("git")
.arg("commit")
.arg("-m")
.arg(&title)
.current_dir(&abbs_path)
.output()?;
Command::new("git")
.arg("push")
.arg("--set-upstream")
.arg("origin")
.arg(&branch)
.current_dir(&abbs_path)
.output()?;
Command::new("git").arg("push").arg("--set-upstream").arg("origin").arg(&branch).output()?;
std::env::set_current_dir(path)?;

return Ok(FindUpdate { package: pkg.to_string(), branch, title });
return Ok(FindUpdate {
package: pkg.to_string(),
branch,
title,
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ pub async fn answer(bot: Bot, msg: Message, cmd: Command, pool: DbPool) -> Respo
}
};

match find_update_and_update_checksum(&package, &ARGS.abbs_path) {
match find_update_and_update_checksum(&package, &ARGS.abbs_path).await {
Ok(f) => {
match buildit_utils::github::open_pr(
app_private_key,
Expand Down

0 comments on commit 7b4e702

Please sign in to comment.