summaryrefslogtreecommitdiff
path: root/src/tox/util/ci.py
blob: 30ba80ed9c31b02a3c5572e01f3dcabaf2fe61a5 (plain)
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
from __future__ import annotations

import os

_ENV_VARS = {  # per https://adamj.eu/tech/2020/03/09/detect-if-your-tests-are-running-on-ci
    "CI": None,  # generic flag
    "TF_BUILD": "true",  # Azure Pipelines
    "bamboo.buildKey": None,  # Bamboo
    "BUILDKITE": "true",  # Buildkite
    "CIRCLECI": "true",  # Circle CI
    "CIRRUS_CI": "true",  # Cirrus CI
    "CODEBUILD_BUILD_ID": None,  # CodeBuild
    "GITHUB_ACTIONS": "true",  # GitHub Actions
    "GITLAB_CI": None,  # GitLab CI
    "HEROKU_TEST_RUN_ID": None,  # Heroku CI
    "BUILD_ID": None,  # Hudson
    "TEAMCITY_VERSION": None,  # TeamCity
    "TRAVIS": "true",  # Travis CI
}


def is_ci() -> bool:
    """:return: a flag indicating if running inside a CI env or not"""
    for env_key, value in _ENV_VARS.items():
        if env_key in os.environ if value is None else os.environ.get(env_key) == value:
            if env_key == "TEAMCITY_VERSION" and os.environ.get(env_key) == "LOCAL":
                continue
            return True
    return False


__all__ = [
    "is_ci",
]