lionsad / drupal_ti
Drupal - Travis集成
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-05 15:25:50 UTC
README
版本
欢迎!
欢迎并感谢您尝试使用drupal_ti!
这将使您能够轻松使用Travis CI测试您的Drupal模块,包括simpletest和PHPUnit测试。
您只需要将您的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"
如果您想使用Drupal-9模块运行drupal_ti,则需要使用
- DRUPAL_TI_ENVIROMENT="drupal-9"
使用不同的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的每个阶段(例如install
、before_script
等)被调用。
通过在runners/simpletest或runners/phpunit/中提供不同的运行器,将执行相应的脚本(例如runners/phpunit/script.sh)。
还包括不同的环境,来自environments/$DRUPAL_TI_ENVIRONMENT.sh
,这使得区分Drupal 7、Drupal 8和Drupal 9变得容易。
这为您提供了模块化的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上托管。这些模块可以使用自定义脚本并使用including
在.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 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 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
为了方便起见,已为 Drupal 安装设置了 drush site-set
命令,因此您在脚本中触发的任何 Drush 命令都将针对测试 Drupal 实例运行。