version: 2.1

jobs:
  build:
    docker:
       - image: circleci/ruby:2.5.8

    working_directory: ~/repo

    steps:
      - checkout

      - restore_cache:
          keys:
            - gems-v2-{{ checksum "Gemfile.lock" }}
            - gems-v2-

      - run:
          name: Force Bundler Version
          command: |
            sudo gem update --system
            echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
            source $BASH_ENV

      - run:
          name: Install Dependencies
          command: |
            bundle config --local set vendor/bundle
            bundle install

      - save_cache:
          key: gems-v2-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle

      - run:
          name: Create ~/.netrc
          command: | 
            cp spec/fixtures/.netrc ~/
            chmod 0600 ~/.netrc

      - run:
          name: Run tests
          command: |
            mkdir /tmp/test-results
            TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
            
            bundle exec rspec --format progress \
                            --format RspecJunitFormatter \
                            --out /tmp/test-results/rspec.xml \
                            --format progress \
                            $TEST_FILES

      - store_test_results:
          path: /tmp/test-results

      - store_artifacts:
          path: /tmp/test-results
          destination: test-results

version: 2.1

jobs:
  build:
    docker:
       - image: circleci/ruby:2.5.8

    working_directory: ~/repo

    steps:
      - checkout

      - restore_cache:
          keys:
            - gems-v3-{{ checksum "Gemfile.lock" }}
            - gems-v3-

      - run:
          name: Force Bundler Version
          command: |
            sudo gem update --system
            echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
            source $BASH_ENV

      - run:
          name: Install Dependencies
          command: |
            bundle config --local set vendor/bundle
            bundle install

      - save_cache:
          key: gems-v3-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle

      - run:
          name: Create ~/.netrc
          command: | 
            cp spec/fixtures/.netrc ~/
            chmod 0600 ~/.netrc

      - run:
          name: Run tests
          command: |
            mkdir /tmp/test-results
            TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
            
            bundle exec rspec --format progress \
                            --format RspecJunitFormatter \
                            --out /tmp/test-results/rspec.xml \
                            --format progress \
                            $TEST_FILES

      - store_test_results:
          path: /tmp/test-results

      - store_artifacts:
          path: /tmp/test-results
          destination: test-results

Update cache version to invalidate
Update cache version to invalidate
