Skip to content

Commit

Permalink
feat: support view log for every build
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash committed Nov 28, 2024
1 parent 457a558 commit a815475
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 112 deletions.
2 changes: 2 additions & 0 deletions src/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ pub struct ExecuteResult {
pub status: Status,
pub start_time: String,
pub elapsed: u64,
pub stdout: String,
pub stderr: String,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
54 changes: 40 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,38 @@ pub enum RunMoonError {
FromUtf8(#[from] std::string::FromUtf8Error),
}

#[derive(Debug)]
struct CommandOutput {
duration: Duration,
stdout: String,
stderr: String,
success: bool,
}

fn run_moon(
workdir: &Path,
source: &MooncakeSource,
args: &[&str],
) -> Result<Duration, RunMoonError> {
) -> Result<CommandOutput, RunMoonError> {
let start = Instant::now();
eprintln!(
"{}",
format!("RUN moon {} for {:?}", args.join(" "), source)
.blue()
.bold()
);
let mut cmd = std::process::Command::new("moon")

let output = std::process::Command::new("moon")
.current_dir(workdir)
.args(args)
.spawn()
.output()
.map_err(|e| RunMoonError::IOError(e))?;
let exit = cmd.wait().map_err(|e| RunMoonError::IOError(e))?;
if !exit.success() {
return Err(RunMoonError::ReturnNonZero(exit));
}

let stdout = String::from_utf8_lossy(&output.stdout).into_owned();
let stderr = String::from_utf8_lossy(&output.stderr).into_owned();

let elapsed = start.elapsed();

eprintln!(
"{}",
format!(
Expand All @@ -66,7 +76,13 @@ fn run_moon(
.green()
.bold()
);
Ok(elapsed)

Ok(CommandOutput {
duration: elapsed,
stdout,
stderr,
success: output.status.success(),
})
}

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -181,21 +197,31 @@ fn stat_mooncake(
let _ = run_moon(workdir, source, &["clean"]);

let r = run_moon(workdir, source, &cmd.args()).map_err(|e| StatMooncakeError::RunMoon(e));
let status = if r.is_err() {
Status::Failure
} else {
Status::Success
let status = match r.as_ref() {
Ok(output) if output.success => Status::Success,
_ => Status::Failure,
};
let d = r.ok();
let output = r.ok();
let start_time = Local::now()
.with_timezone(&FixedOffset::east_opt(8 * 3600).unwrap())
.format("%Y-%m-%d %H:%M:%S.%3f")
.to_string();
let elapsed = d.map(|d| d.as_millis() as u64).unwrap_or(0);
let elapsed = output
.as_ref()
.map(|d| d.duration.as_millis() as u64)
.unwrap_or(0);
let execute_result = ExecuteResult {
status,
start_time,
elapsed,
stdout: output
.as_ref()
.map(|d| d.stdout.clone())
.unwrap_or_default(),
stderr: output
.as_ref()
.map(|d| d.stderr.clone())
.unwrap_or_default(),
};
Ok(execute_result)
}
Expand Down
3 changes: 2 additions & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.1",
"vite": "^5.4.1"
}
},
"packageManager": "[email protected]+sha256.dbdf5961c32909fb030595a9daa1dae720162e658609a8f92f2fa99835510ca5"
}
Loading

0 comments on commit a815475

Please sign in to comment.