PHPackages                             mlocati/ci-info - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. mlocati/ci-info

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

mlocati/ci-info
===============

Get informations about the current continuous integration environment

1.1.0(5y ago)3134.1k↓14.1%2MITPHPPHP &gt;=7.2

Since Jun 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mlocati/ci-info)[ Packagist](https://packagist.org/packages/mlocati/ci-info)[ Docs](https://github.com/mlocati/ci-info)[ GitHub Sponsors](https://github.com/sponsors/mlocati)[ Fund](https://paypal.me/mlocati)[ RSS](/packages/mlocati-ci-info/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (2)

CI-Info
=======

[](#ci-info)

This package lets you get details about the current Continuous Integration environment.

Supported environments are:

- AppVeyor
- GitHub Actions
- TravisCI

Installation
------------

[](#installation)

You can install this package in two ways:

- using [composer](https://getcomposer.org): ```
    composer require mlocati/ci-info

    ```
- manually: download a ZIP archive from the [project Releases page](https://github.com/mlocati/ci-info/releases).

Usage from within your PHP scripts
----------------------------------

[](#usage-from-within-your-php-scripts)

### Setup

[](#setup)

First of all, **if you don't use Composer**, you need to include the `autoload.php` file you can find in the root directory of this project:

```
require_once 'path/to/autoload.php';
```

Usage
-----

[](#usage)

### Determine the current CI Environment

[](#determine-the-current-ci-environment)

```
$driver = (new \CIInfo\DriverList())->getDriverForEnvironment();
if ($driver === null) {
    // CI environment Not detected
} else {
    if ($ci->getHandle() === \CIInfo\Driver\GithubActions::HANDLE) {
        // We are running in a GitHub Actions build
    }
}
```

### Get info about the current job

[](#get-info-about-the-current-job)

```
try {
    $state = (new \CIInfo\StateFactory())->getCurrentState();
} catch (\CIInfo\Exception $whoops) {
    echo "Something went wrong: " . (string) $whoops;
    return;
}

switch ($state->getEvent()) {
    case \CIInfo\State::EVENT_PUSH:
        // $state is an instance of the \CIInfo\State\Push (or its \CIInfo\State\PushWithoutBaseCommit subclass) class
        echo "We are in a build triggered by a push.\n";
        break;
    case \CIInfo\State::EVENT_PULLREQUEST:
        // $state is an instance of the \CIInfo\State\PullRequest class
        echo "We are in a build triggered by a pull request.\n";
        break;
    case \CIInfo\State::EVENT_TAG:
        // $state is an instance of the \CIInfo\State\Tag class
        echo "We are in a build triggered by the creation of a tag.\n";
        break;
    case \CIInfo\State::EVENT_SCHEDULED:
        // $state is an instance of the \CIInfo\State\Scheduled class
        echo "We are in a build triggered by a scheduled job.\n";
        break;
    case \CIInfo\State::EVENT_MANUAL:
        // $state is an instance of the \CIInfo\State\Manual class
        echo "We are in a build triggered manually (via APIs, manual builds, repository_dispatch events, ...).\n";
        break;
}
```

To see the methods available for every class, see the [source code](https://github.com/mlocati/ci-info/tree/master/src/State).

Usage from a shell
------------------

[](#usage-from-a-shell)

You can also use this library in your shell scripts (bash, sh, powershell, ...).

First of all, you have to determine the path of the `ci-info` file. It's under the `bin` directory (or `composer/vendor/bin` for composer-based projects).

`ci-info` can provide details about the current environment/job.

Here's a sample POSIX script:

```
$ driver="$(./bin/ci-info driver)"
$ echo "The current CI environment is: $driver"
The current CI environment is: travis-ci
```

Here's a sample PowerShell script:

```
PS> $driver="$(.\bin\ci-info driver)"
PS> Write-Host "The current CI environment is: $driver"
The current CI environment is: github-actions
```

To get the full list of the features of the `ci-info` command, type:

```
$ ./bin/ci-info --help
```

Which outputs:

```
Syntax:
  ./bin/ci-info [-q|--quiet] [-h|--help]

Options:
-q|--quiet: turn off displaying errors
-h|--help : show this syntax message and quits

Allowed values for  are:
# driver
Print the handle identifying the current environment.
Possible results are:
- appveyor: AppVeyor
- github-actions: GitHub Actions
- travis-ci: Travis CI

# event
Print the current operation type.
Possible results are:
- cron: Scheduled event
- manual: Manually triggered event (API calls, repository_dispatch events, forced rebuilds, ...)
- pr: Pull request event
- push: Push event
- tag: Tag creation event

# sha1
Print the SHA-1 of the most recent commit (it's the merge commit in case of pull requests)

# pr:base:branch
Print the target branch of a pull request

# pr:base:sha1
Print the SHA-1 of the last commit in the target branch

# pr:head:sha1
Print the SHA-1 of the last commit in the pull request branch

# pr:wrongsha1
Print the wrong SHA-1 of the merge commit of a pull request event as defined by the current environment.
For example, the TRAVIS_COMMIT environment variable defined in TravisCI may be wrong (see https://travis-ci.community/t/travis-commit-is-not-the-commit-initially-checked-out/3775 )
If there merge commit SHA-1 is correct, nothing gets printed out.

# pr:range
Print the commit range of pull request events (example: 123456abcded...abcded123456)

# push:branch
Print the name of the branch affected by a push event

# push:range:has
Check if the commit range is available.
In case it's not available, the exit code is 1, otherwise it's 0.
The reason why the range is not available is printed out to the standard error (use -q to prevent that).

# push:prev:sha1
Print the SHA-1 of the commit prior to the last commit for a push event

# push:range
Print the commit range of push events (example: 123456abcded...abcded123456)

# tag:name
Print the tag name (for tag jobs)

# manual:branch
Print the current branch in a manually-triggered job

# cron:branch
Print the current branch in a scheduled job

Exit code:
0: success
1: failure

```

Tests
-----

[](#tests)

This library is tested against two types of cases:

- Offline tests, implemented as GitHub Actions and managed by phpunit, which test the library against well-known environment statuses of the supported CI environment
    - Status: [![Offline Tests](https://github.com/mlocati/ci-info/workflows/Offline%20Tests/badge.svg)](https://github.com/mlocati/ci-info/actions?query=workflow%3A%22Offline+Tests%22)
- Online tests, executed directly in every supported CI enviromnent
    - AppVeyor: [![AppVeyor Online Tests](https://camo.githubusercontent.com/e0bccda272c852d6d02b60d148548efe31b4e15dd266161d0a36e5b913c0ed8e/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f78356a306672657032637238643269332f6272616e63682f6d61737465723f7376673d74727565)](https://ci.appveyor.com/project/mlocati/ci-info/history)
    - GitHub Actions: [![GitHub Actions Online Tests](https://github.com/mlocati/ci-info/workflows/Online%20Tests/badge.svg)](https://github.com/mlocati/ci-info/actions?query=workflow%3A%22Online+Tests%22)
    - TravisCI:
        - Push tests: [![TravisCI Online Tests for pushes](https://camo.githubusercontent.com/39915c35e6464e0c7be47a99eda7464b756027c0f0aec1354f499ba7dd1d7801/68747470733a2f2f7472617669732d63692e6f72672f6d6c6f636174692f63692d696e666f2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/github/mlocati/ci-info/branches)
        - Pull request tests: [![TravisCI Online Tests for pull requests](https://camo.githubusercontent.com/39915c35e6464e0c7be47a99eda7464b756027c0f0aec1354f499ba7dd1d7801/68747470733a2f2f7472617669732d63692e6f72672f6d6c6f636174692f63692d696e666f2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/github/mlocati/ci-info/pull_requests)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

2

Last Release

2143d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e9d7ece045fc89575e083ee4852edf31218df403c84f41a0de01863dae982f5?d=identicon)[mlocati](/maintainers/mlocati)

---

Top Contributors

[![mlocati](https://avatars.githubusercontent.com/u/928116?v=4)](https://github.com/mlocati "mlocati (92 commits)")

---

Tags

requestgithubtravisappveyorcicontinuouspullactionsinfointegrationstravisci

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/mlocati-ci-info/health.svg)

```
[![Health](https://phpackages.com/badges/mlocati-ci-info/health.svg)](https://phpackages.com/packages/mlocati-ci-info)
```

###  Alternatives

[ondram/ci-detector

Detect continuous integration environment and provide unified access to properties of current build

22249.4M33](/packages/ondram-ci-detector)[moodlehq/moodle-plugin-ci

Helps running Moodle plugins analysis checks and tests under various CI environments.

612.6M](/packages/moodlehq-moodle-plugin-ci)[jbzoo/ci-report-converter

The tool converts different error reporting standards for deep integration with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc)

30784.4k2](/packages/jbzoo-ci-report-converter)[saggre/phpdocumentor-markdown

Markdown template for phpDocumentor3

2079.5k30](/packages/saggre-phpdocumentor-markdown)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
