38 releases

✓ Uses Rust 2018 edition

new 0.10.2 Jul 3, 2020
0.10.0 Mar 27, 2020
0.9.0 Dec 8, 2019
0.8.1 Sep 29, 2019
0.1.12 Nov 3, 2017

#4 in Build Utils

Download history 5047/week @ 2020-03-16 4728/week @ 2020-03-23 2799/week @ 2020-03-30 3056/week @ 2020-04-06 3132/week @ 2020-04-13 2435/week @ 2020-04-20 3289/week @ 2020-04-27 2859/week @ 2020-05-04 2515/week @ 2020-05-11 3473/week @ 2020-05-18 4477/week @ 2020-05-25 5365/week @ 2020-06-01 3088/week @ 2020-06-08 3380/week @ 2020-06-15 3989/week @ 2020-06-22 4148/week @ 2020-06-29

14,943 downloads per month
Used in 31 crates (2 directly)

Apache-2.0

1MB
2K SLoC

ci_info

crates.io CI codecov
license Libraries.io for GitHub Documentation downloads
Built with cargo-make

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.
The code is based on 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.10.2"

There is optional serde support that can be enabled via the serde-1 feature:

[dependencies]
ci_info = { version = "*", features = ["serde-1"] }

API Documentation

See full docs at: API Docs

Contributing

See contributing guide

Release History

See Changelog

License

Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.

Dependencies

~2MB
~12K SLoC