くりにっき

フルスタックキュアエンジニアです

Code Climate Test Reporter用のCircleCI Orbsを作った

https://circleci.com/orbs/registry/orb/sue445/codeclimate

github.com

経緯

自分のリポジトリ.circleci/config.yml にあった野良commandをコピペ運用するのが嫌だったというのと、既存のCode Climate系のOrbsを探した時にいいのがなかったのでOrb化しました

使い方

version: 2.1

orbs:
  codeclimate: sue445/codeclimate@x.y.z

jobs:
  test:
    environment:
      CC_TEST_REPORTER_ID: YOUR_CODE_CLIMATE_REPORTER_ID
  
    steps:
      - checkout
  
      - codeclimate/with-cc-test-reporter:
          after_build_args: "--coverage-input-type simplecov"
  
          steps:
            - run: bundle exec rspec

Orbでやってること

Code Climate Test Reporter を使う時は

  1. バイナリをダウンロード
  2. ./cc-test-reporter before-build を実行
  3. 任意のテストコマンドを実行
  4. ./cc-test-reporter after-build を実行

という流れなのですが、3以外の部分を codeclimate/with-cc-test-reporter の中に隠蔽しています。

小ネタ

commandのparameterの steps typeを使うとRubyでいうところのブロックを使ったサンドイッチメソッドのようなリファクタリングができて割と便利

https://github.com/sue445/circleci-orb-codeclimate/blob/0.1.0/src/commands/with-cc-test-reporter.yml#L4-L7