use std::path::{Path, PathBuf};
pub const METADATA_JSON: &str = "metadata.json";
pub const ARTIFACTS_JSON: &str = "artifacts.json";
pub const CONTEXT_JSON: &str = "context.json";
pub const REPORT_JSON: &str = "report.json";
pub const ROLLBACK_JSON: &str = "rollback.json";
pub const SUMMARY_JSON: &str = "summary.json";
pub const CONFIG_YAML: &str = "config.yaml";
pub const RELEASE_NOTES_MD: &str = "release-notes.md";
pub const MATRIX_JSON: &str = "matrix.json";
pub const RUN_DIR_PREFIX: &str = "run-";
pub fn layout_roots(dist: &Path) -> Vec<PathBuf> {
let mut roots = vec![dist.to_path_buf()];
if let Ok(entries) = std::fs::read_dir(dist) {
let mut subdirs: Vec<PathBuf> = entries
.flatten()
.map(|e| e.path())
.filter(|p| p.is_dir())
.collect();
subdirs.sort();
roots.extend(subdirs);
}
roots
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sidecar_basenames_are_stable() {
assert_eq!(METADATA_JSON, "metadata.json");
assert_eq!(ARTIFACTS_JSON, "artifacts.json");
assert_eq!(CONTEXT_JSON, "context.json");
assert_eq!(REPORT_JSON, "report.json");
assert_eq!(ROLLBACK_JSON, "rollback.json");
assert_eq!(SUMMARY_JSON, "summary.json");
assert_eq!(RUN_DIR_PREFIX, "run-");
}
#[test]
fn layout_roots_lists_the_root_then_sorted_subdirs() {
let tmp = tempfile::tempdir().expect("tempdir for dist layout");
for name in ["zeta", "alpha", "mid"] {
std::fs::create_dir(tmp.path().join(name)).expect("create crate subdir");
}
std::fs::write(tmp.path().join(ARTIFACTS_JSON), "[]").expect("write a sidecar file");
assert_eq!(
layout_roots(tmp.path()),
vec![
tmp.path().to_path_buf(),
tmp.path().join("alpha"),
tmp.path().join("mid"),
tmp.path().join("zeta"),
]
);
}
}