aliases:
  - &save-mac-bundler-cache
    key: bundle_mac
    paths:
      - vendor/bundle

  - &restore-mac-bundler-cache
    key: bundle_mac

  - &bundler-environment
    BUNDLE_JOBS: 3
    BUNDLE_RETRY: 3
    BUNDLE_PATH: vendor/bundle

  - &shell
    /bin/bash --login -eo pipefail

  - &set-ruby-version
    echo "ruby-2.4" > ~/.ruby-version

version: 2
jobs:

  swift:
    macos:
      xcode: "10.0.0"
    environment: *bundler-environment
    # Used to invoke chruby
    shell: *shell
    steps:
      - checkout
      - restore_cache: *restore-mac-bundler-cache
      - run: *set-ruby-version
      - run: bundle install
      - run: git submodule update --init --recursive
      - run: bundle exec rake swift_spec
      - save_cache: *save-mac-bundler-cache

  objc:
    macos:
      xcode: "10.0.0"
    environment: *bundler-environment
    # Used to invoke chruby
    shell: *shell
    steps:
      - checkout
      - restore_cache: *restore-mac-bundler-cache
      - run: *set-ruby-version
      - run: bundle install
      - run: git submodule update --init --recursive
      - run: bundle exec rake objc_spec
      - save_cache: *save-mac-bundler-cache

  cocoapods:
    macos:
      xcode: "10.0.0"
    environment: *bundler-environment
    # Used to invoke chruby
    shell: *shell
    steps:
      - checkout
      - restore_cache:
          key: cocoapods
      - restore_cache: *restore-mac-bundler-cache
      - run: *set-ruby-version
      - run: bundle install
      - run: git submodule update --init --recursive
      - run: bundle exec rake cocoapods_spec
      - save_cache:
          key: cocoapods
          paths:
            - ~/.cocoapods
      - save_cache: *save-mac-bundler-cache

  danger_and_rubocop:
    docker:
      - image: circleci/ruby:2.4-node
        environment: *bundler-environment
        # Used to invoke chruby
        shell: *shell
    steps:
      - checkout
      - restore_cache:
          key: bundle_linux
      - run: bundle install
      - run: bundle exec danger --verbose || true
      - run: bundle exec rake rubocop
      - save_cache:
          key: bundle_linux
          paths:
            - vendor/bundle

workflows:
  version: 2
  workflow:
    jobs:
      - swift
      - objc
      - cocoapods
      - danger_and_rubocop