yanniboi / drupal_ti
Drupal - Travis Integration
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-22 09:39:13 UTC
README
版本
欢迎!
欢迎并感谢您尝试drupal_ti!
这将使您能够通过simpletest和PHPUnit测试轻松使用Travis测试您的Drupal模块。
您所需的所有操作就是将您的Drupal.org仓库推送到Github,设置下面的模块,登录到travis-ci.org,设置仓库,然后您就可以立即开始使用。
设置
将.travis.yml.dist复制到您的根目录作为.travis.yml,并将DRUPAL_TI_MODULE_NAME全局环境变量自定义以匹配您模块的名称。
您还需要激活一个矩阵选项,基于您是否支持Simpletest、PHPUnit、Behat或全部一起
env:
matrix:
# [[[ SELECT ANY OR MORE OPTIONS ]]]
- DRUPAL_TI_RUNNERS="phpunit"
- DRUPAL_TI_RUNNERS="phpunit simpletest behat"
此示例将以PHPUnit作为矩阵运行器运行,这可以快速提供结果,然后是PHPUnit、Simpletest和Behat作为慢速运行器。
如果您想使用Drupal-8模块运行drupal_ti,则需要使用
- DRUPAL_TI_ENVIROMENT="drupal-8"
使用不同的tests/目录。
如果您的tests/和composer.json不在tests/目录中,您可能需要更改
before_install:
# Comment this line for different directories, e.g. composer in the root.
# - cd ./tests
它是如何工作的
drupal_ti提供了一个drupal-ti命令,该命令随后在travis-ci的每个阶段(例如安装、before_script等)中被调用。
通过在runners/simpletest或runners/phpunit/中提供不同的运行器,将执行相应的脚本(例如runners/phpunit/script.sh)。
此外,还包含来自environments/$DRUPAL_TI_ENVIRONMENT.sh的不同环境,这使得区分Drupal 7和8变得很容易。
这为您提供了模块化的travis体验,因此脚本可以非常通用。
Drupal安装在$TRAVIS_BUILD_DIR/drupal_travis/drupal中,drush在before_script阶段后可用。
如何自定义默认行为
通过使用
- DRUPAL_TI_SCRIPT_DIR_BEFORE="./drupal_ti/before"
- DRUPAL_TI_SCRIPT_DIR_AFTER="./drupal_ti/after"
您可以从您的基本目录定义自己的脚本,并且drupal_ti将在您的主脚本之前和之后调用它们。
这非常有用,例如更改默认环境变量,e.g. environments/drupal-7.sh定义
export DRUPAL_TI_DRUSH_VERSION="drush/drush:6.*"
但您可能需要不同的版本,并覆盖drupal_ti_install_drupal函数(因为core-quick-drupal命令需要drush 6)。
理论上,您甚至可以通过仅用空格分隔来定义多个,或者通过composer安装 - 可能性是无限的 :).
示例
- DRUPAL_TI_SCRIPT_DIR_BEFORE="./drupal_ti/before ./vendor/lionsad/drupal_ti_base_cool/drupal_ti/before"
- DRUPAL_TI_SCRIPT_DIR_AFTER="./drupal_ti/after ./vendor/lionsad/drupal_ti_base_cool/drupal_ti/after"
从Github仓库添加模块依赖项
您的模块可能有几个依赖项不在Drupal.org上。可以使用自定义脚本并将它们包括在.travis.yml文件中来添加这些模块。
在.travis.yml中,您将有一个before_script部分。默认命令安装Drupal和我们正在测试的模块。我们可以添加一个命令drupal-ti --include [script]。此命令将首先加载脚本,然后运行默认的drupal-ti before_script命令。
.travis.yml
before_script:
# We run our script to add module dependencies
# This uses git clone over HTTPS because the modules don't currently
# exist on drupal.org.
- drupal-ti --include drupal_ti/before/before_script.sh
- drupal-ti before_script
脚本路径相对于我们的/tests目录,因为我们已经在before_install过程中将其移动到默认目录。
现在我们可以创建以下自定义脚本,
/tests/drupal_ti/before/before_script.sh
#!/bin/bash
# Add an optional statement to see that this is running in Travis CI.
echo "running drupal_ti/before/before_script.sh"
set -e $DRUPAL_TI_DEBUG
# Ensure the right Drupal version is installed.
# The first time this is run, it will install Drupal.
# Note: This function is re-entrant.
drupal_ti_ensure_drupal
# Change to the Drupal directory
cd "$DRUPAL_TI_DRUPAL_DIR"
# Create the the module directory (only necessary for D7)
# For D7, this is sites/default/modules
# For D8, this is modules
mkdir -p "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_MODULES_PATH"
cd "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_MODULES_PATH"
# Manually clone the dependencies
git clone --depth 1 https://github.com/my-project/my-dependency.git
# or with a different branch
git clone --depth 1 --branch 8.x-1.x https://github.com/my-project/my-dependency.git
目录/tests/drupal_ti/before/也可以用于添加使用更复杂的模式自动发现的脚本,例如/tests/before/runners/[runner]/[command].sh。但是,这将仅限于特定的运行器,而上面的include模式将为所有运行器运行。
带Composer管理器的脚本
Composer管理器是一个流行的依赖项,需要额外的工作才能设置。
#!/bin/bash
# Add an optional statement to see that this is running in Travis CI.
echo "running drupal_ti/before/before_script.sh"
set -e $DRUPAL_TI_DEBUG
# Ensure the right Drupal version is installed.
# The first time this is run, it will install Drupal.
# Note: This function is re-entrant.
drupal_ti_ensure_drupal
# Change to the Drupal directory
cd "$DRUPAL_TI_DRUPAL_DIR"
# Create the the module directory (only necessary for D7)
# For D7, this is sites/default/modules
# For D8, this is modules
mkdir -p "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_MODULES_PATH"
cd "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_MODULES_PATH"
# Manually clone the dependencies
git clone --depth 1 --branch 8.x-1.x http://git.drupal.org/project/composer_manager.git
# Initialize composer manage
php "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_MODULES_PATH/composer_manager/scripts/init.php"
# Ensure the module is linked into the code base and enabled.
# Note: This function is re-entrant.
drupal_ti_ensure_module_linked
# Update composer
cd "$DRUPAL_TI_DRUPAL_DIR"
composer drupal-rebuild
composer install --prefer-source
贡献
欢迎贡献。
Drush
为了您的方便,'drush site-set' 命令已经为 Drupal 安装设置好了,因此您在自己的脚本中触发的任何 Drush 命令都将针对测试 Drupal 实例运行。