Skip to content

Instantly share code, notes, and snippets.

@yihyang
Created September 13, 2018 06:47
Show Gist options
  • Select an option

  • Save yihyang/28dd5ff0d2de7f4a74a059e16cd083b5 to your computer and use it in GitHub Desktop.

Select an option

Save yihyang/28dd5ff0d2de7f4a74a059e16cd083b5 to your computer and use it in GitHub Desktop.
CircleCI Config to run multiple test using workflow
# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
# TODO: Remove the following when CircleCI Image is using newer version
# Refer to issue here: https://discuss.circleci.com/t/session-not-created-exception-chrome-version-must-be-62-0-3202-0/19258
install_chrome: &install_chrome
name: Install Chrome
command: |
sudo apt-get update
sudo apt-get install libappindicator3-1
curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome.deb
sudo sed -i 's|HERE/chrome\"|HERE/chrome\" --disable-setuid-sandbox|g' /opt/google/chrome/google-chrome
rm google-chrome.deb
version: 2
jobs:
build_product_b:
working_directory: ~/repo
docker:
# specify the version you desire here
- image: circleci/ruby:2.4.1-node-browsers
environment:
- RAILS_ENV: test
- RACK_ENV: test
- DATABASE_URL: postgres://ubuntu@localhost:5432/product_b_test
- image: circleci/postgres:9.5-alpine
environment:
- POSTGRES_USER: ubuntu
- POSTGRES_DB: product_b_test
- POSTGRES_PASSWORD: ""
- image: circleci/mongo:latest
steps:
- checkout
- run:
<<: *install_chrome
# Download and cache dependencies
- restore_cache:
name: Restore gems cache
keys:
- product_b-gems-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
# fallback to using the latest cache if no exact match is found
- product_b-gems-{{ .Branch }}
- product_b-gems-
- run:
name: install dependencies
command: bundle install --jobs 4 --retry 3 --path vendor/bundle
- save_cache:
name: Save gems cache
key: product_b-gems-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths: vendor/bundle
# Javascript dependencies
- restore_cache:
name: Restore node_modules cache
keys:
- product_b-node-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
# fallback to using the latest cache if no exact match is found
- product_b-node-{{ .Branch }}
- product_b-node-
- run:
name: install javascript dependencies
command: yarn install
- save_cache:
name: Save node_modules cache
key: product_b-node-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths: node_modules
# Database setup
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Setup DB
command: |
bundle exec rake db:create
bundle exec rake db:migrate --trace
- run:
name: Setup .env
command: |
cp .env.sample .env
- run:
name: Setup mongoid
command: |
cp config/mongoid.yml.sample config/mongoid.yml
# Precompile assets
# Load assets from cache if possible, precompile assets then save cache
- restore_cache:
name: Restore assets cache
keys:
- product_b-assets-{{ .Branch }}-
- product_b-assets-{{ .Branch }}
- product_b-assets
- run:
name: Compile assets
command: bundle exec rake assets:precompile assets:clean RAILS_ENV=test
- save_cache:
name: Saving assets cache
key: product_b-assets-{{ .Branch }}-{{ epoch }}
paths:
- public/assets
- tmp/cache/assets/sprockets
# run tests!
- run:
name: run tests
command: |
mkdir /tmp/test-results
bundle exec rspec --format RspecJunitFormatter \
--out /tmp/test-results/rspec.xml \
--format documentation \
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
# collect reports
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
destination: test-results
- store_artifacts:
path: /home/circleci/project/tmp/capybara
destination: capybara
build_product_a:
working_directory: ~/repo
docker:
# specify the version you desire here
- image: circleci/ruby:2.4.1-node-browsers
environment:
- RAILS_ENV: test
- RACK_ENV: test
- DATABASE_URL: postgres://ubuntu@localhost:5432/product_a_test
- image: circleci/postgres:9.5-alpine
environment:
- POSTGRES_USER: ubuntu
- POSTGRES_DB: product_a_test
- POSTGRES_PASSWORD: ""
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- product_a-gems-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
# fallback to using the latest cache if no exact match is found
- product_a-gems-{{ .Branch }}
- product_a-gems-
- run:
<<: *install_chrome
- run:
name: install dependencies
command: cd ~/repo/lib/product_a && bundle install --jobs=4 --retry=3 --path vendor/bundle
- save_cache:
key: product_a-gems-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
# Database setup
- run:
name: Wait for DB
command: |
dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Setup DB
command: |
cd ~/repo/lib/product_a && bundle exec rake db:create --trace
cd ~/repo/lib/product_a && bundle exec rake db:migrate --trace
# Setup Environment variables
- run:
name: Setup .env
command: |
cd ~/repo/lib/product_a && cp .env.sample .env
# run tests!
- run:
name: run tests
command: |
mkdir /tmp/test-results
cd ~/repo/lib/product_a && bundle exec rspec --format documentation \
--format RspecJunitFormatter \
--out /tmp/test-results/rspec.xml \
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
# collect reports
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
destination: test-results
- store_artifacts:
path: /home/circleci/project/spec/dummy_app/tmp/capybara
destination: capybara
workflows:
version: 2
build:
jobs:
- build_product_a
- build_product_b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment