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;
6pub mod version;
7
8pub use error::ContractError;
9pub use model::{
10    BuildTool, Contract, Language, Pipeline, Platform, Registry, Scope, Source, SourceControl,
11    SourceType, Stage, StageBuild, StageRelease, StageTest, VersionSource,
12    detect_language_by_files,
13};
14pub use version::{normalize_version, read_all_config_versions, validate_version};
15
16use std::path::Path;
17
18/// 从 `.quanttide/devops/contract.yaml` 加载契约。
19pub fn load(repo_path: &Path) -> Result<Contract, ContractError> {
20    let path = repo_path.join(".quanttide/devops/contract.yaml");
21    let content = std::fs::read_to_string(&path)?;
22    load_from_str(&content)
23}
24
25/// 从 YAML 字符串解析契约。
26pub fn load_from_str(s: &str) -> Result<Contract, ContractError> {
27    serde_yaml::from_str::<Contract>(s).map_err(|e| ContractError::Parse(e.to_string()))
28}