version: 2
jobs:
  build:
    parallelism: 1
    docker:
      - image: circleci/ruby:2.5.5
        environment:
          BUNDLE_JOBS: 3
          BUNDLE_RETRY: 3
          BUNDLE_PATH: vendor/bundle
          PGHOST: 127.0.0.1
          PGUSER: eikaiwa
          RAILS_ENV: test
      - image: circleci/postgres:11-alpine
        environment:
          POSTGRES_USER: eikaiwa
          POSTGRES_DB: iknow_view_models
          POSTGRES_PASSWORD: ""
    steps:
      - checkout

      # Which version of bundler?
      - run:
          name: Which bundler?
          command: bundle -v

      - run:
          name: Create gem cache key
          command: cat Gemfile ./gemfiles/*.gemfile > /tmp/gemfiles

      # Restore bundle cache
      - restore_cache:
          keys:
            - iknow_viewmodels-{{ checksum "/tmp/gemfiles" }}
            - iknow_viewmodels-

      - run:
          name: Bundle Install
          command: bundle check || bundle install

      - run:
          name: Appraisal Install
          command: bundle exec appraisal install

      # Store bundle cache
      - save_cache:
          key: iknow_viewmodels-{{ checksum "/tmp/gemfiles" }}
          paths:
            - vendor/bundle

      - run:
          name: Wait for DB
          command: dockerize -wait tcp://localhost:5432 -timeout 1m

      - run:
          name: Run minitest for each appraisal
          command: bundle exec appraisal rake test

      - store_test_results:
          path: test/reports

version: 2
jobs:
  build:
    parallelism: 1
    docker:
      - image: circleci/ruby:2.5.5
        environment:
          BUNDLE_JOBS: 3
          BUNDLE_RETRY: 3
          BUNDLE_PATH: vendor/bundle
          PGHOST: 127.0.0.1
          PGUSER: eikaiwa
          RAILS_ENV: test
      - image: circleci/postgres:11-alpine
        environment:
          POSTGRES_USER: eikaiwa
          POSTGRES_DB: iknow_view_models
          POSTGRES_PASSWORD: ""
    steps:
      - checkout

      # Which version of bundler?
      - run:
          name: Which bundler?
          command: bundle -v

      - run:
          name: Compute a gemfile lock
          command: bundle lock

      # Restore bundle cache
      - restore_cache:
          keys:
            - iknow_viewmodels-{{ checksum "Gemfile.lock" }}
            - iknow_viewmodels-

      - run:
          name: Bundle Install
          command: bundle check || bundle install

      - run:
          name: Appraisal Install
          command: bundle exec appraisal install

      # Store bundle cache
      - save_cache:
          key: iknow_viewmodels-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle

      - run:
          name: Wait for DB
          command: dockerize -wait tcp://localhost:5432 -timeout 1m

      - run:
          name: Run minitest for each appraisal
          command: bundle exec appraisal rake test

      - store_test_results:
          path: test/reports

Create a bundle lock on the project to cache bundled gems
circleci: Create a bundle lock on the project to cache bundled gems

Note that this means that gem changes that only appear in appraisals won't
change the cache key, so will have to be reinstalled each time until the
main bundle changes.
