Crates.io | ci_env |
lib.rs | ci_env |
version | |
source | src |
created_at | 2023-03-16 20:49:48.3124+00 |
updated_at | 2025-02-01 17:49:17.761005+00 |
description | Detect CI information from the environment. |
homepage | https://github.com/milesj/rust-cicd-env |
repository | https://github.com/milesj/rust-cicd-env |
max_upload_size | |
id | 812066 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Detects CI (continuous integration) information from the current environment.
To start, detect if in a CI environment.
ci_env::is_ci();
Or detect which CI provider is being used.
ci_env::detect_provider(); // GithubActions
And most importantly, extract information about the CI environment and CI provider. This includes branch, commit, and pull request information.
use ci_env::get_environment;
if let Some(ci) = get_environment() {
println!("Provider: {:?}", ci.provider);
println!("Branch: {}", ci.branch);
println!("Commit: {}", ci.revision);
if let Some(pr_number) = ci.request_id {
println!("PR #: {}", pr_number);
}
}
This library will properly take into account source and target branches when a pull request is involved. Do note though that not all providers provide this information.