36 releases

✓ Uses Rust 2018 edition

new 0.10.0 Mar 27, 2020
0.9.1 Jan 18, 2020
0.9.0 Dec 8, 2019
0.8.1 Sep 29, 2019
0.1.12 Nov 3, 2017

#3 in Build Utils

Download history 12072/week @ 2019-12-10 10093/week @ 2019-12-17 4945/week @ 2019-12-24 6917/week @ 2019-12-31 11632/week @ 2020-01-07 14373/week @ 2020-01-14 18157/week @ 2020-01-21 10734/week @ 2020-01-28 7248/week @ 2020-02-04 5004/week @ 2020-02-11 4349/week @ 2020-02-18 3639/week @ 2020-02-25 4155/week @ 2020-03-03 4437/week @ 2020-03-10 5505/week @ 2020-03-17 3815/week @ 2020-03-24

33,341 downloads per month
Used in 23 crates (2 directly)

Apache-2.0

1MB
2K SLoC

ci_info

crates.io Build Status Build status 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 info.vendor.is_some() {
        println!("Vendor: {:#?}", info.vendor.unwrap());
        println!("Name: {:#?}", info.name.unwrap());
    }
    if info.pr.is_some() {
        println!("Is PR: {:#?}", info.pr.unwrap());
    }
    if info.branch_name.is_some() {
        println!("Branch Name: {:#?}", info.branch_name.unwrap());
    }
}

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 = "*"

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