YutaGoto/salmon_run

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
version: 2.1

ruby_image: &ruby_image
  circleci/ruby:2.7.0-node-browsers

bundle_cache_key: &bundle_cache_key
  v1-dependencies-{{ checksum "Gemfile.lock" }}

executors:
  docker-exec:
    docker:
      - image: *ruby_image
        environment:
          TZ: Asia/Tokyo
          CC_TEST_REPORTER_ID: ${CC_TEST_REPORTER_ID}
          RAILS_ENV: test
          PGHOST: 127.0.0.1
          PGUSER: root
      - image: circleci/postgres:11.3
        environment:
          POSTGRES_USER: root
          POSTGRES_DB: salmon_run_test
      - image: circleci/node:10.1.0-browsers

jobs:
  lint:
    executor: docker-exec
    working_directory: ~/salmon_run
    steps:
      - checkout
      - restore_cache:
          name: Restore cache salmon-run
          keys:
            - salmon-run-{{ checksum "Gemfile.lock" }}
            - salmon-run-
      - run:
          name: update bundler
          command: gem update bundler
      - run: bundle install --jobs=4 --retry=3 --path=vendor/bundle
      - save_cache:
          name: Saving cache salmon-run
          key: salmon-run-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle
      - run: bundle exec rails db:create
      - run: bundle exec rails db:schema:load
      - run:
          name: RuboCop check
          command: bundle exec rubocop
      - run:
          name: goodcheck self check
          command: bundle exec goodcheck test
      - run:
          name: Regexp based customizable linter
          command: bundle exec goodcheck check
      - run:
          name: Do not comment out unused code
          command: bundle exec dont_comment app/**/*.rb spec/**/*.rb

  mdlint:
    executor: docker-exec
    working_directory: ~/salmon_run
    steps:
      - checkout
      - run:
          name: install dependencies packages
          command: yarn
      - run:
          name: check markdown lint
          command: yarn mdlint
  eslint:
    executor: docker-exec
    working_directory: ~/salmon_run
    steps:
      - checkout
      - run:
          name: install dependencies packages
          command: yarn
      - run:
          name: check frontend lint
          command: yarn lint

  check:
    executor: docker-exec
    working_directory: ~/salmon_run
    steps:
      - checkout
      - restore_cache:
          name: Restore cache salmon-run
          keys:
            - salmon-run-{{ checksum "Gemfile.lock" }}
            - salmon-run-
      - run:
          name: update bundler
          command: gem update bundler
      - run: bundle install --jobs=4 --retry=3 --path=vendor/bundle
      - save_cache:
          name: Saving cache salmon-run
          key: salmon-run-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle
      - run: bundle exec rails db:create
      - run: bundle exec rails db:schema:load
      - run:
          name: Code smell detector by Reek
          command: bundle exec reek /app -c .reek
      - run:
          name: Analysis of security vulnerabilities by brakeman
          command: bundle exec brakeman -A -w1 -z

  test:
    executor: docker-exec
    working_directory: ~/salmon_run
    steps:
      - checkout
      - run:
          name: Install System Dependencies
          command: |
            sudo apt-get update
            sudo apt-get install -y libappindicator1 libgbm1 fonts-liberation
            export CHROME_BIN=/usr/bin/google-chrome
            wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
            sudo dpkg -i google-chrome*.deb

      - run:
          name: Setup Code Climate test-reporter
          command: |
            curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
            chmod +x ./cc-test-reporter
      - run:
          name: install dependencies packages
          command: yarn
      - restore_cache:
          name: Restore cache salmon-run
          keys:
            - salmon-run-{{ checksum "Gemfile.lock" }}
            - salmon-run-
      - run:
          name: update bundler
          command: gem update bundler
      - run: bundle install --jobs=4 --retry=3 --path=vendor/bundle
      - save_cache:
          name: Saving cache salmon-run
          key: salmon-run-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle
      - run: bundle exec rails db:create
      - run: bundle exec rails db:schema:load
      - run: mkdir ~/rspec
      - run:
          name: Run rspec in parallel
          command: |
            ./cc-test-reporter before-build
            bundle exec rspec --format progress \
                              $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
            ./cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?

      - store_test_results:
          path: ~/rspec

workflows:
  version: 2
  build:
    jobs:
      - lint
      - check
      - mdlint
      - eslint
      - test:
          requires:
            - lint
            - check
            - mdlint
            - eslint