buildinfy 0.2.1

Easy access to GitLab/GitHub/Gitea CI/CD variables for automatic versioning
Documentation
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`/`GITHUB_REF_NAME`)
pub fn build_reference() -> Option<&'static str> {
    option_env!("CI_COMMIT_REF_NAME").or(option_env!("GITHUB_REF_NAME"))
}
/// '123', ... (CI pipeline id, `CI_PIPELINE_ID`/`GITHUB_RUN_NUMBER`)
pub fn build_pipeline_id() -> Option<&'static str> {
    option_env!("CI_PIPELINE_ID").or(option_env!("GITHUB_RUN_NUMBER"))
}
/// '123', ... (CI pipeline id per project (if available), `CI_PIPELINE_IID`/`GITHUB_RUN_NUMBER`)
pub fn build_pipeline_id_per_project() -> Option<&'static str> {
    option_env!("CI_PIPELINE_IID").or(option_env!("GITHUB_RUN_NUMBER"))
}
/// 'package-debian-amd64', ... (CI job name, `CI_JOB_NAME`/`GITHUB_JOB`)
pub fn build_job_name() -> Option<&'static str> {
    option_env!("CI_JOB_NAME").or(option_env!("GITHUB_JOB"))
}
/// Git revision if available, from build variable `CI_COMMIT_SHA`/`GITHUB_SHA`
pub fn build_revision() -> Option<&'static str> {
    option_env!("CI_COMMIT_SHA").or(option_env!("GITHUB_SHA"))
}

/// project owner and repository name, from build variable `CI_PROJECT_NAME`/`GITHUB_REPOSITORY`. Can contain multiple slashes (2 if GitLab subgroeps are used). Fallback to Rust package name
pub fn build_project() -> Option<&'static str> {
    option_env!("CI_PROJECT_PATH").or(option_env!("GITHUB_REPOSITORY")).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());
    }
}