6

我有一个包含多个组件的存储库,其中大部分是用 JavaScript (Node.js) 编写的,一个是用 Ruby (Ruby on Rails) 编写的。我想要一个 .travis.yml 文件来触发一个构建,该构建运行每个组件的所有测试。根据这个 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在每个子目录中运行适当的测试套件。

4

1 回答 1

18

事实证明,在 Travis CI 上运行隔离测试套件的每个 VM 都预装了Node.js 和 Ruby。默认情况下,您将获得 Ruby 1.9.3 和 Node.js 0.12.2(但随着 Travis 团队更新他们的环境,这可能会发生变化),因此即使您只能在文件中指定一种语言(例如language: Ruby.travis.yml,您仍然可以同时运行 Ruby和 Travis CI VM 上的 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
于 2015-07-12T23:59:12.947 回答