mirror of
https://seed.radicle.dev/rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE.git
synced 2026-11-15 16:00:39 +08:00
This lets me see the core logic easier. Signed-off-by: Lars Wirzenius <liw@liw.fi>
42 lines
1.2 KiB
Rust
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),
|
|
}
|