# 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
  slack:       circleci/slack@3

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

commands:
  bundle_install:
    steps:
      - run: bundle config --local path vendor/bundle
      - run: bundle install --jobs=4 --retry=3

jobs:
  rspec:
    parameters:
      version:
        type: string
    executor:
      name: ruby
      tag: << parameters.version >>
    steps:
      - checkout
      - run: ruby --version
      - run: bundle --version
      - run: gem --version
      - bundle_install
      - codeclimate/with-cc-test-reporter:
          after_build_args: "--coverage-input-type simplecov"
          steps:
            - run: bundle exec rspec
      - slack/notify-on-failure

  rubocop:
    executor:
      name: ruby

    steps:
      - checkout
      - bundle_install
      - run: bundle exec rubocop
      - slack/notify-on-failure

build_jobs: &build_jobs
  - rspec:
      matrix:
        parameters:
          version:
            - "2.5"
            - "2.6"
            - "2.7"
            - "3.0"
  - rubocop

workflows:
  version: 2

  build:
    jobs: *build_jobs

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