如何在 Travis CI 上的一个项目中 运行 Node.js 和 Ruby 测试

How to run Node.js and Ruby tests within one project on Travis CI

我有一个包含多个组件的存储库,其中大部分在 JavaScript (Node.js) 中,一个在 Ruby 中编写(Ruby on Rails).我想要一个 .travis.yml 文件来触发一个构建,该构建 运行 对每个组件进行所有测试。根据this Travis CI Google Group thread,官方暂无支持

我的目录结构是这样的:

. ├── buildserver ├── core ├── extensions ├── webapp ├── Vagrantfile ├── package.json ├── .travis.yml └── Makefile

我希望能够 运行 特定版本的 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