version: 2.1 ruby-image: &ruby-image cimg/ruby:<%= ruby_version %> <%- if selected?(:database, :postgresql) -%> postgres-image: &postgres-image postgres:<%= Potassium::POSTGRES_VERSION %> <%- end -%> <%- if selected?(:background_processor) -%> redis-image: &redis-image redis <%- end -%> env-vars: &env-vars BUNDLE_JOBS: 4 BUNDLE_PATH: vendor/bundle RAILS_ENV: test orbs: browser-tools: circleci/browser-tools@1.1 executors: test-executor: docker: - image: *ruby-image environment: *env-vars <%- if selected?(:database, :postgresql) -%> - image: *postgres-image <%- end -%> <%- if selected?(:background_processor) -%> - image: *redis-image <%- end -%> lint-executor: docker: - image: *ruby-image environment: *env-vars commands: setup: description: checkout code, restore cache, install dependencies, save cache steps: - checkout - restore_cache: keys: - bundle-dependencies-{{ .Environment.BUNDLE_CACHE_VERSION }}-{{ checksum "Gemfile.lock" }} - bundle-dependencies- - restore_cache: keys: - yarn-dependencies-{{ .Environment.YARN_CACHE_VERSION }}-{{ checksum "yarn.lock" }} - yarn-dependencies- - run: name: Install reviewdog command: | curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b ./bin - run: name: Install bundle dependencies command: | BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ") gem install bundler:$BUNDLER_VERSION bundle _$(echo $BUNDLER_VERSION)_ install - run: name: Install yarn dependencies command: | curl -sL https://deb.nodesource.com/setup_$(cat .node-version).x | sudo -E bash - sudo apt-get install -y nodejs curl -o- -sL https://yarnpkg.com/install.sh | bash sudo ln -s $HOME/.yarn/bin/yarn /usr/local/bin/yarn yarn install --frozen-lockfile - save_cache: key: bundle-dependencies-{{ .Environment.BUNDLE_CACHE_VERSION }}-{{ checksum "Gemfile.lock" }} paths: - vendor/bundle - save_cache: key: yarn-dependencies-{{ .Environment.YARN_CACHE_VERSION }}-{{ checksum "yarn.lock" }} paths: - node_modules <%- if selected?(:storage, :shrine) -%> - run: name: Install apt and vips buildpack dependencies command: | xargs -a Aptfile sudo apt-get install sudo apt-get install libvips <%- end -%> jobs: test: executor: test-executor steps: - setup - browser-tools/install-chrome - browser-tools/install-chromedriver <%- if selected?(:background_processor) -%> - run: name: Wait for redis service command: dockerize -wait tcp://localhost:6379 -timeout 1m <%- end -%> <%- if selected?(:database, :postgresql) -%> - run: name: Wait for postgres service command: dockerize -wait tcp://localhost:5432 -timeout 1m - run: name: Setup database command: bundle exec rails db:create db:schema:load <%- end -%> - run: name: Run RSpec unit tests command: | RSPEC_JUNIT_ARGS="-r rspec_junit_formatter -f RspecJunitFormatter -o test_results/rspec.xml" RSPEC_FORMAT_ARGS="-f progress --no-color -p 10" bundle exec rspec spec $RSPEC_FORMAT_ARGS $RSPEC_JUNIT_ARGS - run: name: Run simplecov shell: /bin/bash command: | cat coverage/coverage.txt | ./bin/reviewdog -reporter=github-pr-review -efm="%f:%l:%c: %m" - run: name: Run RSpec system tests command: | RSPEC_JUNIT_ARGS="-r rspec_junit_formatter -f RspecJunitFormatter -o test_results/rspec-system.xml" RSPEC_FORMAT_ARGS="--tag type:system -f progress --no-color -p 10" bundle exec rspec spec $RSPEC_FORMAT_ARGS $RSPEC_JUNIT_ARGS <%- if selected?(:front_end, :vue) -%> - run: name: Run jest command: | yarn run test > coverage/input_jest.txt ./node_modules/.bin/format-coverage coverage/input_jest.txt coverage/output_jest.txt /home/circleci/project/app/javascript cat coverage/output_jest.txt | ./bin/reviewdog -reporter=github-pr-review -efm="%f:%l:%c: %m" <%- end -%> - store_test_results: path: test_results lint: executor: lint-executor steps: - setup - run: name: Get files to lint command: git diff origin/master --name-only --diff-filter=d > tmp/files_to_lint - run: name: Run rubocop shell: /bin/bash command: | cat tmp/files_to_lint | grep -E '.+\.(rb)$' | xargs bundle exec rubocop --force-exclusion \ | ./bin/reviewdog -reporter=github-pr-review -f=rubocop - run: name: Run eslint shell: /bin/bash command: | cat tmp/files_to_lint | grep -E '.+\.(js|jsx|vue)$' | xargs yarn run eslint \ | ./bin/reviewdog -reporter=github-pr-review -f=eslint - run: name: Run tsc shell: /bin/bash command: | yarn run tsc --noEmit | ./bin/reviewdog -reporter=github-pr-review -f=tsc - run: name: Run vue-tsc shell: /bin/bash command: | yarn run vue-tsc --noEmit | ./bin/reviewdog -reporter=github-pr-review -f=tsc - run: name: Run stylelint shell: /bin/bash command: | cat tmp/files_to_lint | grep -E '.+\.(scss|css|less)$' | xargs yarn run stylelint \ | ./bin/reviewdog -reporter=github-pr-review -f=stylelint workflows: test_and_lint: jobs: - test: context: org-global - lint: context: org-global