typisttech / travis-nginx-wordpress
在Travis CI基于容器的基础设施上运行的Nginx和WordPress的基本模板。
Requires
- wp-cli/wp-cli: ^1.5
README
在Travis CI基于容器的基础设施上运行的Nginx和WordPress的基本模板。
此仓库的目的是什么?
您需要在Travis CI上运行依赖于Nginx的自动化测试吗?您希望这些测试在Docker 基于容器的基础设施上运行吗?您是否在尝试让所有这些工作在一起时感到头疼?那么这个仓库就是为您准备的。
Travis CI没有预装Nginx,因此需要编写脚本安装。由于Travis CI的基于容器的基础设施不允许sudo权限,因此此安装不是微不足道的。希望通过提供此仓库,我可以帮助某人避免在为他们的项目设置Nginx时遇到麻烦。
安装和使用
该脚本针对Travis CI PHP构建镜像进行了定制,可能不在所有情况下都适用。下面是一个基本的.travis.yml
示例
# .travis.yml
language: php
services:
- mysql
cache:
apt: true
directories:
- $HOME/.composer/cache/files
addons:
apt:
packages:
- nginx
hosts:
- wp.dev
php:
- 7.1
- 7.2
- nightly
env:
global:
- COMPOSER_NO_INTERACTION=1
matrix:
- WP_VERSION=nightly
- WP_VERSION=latest
- WP_VERSION=4.9.3
- WP_VERSION=4.8.5
before_install:
# Install helper scripts
- composer global require --prefer-dist "typisttech/travis-nginx-wordpress:^1.0.0"
- export PATH=$HOME/.composer/vendor/bin:$PATH
- tnw-install-nginx
- tnw-install-wordpress
- tnw-prepare-codeception
install:
# Build the test suites
- cd $TRAVIS_BUILD_DIR
- composer install -n --prefer-dist
- vendor/bin/codecept build -n
script:
# Run the tests
- cd $TRAVIS_BUILD_DIR
- vendor/bin/codecept run -n --coverage --coverage-xml
after_script:
- tnw-upload-coverage-to-scrutinizer
- tnw-upload-coverage-to-codecov
这是与上述Travis设置兼容的codeception.dist.yml
的基本示例
# codeception.dist.yml
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
coverage:
enabled: true
include:
- src/my-plugin/*
exclude:
- src/my-plugin/partials/*
params: [env] # get parameters from environment vars
modules:
config:
WPDb:
dsn: 'mysql:host=localhost;dbname=wordpress'
user: 'root'
password: ''
dump: 'tests/_data/dump.sql'
url: 'http://wp.dev:8080'
WPBrowser:
url: 'http://wp.dev:8080'
adminUsername: 'admin'
adminPassword: 'password'
adminPath: '/wp-admin'
WordPress:
depends: WPDb
wpRootFolder: '/tmp/wordpress'
adminUsername: 'admin'
adminPassword: 'password'
WPLoader:
wpRootFolder: '/tmp/wordpress'
dbName: 'wordpress_int'
dbHost: 'localhost'
dbUser: 'root'
dbPassword: ''
tablePrefix: 'int_wp_'
domain: 'wordpress.dev'
adminEmail: 'admin@wordpress.dev'
WPWebDriver:
url: 'http://wp.dev:8080'
port: 4444
window_size: '1024x768'
adminUsername: 'admin'
adminPassword: 'password'
adminPath: '/wp-admin'
定制
默认脚本在/tmp/wordpress
上安装WordPress核心,并在http://wp.dev:8080
上提供。
您可以通过环境变量定制构建。请检查bin目录中函数的变量,以获取可用的配置。
它是如何工作的?
所有设置脚本都位于bin目录中,模板文件位于tpl目录中。它们简洁且基础,因此应该相对容易理解。该仓库定义了6个设置脚本
tnw-install-wordpress
- 安装WordPress
tnw-install-nginx
- 设置Nginx以从本地域的文件夹中提供网站
tnw-prepare-codeception
tnw-upload-coverage-to-codecov
- 将测试覆盖率上传到 codecov.io
tnw-upload-coverage-to-scrutinizer
- 将测试覆盖率上传到 Scrutinizer
WordPress
WordPress 安装通过 tnw-install-wordpress bash 脚本完成。基本安装过程如下
- 创建 WordPress 数据库。
- 下载 WordPress 核心文件。
- 生成
wp-config.php
文件。- 注意添加了
define( 'AUTOMATIC_UPDATER_DISABLED', true );
- 注意添加了
- 安装 WordPress 数据库。
Nginx
Nginx 安装通过 tnw-install-nginx bash 脚本完成。基本安装过程如下
- 使用 apt 插件 通过 .travis.yml 文件中的条目安装 Nginx。
- 将配置模板复制到新目录,并用环境变量替换占位符。
- 使用自定义配置文件启动 php-fpm 和 Nginx,而不是默认配置。
Codeception
Codeception 准备通过 tnw-prepare-codeception bash 脚本完成。基本安装过程如下
- 将
codeception.yml
和codeception.dist.yml
中的phantomjs
路径替换为 TravisCI 中的一个。 - 为测试创建额外的数据库。
- 将数据库转储导入 WordPress。
- 升级 WordPress 数据库。
- 导出 WordPress 数据库转储以供以后使用。
注意:必须用单引号包裹 phantomjs
路径。
extensions:
enabled:
- Codeception\Extension\Phantoman
config:
Codeception\Extension\Phantoman:
path: '/usr/bin/phantomjs'
port: 4444
suites: ['acceptance']
Codecov.io
通过 tnw-upload-coverage-to-codecov bash 脚本完成 Codecov.io 测试覆盖率上传。基本安装过程如下
- 运行 codecov-bash 脚本。
Scrutinizer CI
通过 tnw-upload-coverage-to-scrutinizer bash 脚本完成 Scrutinizer CI 测试覆盖率上传。基本安装过程如下
- 下载 ocular。
- 将测试覆盖率文件上传到 Scrutinizer CI。
已知问题
-
Nginx 启动时会给出警告消息,可以忽略。
$ install-nginx [26-Dec-2046 00:00:00] NOTICE: [pool travis] 'user' directive is ignored when FPM is not running as root nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
另请参阅
使用此包的实际案例
这里是
在这里添加自己的 内容
支持!
通过PayPal捐赠 
喜欢Travis CI Nginx WordPress测试?帮助我维护Travis CI Nginx WordPress测试,一个 捐赠 可以帮助到它。
为什么不雇佣我呢?
准备好接受自由职业WordPress工作。通过 这里 的联系表单联系我,或者通过电子邮件 info@typist.tech
想以其他方式帮忙?想成为赞助商?
联系: Tang Rufus
变更日志
查看 CHANGELOG.md。
致谢
Travis CI Nginx WordPress测试最初是从 Travis CI Nginx测试 项目分叉出来的。特别感谢其作者 Todd Burry。
许可
Travis CI Nginx WordPress测试是在 MIT许可证 下发布的。