Created
November 20, 2017 00:19
-
-
Save henrypoydar/3685d1cd38bd591bbe566e5053c229d6 to your computer and use it in GitHub Desktop.
Rails 5.1 CircleCI 2.0 Configuration
This file contains hidden or 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 | |
jobs: | |
build: | |
environment: | |
working_directory: ~/circleci-myapp | |
docker: | |
- image: circleci/ruby:2.4.2-node-browsers | |
environment: | |
CC_TEST_REPORTER_ID: XXXYYY | |
RAILS_ENV: test | |
TEST_REPORT_PATH: "test/reports" | |
- image: circleci/postgres:9.6.2-alpine | |
environment: | |
POSTGRES_USER: circleci | |
parallelism: 2 | |
steps: | |
- checkout | |
# Restore bundle cache | |
- type: cache-restore | |
key: myapp-bundle-{{ checksum "Gemfile.lock" }} | |
# Restore yarn cache | |
- type: cache-restore | |
key: myapp-yarn-{{ checksum "yarn.lock" }} | |
# Install gem dependencies | |
- run: bundle install --path vendor/bundle | |
# Install Javascript dependencies | |
- run: bin/yarn install | |
# Store bundle cache | |
- type: cache-save | |
key: myapp-bundle-{{ checksum "Gemfile.lock" }} | |
paths: | |
- vendor/bundle | |
# Store yarn cache | |
- type: cache-save | |
key: myapp-yarn-{{ checksum "yarn.lock" }} | |
paths: | |
- ~/.yarn-cache | |
# Database setup | |
- run: bin/rails db:create | |
- run: bin/rails db:schema:load | |
# Code Climate setup | |
- run: curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter | |
- run: chmod +x ./cc-test-reporter | |
- run: sudo apt-get -y -qq install awscli | |
- run: aws s3 rm s3://myapp/coverage/$CIRCLE_PREVIOUS_BUILD_NUM --recursive | |
# Run Ruby unit tests and app integration tests in parallel | |
- type: shell | |
command: | | |
bin/rails test $(circleci tests glob "test/**/*_test.rb" | circleci tests split --split-by=timings) | |
# Run Javascript unit tests | |
- run: yarn test | |
# Code Climate coverage, split for parallel nodes | |
- run: ./cc-test-reporter format-coverage --output "coverage/codeclimate.$CIRCLE_NODE_INDEX.json" | |
- run: aws s3 sync coverage/ "s3://myapp/coverage/$CIRCLE_BUILD_NUM" | |
# Run security scan | |
- run: bundle exec brakeman | |
# Save artifacts | |
- type: store_test_results | |
path: test/reports | |
# `deploy` runs only on node 0 after parallel steps have finished | |
# Upload results from all parallel nodes to Code Climate | |
- deploy: | |
command: | | |
aws s3 sync "s3://myapp/coverage/$CIRCLE_BUILD_NUM" coverage/ | |
./cc-test-reporter sum-coverage --output - --parts $CIRCLE_NODE_TOTAL coverage/codeclimate.*.json | ./cc-test-reporter upload-coverage --input - | |
@monfresh @HoyaBoya i am having an error at this line - run: ./cc-test-reporter format-coverage --output "coverage/codeclimate.$CIRCLE_NODE_INDEX.json"
at this line and it says Error: could not find any viable formatter. available formatters: clover, cobertura, coverage.py, excoveralls, gcov, gocov, jacoco, lcov, simplecov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@monfresh nice comment. I needed to do the same steps with
sudo pip install awscli
as well to get around aseek
error in my upload of coverage results.Nice contribution @henrypoydar.