cuenv_ci/provider/mod.rs
1//! CI provider trait and implementations.
2//!
3//! This module provides a trait-based abstraction for CI/CD providers.
4//!
5//! # Provider Implementations
6//!
7//! - [`LocalProvider`]: Fallback provider for local development (included in this crate)
8//! - `cuenv-github`: [`GitHubCIProvider`](https://docs.rs/cuenv-github) for GitHub Actions
9//!
10//! # Example
11//!
12//! ```rust,ignore
13//! use cuenv_ci::provider::{CIProvider, local::LocalProvider};
14//!
15//! // Try to detect a CI provider, fall back to local
16//! let provider = LocalProvider::detect().expect("LocalProvider always detects");
17//! let files = provider.changed_files().await?;
18//! ```
19
20use crate::context::CIContext;
21use crate::report::{CheckHandle, PipelineReport};
22use async_trait::async_trait;
23use cuenv_core::Result;
24use std::path::PathBuf;
25
26/// Trait for CI/CD provider integrations.
27///
28/// Implementations provide platform-specific functionality for:
29/// - Detecting the CI environment
30/// - Finding changed files
31/// - Creating and updating check runs/statuses
32/// - Uploading reports
33#[async_trait]
34pub trait CIProvider: Send + Sync {
35 /// Detect if running in this CI environment.
36 ///
37 /// Returns `Some(Self)` if the current environment matches this provider,
38 /// `None` otherwise.
39 fn detect() -> Option<Self>
40 where
41 Self: Sized;
42
43 /// Get normalized CI context.
44 fn context(&self) -> &CIContext;
45
46 /// Get files changed in this build.
47 ///
48 /// For PRs, this returns files changed relative to the base branch.
49 /// For pushes, this returns files changed in the pushed commits.
50 async fn changed_files(&self) -> Result<Vec<PathBuf>>;
51
52 /// Create a check/status for a project pipeline.
53 async fn create_check(&self, name: &str) -> Result<CheckHandle>;
54
55 /// Update check with progress summary.
56 async fn update_check(&self, handle: &CheckHandle, summary: &str) -> Result<()>;
57
58 /// Complete check with final report (renders to provider-specific format).
59 async fn complete_check(&self, handle: &CheckHandle, report: &PipelineReport) -> Result<()>;
60
61 /// Upload report artifact, return URL if available.
62 async fn upload_report(&self, report: &PipelineReport) -> Result<Option<String>>;
63}
64
65pub mod local;
66
67pub use local::LocalProvider;