version_bump/env_ci
CI environment detection from environment variables. This is a small, pure
reimplementation of the parts of the env-ci package that the release
pipeline relies on: figuring out whether we’re running in CI, which provider,
the branch and commit under test, and whether the build is for a pull/merge
request.
Everything here is a pure function of an environment dictionary so it can be
unit-tested without touching the real process environment. Callers wire up
the live environment (e.g. via envoy) and pass it in.
Types
The result of inspecting the environment for CI metadata.
pub type CiEnv {
CiEnv(
is_ci: Bool,
provider: String,
branch: option.Option(String),
commit: option.Option(String),
is_pr: Bool,
)
}
Constructors
-
CiEnv( is_ci: Bool, provider: String, branch: option.Option(String), commit: option.Option(String), is_pr: Bool, )Arguments
- is_ci
-
Whether we appear to be running inside a CI service at all.
- provider
-
A short identifier for the detected provider (e.g. “github”, “gitlab”, “generic”, or “” when nothing CI-like was found).
- branch
-
The branch being built, if it could be determined.
- commit
-
The commit SHA being built, if it could be determined.
- is_pr
-
Whether this build corresponds to a pull/merge request.
Values
pub fn detect(env: dict.Dict(String, String)) -> CiEnv
Detect the CI environment from the given environment variables.
Providers are checked from most-specific to least-specific so that a generic
CI=true only wins when no known provider matched. Returns a CiEnv with
is_ci: False and an empty provider when nothing CI-like is present.