ondram/ci-detector
Detects when your PHP app is running in CI. Provides a simple API to identify common CI providers via environment variables, so you can tweak behavior for tests, builds, and deployments without hardcoding provider logic.
Start by installing the package via Composer: composer require ondram/ci-detector. Then instantiate OndraM\CiDetector\CiDetector and call detect() to get a typed object representing the current CI environment (e.g., GitHubActions, GitLabCi, CircleCi). Use the isCi() method to gate CI-specific logic, and inspect methods like getName(), getBuildNumber(), or getCommitHash() to access contextual metadata.
Example first use case: in a Laravel test bootstrap file (tests/Bootstrap.php), detect CI to enable parallelized test execution or suppress interactive prompts:
$ci = (new CiDetector())->detect();
if ($ci?->isCi()) {
config()->set('database.default', 'ci_testing'); // custom DB config
}
Review the src/Ci/ directory in the repo (or generated PHPDoc) to see which CI providers are supported and which metadata fields are reliably exposed.
$ci?->isCi() guards, especially useful in feature tests.php artisan db:wipe) outside CI by checking $ci?->isCi() and the provider type.php artisan ci:status to output build context for troubleshooting CI failures.Common integration points: AppServiceProvider::boot(), PHPUnit bootstrap files, custom deployment scripts, or job-level commands in CI config (e.g., .github/workflows/ci.yml).
CI=true set manually), leading to incorrect detection. Always validate via isCi() first, and consider provider-specific checks (e.g., $ci instanceof GitHubActions) for critical logic.method_exists() or has*() checks before accessing optional properties like getBuildUrl() or getJobId().CiInterface and registering custom detectors via CiDetector::addDetector(new YourCustomCiDetector()).detect() is idempotent and fast—safe to call repeatedly—but avoid instantiating CiDetector in hot loops.putenv()/$_ENV overrides. Never rely on real CI detection in unit tests; instead, assert against concrete detector classes (e.g., isInstanceOf(GitLabCi::class)).detect() may return null in edge cases (e.g., invalid env state); default to safe behavior (e.g., non-CI mode) when detection fails.How can I help you explore Laravel packages today?