<commit_before>version: 2
jobs:
  build:
    working_directory: ~/marc_liberation

    # Primary command image where all commands run
    docker:
      - image: circleci/ruby:2.6-node-browsers
        environment:
          RAILS_ENV: test
          PGHOST: localhost
          PGUSER: bibdata
      - image: postgres:10.6-alpine
        environment:
          POSTGRES_USER: bibdata
          POSTGRES_DB: marc_liberation_test
          POSTGRES_HOST_AUTH_METHOD: trust

    steps: 
      - checkout
      - run:
          name: Install node@8.17.0 (need right version for `yarn`)
          command: |
            set +e
            touch $BASH_ENV
            curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
            echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
            echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
            echo 'nvm install v8.17.0' >> $BASH_ENV
            echo 'nvm alias default v8.17.0' >> $BASH_ENV
      - run:
          name: Check current version of node
          command: node -v
      - restore_cache:
          keys:
          - marc_liberation-{{ checksum "Gemfile.lock" }}-2
      - run:
          name: Install phantomjs
          command: sudo apt install phantomjs
      - run: sudo apt-get -y update
      - run: sudo apt-get install -y postgresql-client || true    
      - run: gem install bundler -v '~> 2.0'
      - run:
          name: Install dependencies
          command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --without development production --jobs 4 --retry 3
      - save_cache:
          key: marc_liberation-{{ checksum "Gemfile.lock" }}-2
          paths:
            - vendor/bundle 

      - run:
          name: Configure location display
          command: cp -v marc_to_solr/translation_maps/location_display.rb.tmpl marc_to_solr/translation_maps/location_display.rb

      - run:
          name: Configure locations
          command: cp -v marc_to_solr/translation_maps/locations.rb.tmpl marc_to_solr/translation_maps/locations.rb

      - run:
          name: Configure holding libraries
          command: cp -v marc_to_solr/translation_maps/holding_library.rb.tmpl marc_to_solr/translation_maps/holding_library.rb

      - run:
          name: Wait for Postgres
          command: dockerize -wait tcp://localhost:5432 -timeout 120s

      - run:
          name: Database setup
          command: bundle exec rake db:setup

      - run:
          name: Rubocop
          command: bundle exec rubocop

      - run:
          name: Rspec
          command: bundle exec rspec spec marc_to_solr/spec<commit_msg>Fix bundle cache restore<commit_after>version: 2
jobs:
  build:
    working_directory: ~/marc_liberation

    # Primary command image where all commands run
    docker:
      - image: circleci/ruby:2.6-node-browsers
        environment:
          RAILS_ENV: test
          PGHOST: localhost
          PGUSER: bibdata
      - image: postgres:10.6-alpine
        environment:
          POSTGRES_USER: bibdata
          POSTGRES_DB: marc_liberation_test
          POSTGRES_HOST_AUTH_METHOD: trust

    steps: 
      - checkout
      - run:
          name: Install node@8.17.0 (need right version for `yarn`)
          command: |
            set +e
            touch $BASH_ENV
            curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
            echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
            echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
            echo 'nvm install v8.17.0' >> $BASH_ENV
            echo 'nvm alias default v8.17.0' >> $BASH_ENV
      - run:
          name: Check current version of node
          command: node -v
      - restore_cache:
          keys:
            # this cache is never found because ruby-oci8 isn't included in ci
            - marc_liberation-{{ checksum "Gemfile.lock" }}-2
            # use a partial cache restore
            - marc_liberation-
      - run:
          name: Install phantomjs
          command: sudo apt install phantomjs
      - run: sudo apt-get -y update
      - run: sudo apt-get install -y postgresql-client || true    
      - run: gem install bundler -v '~> 2.0'
      - run:
          name: Install dependencies
          command: bundle install --path=vendor/bundle --without development production --jobs 4 --retry 3
      - save_cache:
          key: marc_liberation-{{ checksum "Gemfile.lock" }}-2
          paths:
            - vendor/bundle
      - run:
          name: Configure location display
          command: cp -v marc_to_solr/translation_maps/location_display.rb.tmpl marc_to_solr/translation_maps/location_display.rb

      - run:
          name: Configure locations
          command: cp -v marc_to_solr/translation_maps/locations.rb.tmpl marc_to_solr/translation_maps/locations.rb

      - run:
          name: Configure holding libraries
          command: cp -v marc_to_solr/translation_maps/holding_library.rb.tmpl marc_to_solr/translation_maps/holding_library.rb

      - run:
          name: Wait for Postgres
          command: dockerize -wait tcp://localhost:5432 -timeout 120s

      - run:
          name: Database setup
          command: bundle exec rake db:setup

      - run:
          name: Rubocop
          command: bundle exec rubocop

      - run:
          name: Rspec
          command: bundle exec rspec spec marc_to_solr/spec
{'fraction_non_alphanumeric': 0.08941605839416059, 'fraction_numerical': 0.012956204379562044, 'mean_word_length': 1.8576642335766422, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2443385', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1647, 'n_words': 428}