Provides current CI environment information.
This library main goal is to provide development/build tools such as cargo-make the needed information on the current CI environment.
Inspired by the ci-info npm module.
Simply include the library and invoke the get function to pull all info as follows:
fn main() {
// Just check if a CI environment is detected.
let ci = ci_info::is_ci();
println!("Is CI: {}", ci);
// Get CI environment information
let info = ci_info::get();
println!("Is CI: {}", info.ci);
if let Some(vendor) = info.vendor {
println!("Vendor: {:#?}", vendor);
println!("Name: {:#?}", info.name.unwrap());
}
if let Some(pr) = info.pr {
println!("Is PR: {:#?}", pr);
}
if let Some(branch_name) = info.branch_name {
println!("Branch Name: {:#?}", branch_name);
}
}use ci_info::types::{CiInfo, Vendor};
fn main() {
// create the CI info manually
let mut mock_info = CiInfo::new();
mock_info.vendor = Some(Vendor::TravisCI);
mock_info.ci = true;
mock_info.pr = Some(true);
mock_info.branch_name = Some("dev_branch".to_string());
// mock environment
ci_info::mock_ci(&mock_info);
let info = ci_info::get();
assert!(info.ci);
assert!(info.pr.unwrap());
assert_eq!(info.vendor.unwrap(), Vendor::TravisCI);
assert_eq!(info.name.unwrap(), "Travis CI");
assert_eq!(info.branch_name.unwrap(), "dev_branch");
// clear CI environment
mock_info = CiInfo::new();
ci_info::mock_ci(&mock_info);
let info = ci_info::get();
assert!(!info.ci);
}In order to use this library, just add it as a dependency:
[dependencies]
ci_info = "^0.14.15"There is optional serde support that can be enabled via the serde-1 feature:
[dependencies]
ci_info = { version = "*", features = ["serde-1"] }You can enable iteration over all Vendor enum variants by enabling iter feature:
[dependencies]
ci_info = { version = "^0.14.14", features = ["iter"] }This allows you to programmatically access all supported CI vendors:
use ci_info::types::Vendor;
use strum::IntoEnumIterator;
// List all supported CI vendors
for vendor in Vendor::iter() {
println!("{:?}", vendor);
}
// Check how many vendors are supported
let count = Vendor::iter().count();
println!("Supporting {} CI vendors", count);
// Filter for specific vendors
let cloud_vendors: Vec<_> = Vendor::iter()
.filter(|v| matches!(v,
Vendor::GitHubActions |
Vendor::GitLabCI |
Vendor::CircleCI
))
.collect();Note: Iteration uses strum's EnumIter derive macro under a feature flag.
Run complete example with: cargo run --example iterate_vendors --features iter
See full docs at: API Docs
See Changelog
Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.