[Continuous Integration] Ruby プロジェクトに Travis CI + Code Climate を導入する

オレオレ gem プロジェクトに CI ツールを導入します。

[markdown]

> * [DriftwoodJP/bcupgrade: Awesome brew cask upgrade command.](https://github.com/DriftwoodJP/bcupgrade)

概要の把握は、こちらを参考にさせて頂きました。

> * [技術的負債を調査する10のポイント(翻訳)](https://techracho.bpsinc.jp/hachi8833/2018_01_24/50875)
> * [GitHubと連携できる継続的インテグレーションツール「Travis CI」入門 | さくらのナレッジ](https://knowledge.sakura.ad.jp/3754/)

## 設定ファイル

こちらを参考に `.travis.yml` を作成します。

> * [Travis CI Test Coverage](https://docs.codeclimate.com/docs/travis-ci-test-coverage)
> * [Getting started – Travis CI](https://docs.travis-ci.com/user/getting-started/)

この設定で期待する結果は、以下の3つです。

– Code Climate で Maintainability が表示される。
– Code Climate で Test Coverage が表示される。
– Travis で Rspec が Build(実行)される。

“`yaml:.travis.yml
env:
global:
– CC_TEST_REPORTER_ID=****
sudo: false
language: ruby
os: osx
cache: bundler
rvm:
– 2.3.3
– 2.4
before_install:
– gem install bundler -v 1.16.1
before_script:
– curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-darwin-amd64 > ./cc-test-reporter
– chmod +x ./cc-test-reporter
– ./cc-test-reporter before-build
script:
– bundle exec rspec
after_script:
– ./cc-test-reporter after-build –exit-code $TRAVIS_TEST_RESULT
“`

## つまずきポイント

– 前述の通り、`cc-test-reporter` の導入方法が変わっていました。
– Test Coverage の表示には、そもそも `simplecov` gem が必要でした。

> * [Display your ruby test coverage using SimpleCov gem and CodeClimate](https://cdn-images-1.medium.com/max/800/1*HcrOiCIvwY5MpBTCT1xrKg.png)

`bundle install` した後に、`**_helper.rb` で呼び出します。

> * [colszowka/simplecov: Code coverage for Ruby 1.9+ with a powerful configuration library and automatic merging of coverage across test suites](https://github.com/colszowka/simplecov)

“`ruby:spec/spec_helper.rb
:
require ‘simplecov’
SimpleCov.start
:
“`

– `.codeclimate.yml` は不要でした。

[RuboCop](https://docs.codeclimate.com/docs/rubocop) などを `.codeclimate.yml` を作成して設定すると、codeclimate.com の設定を上書きしてしまいました。

> You have a YML config file which is overriding these settings.
This repository uses a committed .codeclimate.yml to configure analysis. Settings on this page will not be applied unless you remove the file. See our documentation for how to edit your config file.

– `Could not find * in any of the sources (Bundler::GemNotFound)` というエラーが表示される。
[method materialize](https://github.com/bundler/bundler/blob/86e4b2a636fa2153bcd048dc084ace180cfe5c4a/lib/bundler/spec_set.rb#L88) で発生している。

うーん、保留。

## 補遺

> * [Building a Ruby Project – Travis CI](https://docs.travis-ci.com/user/languages/ruby/#Default-Build-Script)
> * [The OS X Build Environment – Travis CI](https://docs.travis-ci.com/user/reference/osx/)
> * [RubyGems Deployment – Travis CI](https://docs.travis-ci.com/user/deployment/rubygems/)

Slack

> * [Configuring Build Notifications – Travis CI](https://docs.travis-ci.com/user/notifications/#Configuring-slack-notifications)
> * [Travis CIのbuild結果をSlackに通知する – Qiita](https://qiita.com/vmmhypervisor/items/b6cd3f8db7b434fbb933)

[/markdown]