1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use core::cfg;

// 'mac', 'win', 'linux'
pub fn build_target() -> &'static str {
    if cfg!(target_os = "linux") {
        "linux"
    } else if cfg!(target_os = "freebsd") {
        "freebsd"
    } else if cfg!(target_os = "macos") {
        "mac"
    } else if cfg!(target_os = "windows") {
        "win"
    } else if cfg!(unix) {
        "unix"
    } else {
        "other"
    }
}
/// 'main', ... (git branches or tags, `CI_COMMIT_REF_NAME`)
pub fn build_reference() -> Option<&'static str> {
    option_env!("CI_COMMIT_REF_NAME")
}
/// '123', ... (GitLab CI pipeline id, `CI_PIPELINE_ID`)
pub fn build_pipeline_id() -> Option<&'static str> {
    option_env!("CI_PIPELINE_ID")
}
/// '123', ... (GitLab CI pipeline id per project, `CI_PIPELINE_IID`)
pub fn build_pipeline_id_per_project() -> Option<&'static str> {
    option_env!("CI_PIPELINE_IID")
}
/// '123', ... (GitLab CI job id, `CI_JOB_ID`)
pub fn build_job_id() -> Option<&'static str> {
    option_env!("CI_JOB_ID")
}
/// Git revision if available, from build variable `CI_COMMIT_SHA`
pub fn build_revision() -> Option<&'static str> {
    option_env!("CI_COMMIT_SHA")
}

/// GitLab project name, from build variable `CI_PROJECT_NAME`. Fallback to Rust package name
pub fn build_project_name() -> Option<&'static str> {
    option_env!("CI_PROJECT_NAME").or(Some(env!("CARGO_PKG_NAME")))
}

/// Sentry error reporting DSN, from build variable `SENTRY_DSN`.
pub fn build_sentry_dsn() -> Option<&'static str> {
    option_env!("SENTRY_DSN")
}

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        println!("{}", crate::build_target());
    }
}