aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mingling_ci/src/cmd.rs1
-rw-r--r--mingling_ci/src/cmd/cmd_report_clean.rs54
-rw-r--r--mingling_ci/src/cmd/cmd_report_collect.rs5
-rw-r--r--mingling_ci/src/reporter.rs3
4 files changed, 60 insertions, 3 deletions
diff --git a/mingling_ci/src/cmd.rs b/mingling_ci/src/cmd.rs
index 45b077e..471a7af 100644
--- a/mingling_ci/src/cmd.rs
+++ b/mingling_ci/src/cmd.rs
@@ -1,2 +1,3 @@
+pub(crate) mod cmd_report_clean;
pub(crate) mod cmd_report_collect;
pub(crate) mod cmd_show_manifests;
diff --git a/mingling_ci/src/cmd/cmd_report_clean.rs b/mingling_ci/src/cmd/cmd_report_clean.rs
new file mode 100644
index 0000000..976851e
--- /dev/null
+++ b/mingling_ci/src/cmd/cmd_report_clean.rs
@@ -0,0 +1,54 @@
+use std::path::PathBuf;
+
+use mingling::{
+ Grouped, RenderResult, Routable,
+ macros::{buffer, command, r_println, renderer},
+};
+
+use crate::Next;
+use crate::reporter::{COLLECT_DIR, REPORT_PATH};
+use crate::res::{CargoError, MessagePrinter};
+
+/// Removes collected logs and the generated report.
+#[command(node = "report-clean")]
+pub fn report_clean() -> Next {
+ let mut removed = Vec::new();
+ for path in [PathBuf::from(COLLECT_DIR), PathBuf::from(REPORT_PATH)] {
+ match std::fs::remove_dir_all(&path).or_else(|_| std::fs::remove_file(&path)) {
+ Ok(()) => removed.push(path),
+ Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
+ Err(e) => {
+ return ErrorReportClean(format!("failed to remove {}: {e}", path.display()))
+ .to_chain();
+ }
+ }
+ }
+ ResultReportClean { removed }.to_chain()
+}
+
+/// Paths removed by `report-clean`.
+#[derive(Grouped)]
+pub struct ResultReportClean {
+ pub removed: Vec<PathBuf>,
+}
+
+#[derive(Grouped, Default)]
+pub struct ErrorReportClean(pub String);
+
+#[renderer(buffer)]
+pub fn render_report_clean(r: ResultReportClean) {
+ if r.removed.is_empty() {
+ r_println!("Report data already clean");
+ } else {
+ for path in r.removed {
+ r_println!("Removed {}", path.display());
+ }
+ }
+}
+
+#[renderer]
+pub fn render_error_report_clean(e: ErrorReportClean, error: &CargoError) -> RenderResult {
+ let render_result = RenderResult::new();
+ error.println(vec![format!("Report: {}", e.0)]);
+ render_result
+}
diff --git a/mingling_ci/src/cmd/cmd_report_collect.rs b/mingling_ci/src/cmd/cmd_report_collect.rs
index bb944b3..3cebaef 100644
--- a/mingling_ci/src/cmd/cmd_report_collect.rs
+++ b/mingling_ci/src/cmd/cmd_report_collect.rs
@@ -8,10 +8,9 @@ use mingling::{
};
use crate::Next;
-use crate::reporter::COLLECT_DIR;
+use crate::reporter::{COLLECT_DIR, REPORT_PATH};
use crate::res::{CargoError, Manifests, MessagePrinter, ResCollectLogs};
-const OUTPUT_PATH: &str = "./.temp/reports/result.md";
const REPORT_TEMPLATE: &str = include_str!("../../tmpls/report.md");
const TASK_SECTION_TEMPLATE: &str = include_str!("../../tmpls/task_section.md");
@@ -93,7 +92,7 @@ pub fn report_collect(manifests: &Manifests, logs: &ResCollectLogs) -> Next {
*template.add_impl("task_sections".to_string()) = sections;
let expanded = template.expand().unwrap_or_default();
- let output = PathBuf::from(OUTPUT_PATH);
+ let output = PathBuf::from(REPORT_PATH);
let parent = output.parent().expect("output path has a parent");
if let Err(e) = std::fs::create_dir_all(parent).and_then(|()| std::fs::write(&output, expanded))
diff --git a/mingling_ci/src/reporter.rs b/mingling_ci/src/reporter.rs
index a3619e7..f5cef60 100644
--- a/mingling_ci/src/reporter.rs
+++ b/mingling_ci/src/reporter.rs
@@ -11,6 +11,9 @@ use std::sync::Mutex;
/// Root of the collected CI logs (relative to the repo root).
pub const COLLECT_DIR: &str = "./.temp/reports/collect";
+/// Generated report output (relative to the repo root).
+pub const REPORT_PATH: &str = "./.temp/reports/result.md";
+
/// The platform a package check ran on.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ReportPlatform {