Skip to main content

radicle_native_ci/
runspec.rs

1use std::path::{Path, PathBuf};
2
3use serde::{Deserialize, Serialize};
4
5use crate::logfile::LogError;
6
7/// How to run CI for this repository.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(deny_unknown_fields)]
10#[allow(dead_code)]
11pub struct RunSpec {
12    /// The shell script snippet to run. It will be run with `bash`
13    /// and with `set -xeuo pipefail`.
14    pub shell: String,
15}
16
17impl RunSpec {
18    /// Read run specification from a file.
19    pub fn from_file(filename: &Path) -> Result<Self, RunSpecError> {
20        let file = std::fs::File::open(filename)
21            .map_err(|e| RunSpecError::ReadRunSpec(filename.into(), e))?;
22        let runspec: RunSpec = serde_norway::from_reader(&file)
23            .map_err(|e| RunSpecError::ParseRunSpec(filename.into(), e))?;
24        Ok(runspec)
25    }
26}
27
28#[derive(Debug, thiserror::Error)]
29pub enum RunSpecError {
30    #[error("failed to read run specification file {0}")]
31    ReadRunSpec(PathBuf, #[source] std::io::Error),
32
33    #[error("failed to parse run spec as YAML: {0}")]
34    ParseRunSpec(PathBuf, #[source] serde_norway::Error),
35
36    #[error(transparent)]
37    Log(#[from] LogError),
38}