Skip to content

Commit

Permalink
Merge pull request #571 from DataRecce/feature/drc-1016-the-judgement…
Browse files Browse the repository at this point in the history
…-of-is_ci-in-telemetry-might-be-wrong

[Chore] Improve is_ci function
  • Loading branch information
even-wei authored Jan 8, 2025
2 parents ec4a288 + 2b30b1e commit 4deb81d
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions recce/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import os
import sys


def is_ci_env():
# some CI service puts the "CI" var
if os.environ.get('CI', 'false') == 'true':
return True

# For CiecleCI exceptions
if os.environ.get('CIRCLECI', 'false') == 'true':
return True

# if not tty, it probably runs automatically
if not sys.stdout.isatty():
return True
# List of CI environment variables and their expected values
ci_environments = {
'CI': 'true', # Generic CI indicator
'CIRCLECI': 'true', # CircleCI
'GITHUB_ACTIONS': 'true', # GitHub Actions
'GITLAB_CI': 'true', # GitLab CI
'JENKINS_URL': None, # Jenkins (just needs to exist)
'TRAVIS': 'true', # Travis CI
'APPVEYOR': 'true', # AppVeyor
'DRONE': 'true', # Drone CI
'TEAMCITY_VERSION': None, # TeamCity
'BITBUCKET_COMMIT': None, # Bitbucket Pipelines
'BUILDKITE': 'true', # Buildkite
'CODEBUILD_BUILD_ID': None, # AWS CodeBuild
'AZURE_PIPELINES': 'true', # Azure Pipelines
}

for env_var, expected_value in ci_environments.items():
env_value = os.environ.get(env_var)
if env_value is not None:
# If we just need the variable to exist
if expected_value is None:
return True
# If we need to match a specific value (case-insensitive)
if env_value.lower() == expected_value.lower():
return True

return False

Expand Down

0 comments on commit 4deb81d

Please sign in to comment.