-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
save report file every time cryo is run
- Loading branch information
Showing
15 changed files
with
183 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::process::Command; | ||
|
||
fn main() { | ||
// Run `git describe --tags --always` | ||
let output = | ||
Command::new("git").args(["describe", "--tags", "--always"]).output().unwrap_or_else(|e| { | ||
panic!("Failed to execute git command: {}", e); | ||
}); | ||
|
||
if output.status.success() { | ||
let git_description = String::from_utf8(output.stdout) | ||
.unwrap_or_else(|e| { | ||
panic!("Failed to read git command output: {}", e); | ||
}) | ||
.trim() | ||
.to_string(); | ||
|
||
println!("cargo:rustc-env=GIT_DESCRIPTION={}", git_description); | ||
} else { | ||
println!("cargo:warning=Could not determine git description"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
mod args; | ||
mod parse; | ||
mod reports; | ||
mod run; | ||
mod summaries; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ use clap_cryo::Parser; | |
|
||
mod args; | ||
mod parse; | ||
mod reports; | ||
mod run; | ||
mod summaries; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::args; | ||
use chrono::{DateTime, Local}; | ||
use cryo_freeze::{FreezeError, FreezeSummary}; | ||
use std::{fs::File, io::Write, path::Path, time::SystemTime}; | ||
|
||
#[derive(serde::Serialize, Debug)] | ||
struct FreezeReport<'a> { | ||
cryo_version: String, | ||
// node_client: String, | ||
cli_command: Vec<String>, | ||
args: &'a args::Args, | ||
chunk_summary: Option<&'a FreezeSummary>, | ||
} | ||
|
||
pub(crate) fn get_report_path( | ||
args: &args::Args, | ||
t_start: SystemTime, | ||
is_complete: bool, | ||
) -> Result<String, FreezeError> { | ||
let report_dir = match &args.report_dir { | ||
Some(report_dir) => Path::new(&report_dir).into(), | ||
None => Path::new(&args.output_dir).join(".cryo_reports"), | ||
}; | ||
std::fs::create_dir_all(&report_dir)?; | ||
let t_start: DateTime<Local> = t_start.into(); | ||
let timestamp: String = t_start.format("%Y-%m-%d_%H-%M-%S").to_string(); | ||
let filename = if is_complete { | ||
timestamp + ".json" | ||
} else { | ||
format!("incomplete_{}", timestamp + ".json") | ||
}; | ||
let path = report_dir.join(filename); | ||
path.to_str() | ||
.ok_or(FreezeError::GeneralError("non-String path".to_string())) | ||
.map(|s| s.to_string()) | ||
} | ||
|
||
pub(crate) fn write_report( | ||
args: &args::Args, | ||
freeze_summary: Option<&FreezeSummary>, | ||
t_start: SystemTime, | ||
) -> Result<String, FreezeError> { | ||
// determine version | ||
let cryo_version = format!("{}__{}", env!("CARGO_PKG_VERSION"), env!("GIT_DESCRIPTION")); | ||
let report = FreezeReport { | ||
cryo_version, | ||
cli_command: std::env::args().collect(), | ||
args, | ||
chunk_summary: freeze_summary, | ||
}; | ||
let serialized = serde_json::to_string(&report)?; | ||
|
||
// create path | ||
let path = get_report_path(args, t_start, freeze_summary.is_some())?; | ||
|
||
// save to file | ||
let mut file = File::create(&path)?; | ||
file.write_all(serialized.as_bytes())?; | ||
|
||
Ok(path) | ||
} |
Oops, something went wrong.