ci_info

Crates.ioci_info
lib.rsci_info
version0.14.14
sourcesrc
created_at2017-10-10 19:06:33.411907
updated_at2023-12-15 07:02:35.419133
descriptionProvides current CI environment information.
homepagehttp://github.com/sagiegurari/ci_info
repositoryhttps://github.com/sagiegurari/ci_info.git
max_upload_size
id35139
size1,559,303
CrateOwner (github:gigainfosystems:crateowner)

documentation

https://sagiegurari.github.io/ci_info/api/ci_info/index.html

README

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.
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.14"

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.

Commit count: 165

cargo fmt