railslink/railslink

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
---
version: 2
defaults: &defaults
  docker:
    - image: circleci/ruby:2.7.4-node
      environment:
        BUNDLE_JOBS: 3
        BUNDLE_RETRY: 3
        BUNDLE_PATH: vendor/bundle
        PGHOST: 127.0.0.1
        PGUSER: railslink
        RAILS_ENV: test
    - image: circleci/postgres:10.10-alpine
      environment:
        POSTGRES_USER: railslink
        POSTGRES_DB: ruby_on_rails_link_test
        POSTGRES_PASSWORD: ""
jobs:
  build:
    parallelism: 3
    <<: *defaults
    steps:
      - checkout

      # Reinstall bundler to fix circleci/ruby-2.4.4 wonkiness
      - run:
          name: Reinstall bundler gem
          command: gem install bundler

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

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

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

      # Restore yarn cache
      - restore_cache:
          keys:
            - railslink-yarn-{{ checksum "yarn.lock" }}
            - railslink-yarn-

      - run:
          name: Yarn Install
          command: yarn install --cache-folder ~/.cache/yarn

      # Store yarn / webpacker cache
      - save_cache:
          key: railslink-yarn-{{ checksum "yarn.lock" }}
          paths:
            - ~/.cache/yarn

      - run:
          name: Run Stylelint
          command: ./node_modules/.bin/stylelint -f verbose app/assets/stylesheets

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

      - run:
          name: Database setup
          command: bin/rails db:schema:load --trace

      # Run rspec in parallel
      - type: shell
        name: "Run Rspec"
        command: |
          bundle exec rspec --profile 10 \
                            --format RspecJunitFormatter \
                            --out test_results/rspec.xml \
                            --format progress \
                            $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)

      # Save test results for timing analysis
      - store_test_results:
          path: test_results

workflows:
  version: 2
  commit:
    jobs:
      - build