Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
feat! drop the env logging
Lars Wirzenius committed 2 years ago
commit 3a20cb66e627478ed42d6c4c181b81c522b6a35f
parent 9225ef0
8 files changed +3 -35
modified Cargo.lock
@@ -1090,8 +1090,6 @@ name = "radicle-native-ci"
version = "0.1.0"
dependencies = [
 "html-page",
-
 "log",
-
 "pretty_env_logger",
 "radicle",
 "radicle-ci-broker",
 "radicle-git-ext",
modified Cargo.toml
@@ -6,8 +6,6 @@ default-run = "radicle-native-ci"

[dependencies]
html-page = "0.1.0"
-
log = "0.4.20"
-
pretty_env_logger = "0.5.0"
radicle-git-ext = "0.7.0"
serde = { version = "1.0.193", features = ["derive"] }
serde_yaml = "0.9.27"
modified src/bin/radicle-native-ci.rs
@@ -17,7 +17,6 @@ use std::{
    path::{Path, PathBuf},
};

-
use log::{debug, error, info};
use uuid::Uuid;

use radicle::prelude::Profile;
@@ -52,9 +51,6 @@ fn main() {
}

fn fallible_main() -> Result<(), NativeError> {
-
    pretty_env_logger::init_custom_env("RADICLE_NATIVE_CI_LOG");
-
    info!("radicle-native-ci starts");
-

    let config = Config::load_via_env()?;
    let mut logfile = config.open_log()?;

@@ -99,8 +95,9 @@ fn fallible_main_inner(
    builder.log(&config.state, run_log.clone());
    builder.run_info(run_info_file.clone());

+
    let run_log = RunLog::new(&run_log);
+

    if let Request::Trigger { repo, commit } = req {
-
        info!("Request to trigger CI on {}, {}", repo, commit);
        builder.repo(repo);
        builder.commit(commit);
        let mut runner = RunnerBuilder::default()
@@ -110,13 +107,12 @@ fn fallible_main_inner(
            .commit(commit)
            .src(&src)
            .log(logfile)
-
            .run_log(&run_log)
+
            .run_log(run_log)
            .timeout(config.timeout)
            .builder(builder)
            .build()?;
        let result = runner.run();
        if let Err(e) = result {
-
            error!("CI run failed: {}", e);
            logfile.writeln(&format!("CI failed: {:?}", e))?;
            builder.result(RunResult::Failure);
            return Err(e);
@@ -128,7 +124,6 @@ fn fallible_main_inner(
    };

    logfile.writeln("radicle-native-ci ends successfully")?;
-
    info!("radicle-native-ci ends");
    Ok(())
}

@@ -136,13 +131,11 @@ fn fallible_main_inner(
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))
}
@@ -162,7 +155,6 @@ struct Runner<'a> {

impl<'a> Runner<'a> {
    fn git_clone(&mut self, repo_path: &Path) -> Result<(), NativeError> {
-
        debug!("cloning repository to {}", self.src.display());
        self.log.writeln("clone repository")?;
        runcmd(
            &mut self.run_log,
@@ -178,7 +170,6 @@ impl<'a> Runner<'a> {
    }

    fn git_checkout(&mut self) -> Result<(), NativeError> {
-
        debug!("checking out commit {}", self.commit);
        self.log.writeln("check out commit")?;
        runcmd(
            &mut self.run_log,
@@ -200,7 +191,6 @@ impl<'a> Runner<'a> {
        write_triggered(&self.run_id)?;

        let repo_path = self.storage.join(self.repo.canonical());
-
        debug!("repo path: {}", repo_path.display());

        self.git_clone(&repo_path)?;
        self.git_checkout()?;
@@ -208,7 +198,6 @@ impl<'a> Runner<'a> {
        let runspec = RunSpec::from_file(&self.src.join(RUNSPEC_PATH))?;
        self.log.writeln(&format!("CI run spec: {:#?}", runspec))?;

-
        debug!("running CI in cloned repository");
        self.log.writeln("run shell snippet in repository")?;
        let snippet = format!("set -xeuo pipefail\n{}", &runspec.shell);
        if let Some(timeout) = self.timeout {
modified src/config.rs
@@ -1,6 +1,5 @@
use std::path::{Path, PathBuf};

-
use log::{debug, error};
use serde::Deserialize;

use crate::logfile::{LogError, LogFile};
@@ -28,7 +27,6 @@ impl Config {
        let filename = std::env::var(ENV).map_err(|e| ConfigError::GetEnv(ENV, e))?;
        let filename = Path::new(&filename);
        let config = Config::read(filename)?;
-
        debug!("configuration from {}: {:#?}", filename.display(), config);
        Ok(config)
    }

modified src/msg.rs
@@ -1,7 +1,5 @@
use std::path::PathBuf;

-
use log::{debug, error};
-

use radicle_ci_broker::msg::{MessageError, Request, Response, RunId};

use crate::{
@@ -12,7 +10,6 @@ use crate::{
/// Read a request from stdin.
pub fn read_request() -> Result<Request, NativeMessageError> {
    let req = Request::from_reader(std::io::stdin()).map_err(NativeMessageError::ReadRequest)?;
-
    debug!("request: {:#?}", req);
    Ok(req)
}

modified src/runcmd.rs
@@ -1,16 +1,11 @@
use std::{path::Path, process::Command};

-
use log::{debug, error};
-

use radicle_ci_broker::msg::{MessageError, Response};

use crate::runlog::{RunLog, RunLogError};

/// Run a command in a directory.
pub fn runcmd(run_log: &mut RunLog, argv: &[&str], cwd: &Path) -> Result<(), RunCmdError> {
-
    debug!("runcmd: argv={:?}", argv);
-
    debug!("runcmd: cwd={:?}", cwd);
-

    assert!(!argv.is_empty());
    let argv0 = argv[0];
    let output = Command::new(argv0)
@@ -18,10 +13,8 @@ pub fn runcmd(run_log: &mut RunLog, argv: &[&str], cwd: &Path) -> Result<(), Run
        .current_dir(cwd)
        .output()
        .map_err(|e| RunCmdError::Command(argv.iter().map(|s| s.to_string()).collect(), e))?;
-
    debug!("{:#?}", output);

    let exit = output.status;
-
    debug!("exit: {:?}", exit);

    run_log.runcmd(
        argv,
modified src/runinfo.rs
@@ -1,6 +1,5 @@
use std::path::{Path, PathBuf};

-
use log::{error, info};
use serde::{Deserialize, Serialize};
use time::{macros::format_description, OffsetDateTime};

@@ -42,7 +41,6 @@ impl RunInfo {

    pub fn write(&self) -> Result<(), RunInfoError> {
        if let Some(filename) = &self.run_info {
-
            info!("Writing run info to {}", filename.display());
            let yaml = serde_yaml::to_string(&self).map_err(RunInfoError::SerializeRunInfo)?;
            std::fs::write(filename, yaml.as_bytes())
                .map_err(|e| RunInfoError::WriteRunInfo(filename.into(), e))?;
modified src/runspec.rs
@@ -1,6 +1,5 @@
use std::path::{Path, PathBuf};

-
use log::{debug, error};
use serde::Deserialize;

use crate::logfile::LogError;
@@ -18,12 +17,10 @@ pub struct RunSpec {
impl RunSpec {
    /// Read run specification from a file.
    pub fn from_file(filename: &Path) -> Result<Self, RunSpecError> {
-
        debug!("loading CI run spec from {}", filename.display());
        let file = std::fs::File::open(filename)
            .map_err(|e| RunSpecError::ReadRunSpec(filename.into(), e))?;
        let runspec: RunSpec = serde_yaml::from_reader(&file)
            .map_err(|e| RunSpecError::ParseRunSpec(filename.into(), e))?;
-
        debug!("runspec: {:#?}", runspec);
        Ok(runspec)
    }
}