Last active
December 16, 2018 14:33
-
-
Save h-sakano/68104439e8cfb6f6836a8a02bd08551b to your computer and use it in GitHub Desktop.
Rails x CircleCI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2.1 | |
executors: | |
default: | |
working_directory: ~/repo | |
docker: | |
- image: circleci/ruby:2.5.1-node-browsers | |
environment: | |
RACK_ENV: test | |
RAILS_ENV: test | |
commands: | |
setup_packages: | |
steps: | |
- restore_cache: | |
keys: | |
- v1-dependencies-{{ checksum "Gemfile.lock" }} | |
# fallback to using the latest cache if no exact match is found | |
- v1-dependencies- | |
- run: | |
name: install dependencies | |
command: | | |
bundle install --jobs=4 --retry=3 --path vendor/bundle | |
- save_cache: | |
paths: | |
- ./vendor/bundle | |
key: v1-dependencies-{{ checksum "Gemfile.lock" }} | |
jobs: | |
rspec: | |
executor: | |
name: default | |
environment: | |
PARALLEL_TESTS_CONCURRENCY: 4 | |
parallelism: 2 | |
steps: | |
- checkout | |
- setup_packages | |
# Database setup | |
- run: bundle exec rails parallel:setup[${PARALLEL_TESTS_CONCURRENCY}] | |
# run tests! | |
- run: | |
name: run tests | |
command: | | |
mkdir /tmp/test-results | |
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)" | |
bundle exec parallel_rspec -n ${PARALLEL_TESTS_CONCURRENCY} $TEST_FILES | |
- run: | |
name: Stash coverage results | |
command: | | |
mkdir coverage_results | |
cp -R coverage/.resultset.json coverage_results/.resultset-${CIRCLE_NODE_INDEX}.json | |
- persist_to_workspace: | |
root: . | |
paths: | |
- coverage_results | |
# collect reports | |
- store_test_results: | |
path: /tmp/test-results | |
- store_artifacts: | |
path: /tmp/test-results | |
destination: test-results | |
coverage: | |
executor: | |
name: default | |
steps: | |
- checkout | |
- setup_packages | |
- attach_workspace: | |
at: . | |
- run: bundle exec rails simplecov:report_coverage | |
- store_artifacts: | |
path: ~/repo/coverage | |
destination: coverage | |
workflows: | |
build: | |
jobs: | |
- rspec | |
- coverage: | |
requires: | |
- rspec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment