我有一个包含多个组件的存储库,其中大部分是用 JavaScript (Node.js) 编写的,一个是用 Ruby (Ruby on Rails) 编写的。我想要一个 .travis.yml 文件来触发一个运行每个组件的所有测试的构建。根据this Travis CI Google Group thread ,目前还没有官方支持。
我的目录结构是这样的:
.
├── 构建服务器
├──核心
├── 扩展
├── 网络应用
├── 流浪文件
├── package.json
├── .travis.yml
└── 生成文件
我希望能够运行特定版本的 Ruby (2.2.2) 和 Node.js (0.12.2)。我已经有了一个 make
目标,所以 make test
在每个子目录中运行适当的测试套件。
最佳答案
事实证明,在 Travis CI 上运行隔离测试套件的每个虚拟机都带有 Node.js and Ruby pre-installed .默认情况下你会得到 Ruby 1.9.3 和 Node.js 0.12.2(但随着 Travis 团队更新他们的环境,这可能会改变),所以即使你只能指定一种语言(例如 language: Ruby
)在您的 .travis.yml
文件中,您仍然可以在 Travis CI VM 上同时运行 Ruby 和 Node.js 程序。
我决定使用 Node.js 语言设置并安装适当的 Ruby 版本(但我可以做相反的事情来获得相同的效果)。
这是我的.travis.yml
配置文件:
language: node_js
node_js:
- 0.12.2
addons:
postgresql: "9.4"
before_install:
- rvm install 2.2.2
install:
# run whatever you have to do here. I have a Makefile that lets you install
# all Node.js-related or Ruby-related dependencies as one step.
- make npm
- make bundler
before_script:
# My Rails app lives in a subdirectory. I want to make sure that
# my database is ready before I start running RSpec tests
- psql -c 'create database test_db;' -U postgres
# I use separate database.yml config for Travis CI
- cp webapp/config/database.travis.yml webapp/config/database.yml
script:
# `test` target executes `bundle exec rspec spec` and `npm run test`
# in all appropriate subdirectories
- make test
关于node.js - 如何在 Travis CI 上的一个项目中运行 Node.js 和 Ruby 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31235146/