Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
refactor: more per-run directory creation into helper funciont
Lars Wirzenius committed 2 years ago
commit b7115d85c445023551658294e84e90c786010731
parent 54c3979
1 file changed +16 -11
modified src/main.rs
@@ -50,17 +50,7 @@ fn fallible_main() -> Result<(), NativeError> {
    info!("radicle-native-ci starts");

    let config = Config::load_via_env()?;
-

-
    let state = &config.state;
-
    if !state.exists() {
-
        debug!("creating {}", state.display());
-
        std::fs::create_dir_all(state).map_err(|e| NativeError::CreateState(state.into(), e))?;
-
    }
-

-
    let run_id = Uuid::new_v4();
-
    let run_dir = state.join(run_id.to_string());
-
    debug!("directory for this run: {}", run_dir.display());
-
    std::fs::create_dir(&run_dir).map_err(|e| NativeError::CreateRunDir(run_dir.clone(), e))?;
+
    let (run_id, run_dir) = mkdir_run(&config)?;

    let src = run_dir.join("src");
    let log = run_dir.join("log");
@@ -85,6 +75,21 @@ fn fallible_main() -> Result<(), NativeError> {
    Ok(())
}

+
/// Create a per-run directory.
+
fn mkdir_run(config: &Config) -> Result<(Uuid, PathBuf), NativeError> {
+
    let state = &config.state;
+
    if !state.exists() {
+
        debug!("creating state directory {}", state.display());
+
        std::fs::create_dir_all(state).map_err(|e| NativeError::CreateState(state.into(), e))?;
+
    }
+

+
    let run_id = Uuid::new_v4();
+
    let run_dir = state.join(run_id.to_string());
+
    debug!("directory for this run: {}", run_dir.display());
+
    std::fs::create_dir(&run_dir).map_err(|e| NativeError::CreateRunDir(run_dir.clone(), e))?;
+
    Ok((run_id, run_dir))
+
}
+

/// Perform the CI run.
fn run(
    run_id: Uuid,