58 releases
| 0.14.15 | Nov 1, 2025 |
|---|---|
| 0.14.14 | Dec 15, 2023 |
| 0.14.13 | Oct 7, 2023 |
| 0.14.10 | Feb 14, 2023 |
| 0.1.12 | Nov 3, 2017 |
#19 in Build Utils
98,746 downloads per month
Used in 160 crates
(16 directly)
1.5MB
2.5K
SLoC
Contains (WOFF font, 400KB) NanumBarunGothic-13b3dcba.ttf.woff2, (WOFF font, 140KB) FiraSans-Italic-81dc35de.woff2, (WOFF font, 135KB) FiraSans-Medium-e1aa3f0a.woff2, (WOFF font, 140KB) FiraSans-MediumItalic-ccf7e434.woff2, (WOFF font, 130KB) FiraSans-Regular-0fe48ade.woff2, (WOFF font, 82KB) SourceSerif4-Bold-6d4fd4c0.ttf.woff2 and 8 more.
ci_info
Provides current CI environment information.
Overview
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.
Usage
Simply include the library and invoke the get function to pull all info as follows:
Fetching Info
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);
}
}
Mocking CI environment
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);
}
Installation
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"] }
Iterating Over Vendor Variants
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
API Documentation
See full docs at: API Docs
Contributing
Release History
See Changelog
License
Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.
Dependencies
~2.5MB
~28K SLoC