Files
radicle-native-ci/src/runspec.rs
T
Lars Wirzenius bc7ffbad0f refactor: split one Rust main module into many small module
This lets me see the core logic easier.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-01-10 17:38:05 +02:00

42 lines
1.2 KiB
Rust

use std::path::{Path, PathBuf};
use log::{debug, error};
use serde::Deserialize;
use crate::logfile::LogError;
/// How to run CI for this repository.
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
#[allow(dead_code)]
pub struct RunSpec {
/// The shell script snippet to run. It will be run with `bash`
/// and with `set -xeuo pipefail`.
pub shell: String,
}
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)
}
}
#[derive(Debug, thiserror::Error)]
pub enum RunSpecError {
#[error("failed to read run specification file {0}")]
ReadRunSpec(PathBuf, #[source] std::io::Error),
#[error("failed to parse run spec as YAML: {0}")]
ParseRunSpec(PathBuf, #[source] serde_yaml::Error),
#[error(transparent)]
Log(#[from] LogError),
}