ondram / ci-detector-standalone
独立 CLI 命令,用于检测持续集成环境并提供对当前构建属性的统一访问
Requires
- php: ^7.1
- ext-mbstring: *
- laminas/laminas-filter: ^2.7
- ondram/ci-detector: =3.4.0
- symfony/console: ^4.0 || ^5.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.2
- lmc/coding-standard: ^1.3 || ^2.0
- php-coveralls/php-coveralls: ^2.2
- php-parallel-lint/php-parallel-lint: ^1.1
- phpstan/extension-installer: ^1.0.3
- phpstan/phpstan: ^0.12.0
- phpstan/phpstan-phpunit: ^0.12.1
- phpunit/phpunit: ^7.5 || ^8.0 || ^9.0
This package is auto-updated.
Last update: 2024-08-29 04:25:31 UTC
README
为 ci-detector PHP 库提供的独立 CLI 命令封装。
它用于检测持续集成环境,并提供统一接口读取构建信息。您可以使用该命令使您的脚本(尤其是 CLI 工具)在多个构建环境中可移植。
检测基于持续集成服务器注入到构建环境中的环境变量。然而,这些变量在每个 CI 中的命名都不同。该命令基于轻量级的 ci-detector PHP 库,它为每个支持的 CI 服务器提供适配器。
如果您需要在 PHP 脚本内部进行检测(因此不需要 CLI 命令),您可以直接使用 ci-detector 库。
版本与父 ci-detector 库的版本匹配。有关最新更改的列表,请参阅那里的 变更日志。
用法
$ ./ci-detector.phar # return status code 0 if CI detected, 1 otherwise $ echo $? # to print status code of previous command 0 $ ./ci-detector.phar detect ci-name Travis CI $ ./ci-detector.phar detect build-number 11.3 $ ./ci-detector.phar detect build-url https://travis-ci.org/OndraM/ci-detector-standalone/jobs/189809581 $ ./ci-detector.phar detect branch feature/test $ ./ci-detector.phar detect commit f45e5809cefdbb819913f9357381f4d291fd49a9 $ ./ci-detector.phar detect repository-url # Not supported on Travis CI, will print empty string $ ./ci-detector.phar detect is-pull-request Yes $ ./ci-detector.phar detect branch main
请参阅 方法参考 了解每个属性的文档。
转储所有可用的属性
dump
命令将显示 ci-detector 在当前环境中检测到的所有属性
$ ./ci-detector.phar dump +-----------------+---------------------------------------------------------------+ | Property name | Current value | +-----------------+---------------------------------------------------------------+ | ci-name | Travis CI | | build-number | 164.1 | | build-url | https://travis-ci.org/OndraM/ci-detector-standalone/jobs/1337 | | commit | 9b232f6813915ddb1f226de93366cb924c72e400 | | branch | feature/dump-command | | target-branch | main | | repository-name | ondram/ci-detector | | repository-url | ssh://git@gitserver:7999/project/repo.git | | is-pull-request | Yes | +-----------------+---------------------------------------------------------------+
这基本上是一个表格,包含了 CiInterface
的 describe()
方法的输出(请参阅 方法参考)。
安装
作为独立的 PHAR 文件安装
CI Detector 可以作为独立的可执行 PHAR 文件(ci-detector.phar
)安装。从 发布页面 下载最新版本。
要运行 CI Detector,请使用命令 ./ci-detector.phar
在保存文件的目录中(或如果文件本身不可执行,请使用 php ci-detector.phar
)。
使用 Composer 安装
$ composer require ondram/ci-detector-standalone
要运行 CI Detector,请使用命令 vendor/bin/ci-detector
。
如果您需要在 PHP 脚本内部进行检测(并且不需要 CLI 命令),您可以直接使用轻量级的 ci-detector 库。