Skip to main content

quanttide_devops/contract/
mod.rs

1/// 契约模型四维架构:Stages / Platforms / Sources / Scopes。
2///
3/// 参考:<https://github.com/quanttide/quanttide-essay-of-devops/blob/main/contract/index.md>
4pub mod error;
5pub mod model;
6
7pub use error::ContractError;
8pub use model::{
9    BuildTool, Contract, Language, Pipeline, Platform, Registry, Scope, Source, SourceControl,
10    SourceType, Stage, StageBuild, StageRelease, StageTest, VersionSource,
11    detect_language_by_files,
12};
13
14use std::path::Path;
15
16/// 从 `.quanttide/devops/contract.yaml` 加载契约。
17pub fn load(repo_path: &Path) -> Result<Contract, ContractError> {
18    let path = repo_path.join(".quanttide/devops/contract.yaml");
19    let content = std::fs::read_to_string(&path)?;
20    load_from_str(&content)
21}
22
23/// 从 YAML 字符串解析契约。
24pub fn load_from_str(s: &str) -> Result<Contract, ContractError> {
25    serde_yaml::from_str::<Contract>(s).map_err(|e| ContractError::Parse(e.to_string()))
26}