# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2.1

orbs:
  codeclimate: sue445/codeclimate@volatile
  ruby-orbs:   sue445/ruby-orbs@volatile

executors:
  ruby:
    parameters:
      tag:
        type: string
        default: "latest"
    docker:
      - image: ruby:<< parameters.tag >>
    environment:
      # c.f. https://github.com/ffaker/ffaker/issues/277#issuecomment-263519146
      LANG:     en_US.UTF-8
      LANGUAGE: en_US.UTF-8
      LC_ALL:   C.UTF-8

      BUNDLE_PATH: vendor/bundle
      BUNDLE_JOBS: 4
      CC_TEST_REPORTER_ID: d91e7c9665019f1574eb4c5a3de1547c80bc3062e3c297282f106501a3c5c694
    working_directory: ~/app

jobs:
  rspec:
    parameters:
      version:
        type: string
    executor:
      name: ruby
      tag: << parameters.version >>
    steps:
      - checkout
      - run: ruby --version
      - run: bundle --version
      - run: gem --version
      - ruby-orbs/bundle-install:
          cache_key_prefix: "v2-rspec"
          with_gemfile_lock: false
          gemspec_name: "itest5ch"
          update_always: true
      - codeclimate/with-cc-test-reporter:
          after_build_args: "--coverage-input-type simplecov"
          steps:
            - run: bundle exec rspec

  rubocop:
    executor:
      name: ruby

    steps:
      - checkout
      - ruby-orbs/bundle-install:
          cache_key_prefix: "v2-rubocop"
          with_gemfile_lock: false
          gemspec_name: "itest5ch"
          update_always: true

      - run: bundle exec rubocop

build_jobs: &build_jobs
  - rspec:
      name:    "rspec:2.5"
      version: "2.5"
  - rspec:
      name:    "rspec:2.6"
      version: "2.6"
  - rspec:
      name:    "rspec:2.7"
      version: "2.7"
  - rubocop

workflows:
  version: 2

  build:
    jobs: *build_jobs

  weekly_build:
    triggers:
      - schedule:
          cron: "00 19 * * 5" # JST 4:00 (Sat)
          filters:
            branches:
              only: master
    jobs: *build_jobs