RyanofWoods/rails-react-swedish-birds

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

jobs:
  run-tests:
    docker:
      - image: cimg/ruby:3.0.4-node
        environment:
          RAILS_ENV: test
          PGHOST: 127.0.0.1
          PGUSER: root
      - image: cimg/postgres:14.0
        environment:
          POSTGRES_USER: root
          POSTGRES_DB: swedish-birds_test

    steps:
      - run: .circleci/bin/halt-for-documentation-only-changes.sh && circleci step halt || true
      - checkout
      - restore_cache:
          key: bundle-{{ checksum "Gemfile.lock" }}
      - run: |
          bundle config set path 'vendor/bundle'
          .circleci/bin/install-same-bundler-version.sh
          bundle check || bundle install
      - run: sudo apt install -y postgresql-client || true
      - save_cache:
          key: bundle-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle
      - restore_cache:
          key: yarn-{{ checksum "yarn.lock" }}
      - run:
          name: Yarn Install
          command: |
            yarn install --cache-folder ~/.cache/yarn
      - save_cache:
          key: yarn-{{ checksum "yarn.lock" }}
          paths:
            - node_modules
            - ~/.cache
      - run: |
          bundle exec rake db:create
          bundle exec rake db:schema:load
      - run:
          name: Download CodeClimate test-reporter
          command: |
            mkdir -p /tmp
            curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
            chmod +x ./tmp/cc-test-reporter
      - run:
          name: Inform CodeClimate of Pending Test Coverage
          command: |
            ./tmp/cc-test-reporter before-build
      - run:
          name: Run backend tests
          command: |
            bundle exec rake test
            ./tmp/cc-test-reporter format-coverage -t simplecov -o tmp/codeclimate.backend.json coverage/backend/.resultset.json
      - run:
          name: Run frontend tests
          command: |
            yarn jest
            ./tmp/cc-test-reporter format-coverage -t lcov -o tmp/codeclimate.frontend.json coverage/frontend/lcov.info
      - run:
          name: Upload coverage results to Code Climate
          command: |
            ./tmp/cc-test-reporter sum-coverage tmp/codeclimate.*.json -p 2 -o tmp/codeclimate.total.json
            ./tmp/cc-test-reporter upload-coverage -i tmp/codeclimate.total.json

workflows:
  run-tests-workflow:
    jobs:
      - run-tests