All Projects → OndraM → Ci Detector

OndraM / Ci Detector

Licence: mit
Detect continuous integration environment and get information of current build

Projects that are alternatives of or similar to Ci Detector

Env Ci
Get environment variables exposed by CI services
Stars: ✭ 180 (+30.43%)
Mutual labels:  appveyor, ci, continuous-integration, jenkins, circleci, travis, gitlab
Nevergreen
🐤 A build monitor with attitude
Stars: ✭ 170 (+23.19%)
Mutual labels:  ci, continuous-integration, jenkins, travis-ci, circleci
Cargo Make
Rust task runner and build tool.
Stars: ✭ 895 (+548.55%)
Mutual labels:  build-automation, appveyor, travis-ci, circleci, travis
Cibuildwheel
🎡 Build Python wheels for all the platforms on CI with minimal configuration.
Stars: ✭ 620 (+349.28%)
Mutual labels:  build-automation, appveyor, ci, travis-ci, circleci
Cistern
A terminal UI for Unix to monitor Continuous Integration pipelines from the command line. Current integrations include GitLab, Azure DevOps, Travis CI, AppVeyor and CircleCI.
Stars: ✭ 161 (+16.67%)
Mutual labels:  appveyor, ci, circleci, travis, gitlab
Tox
Command line driven CI frontend and development task automation tool.
Stars: ✭ 2,523 (+1728.26%)
Mutual labels:  appveyor, continuous-integration, circleci, travis, gitlab
Skyhook
Parses webhooks and forwards them in the proper format to Discord.
Stars: ✭ 263 (+90.58%)
Mutual labels:  appveyor, jenkins, travis-ci, circleci, gitlab
Ci Matters
Integration (comparison) of different continuous integration services on Android project
Stars: ✭ 119 (-13.77%)
Mutual labels:  ci, jenkins, travis-ci, circleci
scikit-ci
Simpler and centralized CI configuration for Python extensions.
Stars: ✭ 15 (-89.13%)
Mutual labels:  circleci, travis-ci, continuous-integration, appveyor
cibuildwheel
🎡 Build Python wheels for all the platforms on CI with minimal configuration.
Stars: ✭ 1,350 (+878.26%)
Mutual labels:  circleci, travis-ci, build-automation, appveyor
developer-ci-benefits
Talk docs—includes CI (Continuous Integration) benefits, description, and setup tips 💡💪
Stars: ✭ 29 (-78.99%)
Mutual labels:  circleci, travis-ci, continuous-integration, ci
Build Harness
🤖Collection of Makefiles to facilitate building Golang projects, Dockerfiles, Helm charts, and more
Stars: ✭ 236 (+71.01%)
Mutual labels:  build-automation, jenkins, travis-ci, circleci
ci playground
Playground for Cloud CI development for C++
Stars: ✭ 23 (-83.33%)
Mutual labels:  circleci, travis-ci, ci, appveyor
CI-Utils
Utilities for running Common Lisp on CI platforms
Stars: ✭ 18 (-86.96%)
Mutual labels:  circleci, travis-ci, ci, appveyor
Danger
🚫 Stop saying "you forgot to …" in code review (in Ruby)
Stars: ✭ 4,691 (+3299.28%)
Mutual labels:  ci, travis, gitlab
Bzppx Codepub
暴走皮皮虾之代码发布系统,是现代的持续集成发布系统,由后台管理系统和agent两部分组成,一个运行着的agent就是一个节点,本系统并不是造轮子,是"鸟枪"到"大炮"的创新,对"前朝遗老"的革命.
Stars: ✭ 471 (+241.3%)
Mutual labels:  ci, continuous-integration, jenkins
Drone
Drone is a Container-Native, Continuous Delivery Platform
Stars: ✭ 24,287 (+17499.28%)
Mutual labels:  build-automation, ci, continuous-integration
Gitlab Ci Pipeline Php
☕️ Docker images for test PHP applications with Gitlab CI (or any other CI platform!)
Stars: ✭ 451 (+226.81%)
Mutual labels:  ci, continuous-integration, gitlab
Ansible Role Jenkins
Ansible Role - Jenkins CI
Stars: ✭ 689 (+399.28%)
Mutual labels:  ci, continuous-integration, jenkins
Danger Js
⚠️ Stop saying "you forgot to …" in code review
Stars: ✭ 4,076 (+2853.62%)
Mutual labels:  ci, jenkins, travis

CI Detector

Latest Stable Version Packagist Downloads Coverage Status GitHub Actions Build Status Travis Build Status AppVeyor Build Status

PHP library to detect continuous integration environment and to provide a unified interface to read the build information.

The detection is based on environment variables injected to the build environment by each CI server. However, these variables are named differently in each CI. This library contains adapters for many supported CI servers to handles these differences, so you can make your scripts (and especially CLI tools) portable to multiple build environments.

Supported continuous integration servers

These CI servers are currently recognized:

If your favorite CI server is missing, feel free to send a pull-request!

Installation

Install using Composer:

$ composer require ondram/ci-detector

Ci-detector requires PHP 7.1+, but if you need compatibility with PHP <7.1, you can still use old ci-detector version 2.x.

Example usage

<?php

$ciDetector = new \OndraM\CiDetector\CiDetector();

if ($ciDetector->isCiDetected()) {  // Make sure we are on CI environment
    echo 'You are running this script on CI server!';
    $ci = $ciDetector->detect();    // Returns class implementing CiInterface or throws CiNotDetectedException

    // Example output when run inside GitHub Actions build:
    echo $ci->getCiName(); // "GitHub Actions"
    echo $ci->getBuildNumber(); // "33"
    echo $ci->getBranch(); // "feature/foo-bar" or empty string if not detected

    // Conditional code for pull request:
    if ($ci->isPullRequest()->yes()) {
        echo 'This is pull request. The target branch is: ';
        echo $ci->getTargetBranch(); // "main"
    }

    // Conditional code for specific CI server:
    if ($ci->getCiName() === OndraM\CiDetector\CiDetector::CI_GITHUB_ACTIONS) {
        echo 'This is being built on GitHub Actions';
    }

    // Describe all detected values in human-readable form:
    print_r($ci->describe());
    // Array
    // (
    //     [ci-name] => GitHub Actions
    //     [build-number] => 33
    //     [build-url] => https://github.com/OndraM/ci-detector/commit/abcd/checks
    //     [commit] => fad3f7bdbf3515d1e9285b8aa80feeff74507bde
    //     [branch] => feature/foo-bar
    //     [target-branch] => main
    //     [repository-name] => OndraM/ci-detector
    //     [repository-url] => https://github.com/OndraM/ci-detector
    //     [is-pull-request] => Yes
    // )

} else {
    echo 'This script is not run on CI server';
}

API methods reference

Available methods of CiInterface instance (returned from $ciDetector->detect()):

Method Example value Description
getCiName() GitHub Actions Name of the CI server.
The value is one of CiDetector::CI_* constants.
getBuildNumber() 33 Get number of this concrete build.
Build number is usually human-readable increasing number sequence. It should increase each time this particular job was run on the CI server. Most CIs use simple numbering sequence like: 1, 2, 3... However, some CIs do not provide this simple human-readable value and rather use for example alphanumeric hash.
getBuildUrl() https://github.com/OndraM/ci-detector/commit/abcd/checks
or empty string
Get URL where this build can be found and viewed or empty string if it cannot be determined.
getCommit() b9173d94(...) Get hash of the git (or other VCS) commit being built.
getBranch() my-feature
or empty string
Get name of the git (or other VCS) branch which is being built or empty string if it cannot be determined.
Use getTargetBranch() to get name of the branch where this branch is targeted.
getTargetBranch() main
or empty string
Get name of the target branch of a pull request or empty string if it cannot be determined.
This is the base branch to which the pull request is targeted.
getRepositoryName() OndraM/ci-detector
or empty string
Get name of the git (or other VCS) repository which is being built or empty string if it cannot be determined.
This is usually in form "user/repository", for example OndraM/ci-detector.
getRepositoryUrl() https://github.com/OndraM/ci-detector
or empty string
Get URL where the repository which is being built can be found or empty string if it cannot be determined.
This is either HTTP URL like https://github.com/OndraM/ci-detector but may be a git ssh url like ssh://[email protected]/OndraM/ci-detector
isPullRequest() TrinaryLogic instance Detect whether current build is from a pull/merge request.
Returned TrinaryLogic object's value will be true if the current build is from a pull/merge request, false if it not, and maybe if we can't determine it (see below for what CI supports PR detection).
Use condition like if ($ci->isPullRequest()->yes()) { /*...*/ } to use the value.
describe() [...]
(array of values)
Return key-value map of all detected properties in human-readable form.

Supported properties of each CI server

Most CI servers support (✔) detection of all information. However some don't expose necessary environment variables, thus reading some information may be unsupported (❌).

CI server Constant of CiDetector is​PullRequest get​Branch getTargetBranch get​Repository​Name get​Repository​Url get​Build​Url
AppVeyor CI_APPVEYOR
AWS CodeBuild CI_AWS_CODEBUILD
Azure Pipelines CI_AZURE_PIPELINES
Bamboo CI_BAMBOO
Bitbucket Pipelines CI_BITBUCKET_PIPELINES
Buddy CI_BUDDY
CircleCI CI_CIRCLE
Codeship CI_CODESHIP
continuousphp CI_CONTINUOUSPHP
drone CI_DRONE
GitHub Actions CI_GITHUB_ACTIONS
GitLab CI_GITLAB
Jenkins CI_JENKINS
TeamCity CI_TEAMCITY
Travis CI CI_TRAVIS
Wercker CI_WERCKER

Testing

Check codestyle, static analysis and run unit-tests:

composer all

To automatically fix codestyle violations run:

composer fix

Standalone CLI version

If you want to use CI Detector as a standalone CLI command (ie. without using inside code of PHP project), see ci-detector-standalone repository, where you can download CI Detector as a standalone PHAR file with simple command line interface.

Similar libraries for other languages

Similar "CI Info" libraries exists for some other languages, for example:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].