Skip to content

Instantly share code, notes, and snippets.

@EtienneDepaulis
Last active July 30, 2018 12:47
Show Gist options
  • Select an option

  • Save EtienneDepaulis/8c6a7ce580b650a2a028ccfdc56c871f to your computer and use it in GitHub Desktop.

Select an option

Save EtienneDepaulis/8c6a7ce580b650a2a028ccfdc56c871f to your computer and use it in GitHub Desktop.

Revisions

  1. EtienneDepaulis revised this gist Jul 30, 2018. No changes.
  2. EtienneDepaulis created this gist Jul 30, 2018.
    118 changes: 118 additions & 0 deletions config.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,118 @@
    version: 2
    jobs:
    checkout_code:
    docker:
    - image: circleci/ruby:2.5.1-node-browsers
    - image: circleci/postgres:10.3-alpine
    working_directory: ~/circleci-app
    steps:
    - checkout
    - save_cache:
    key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
    paths:
    - ~/circleci-app
    bundle_dependencies:
    docker:
    - image: circleci/ruby:2.5.1-node-browsers
    - image: circleci/postgres:10.3-alpine
    working_directory: ~/circleci-app
    steps:
    - restore_cache:
    keys:
    - v1-repo-{{ .Environment.CIRCLE_SHA1 }}
    - restore_cache:
    keys:
    - v1-bundle-{{ checksum "Gemfile.lock" }}
    - run: bundle install --path vendor/bundle
    - save_cache:
    key: v1-bundle-{{ checksum "Gemfile.lock" }}
    paths:
    - ~/circleci-app/vendor/bundle
    lint:
    docker:
    - image: circleci/ruby:2.5.1-node-browsers
    environment:
    RAILS_ENV: test
    working_directory: ~/circleci-app
    steps:
    - restore_cache:
    keys:
    - v1-repo-{{ .Environment.CIRCLE_SHA1 }}
    - restore_cache:
    keys:
    - v1-bundle-{{ checksum "Gemfile.lock" }}
    - run: bundle --path vendor/bundle
    - run: git diff-tree -r --no-commit-id --name-only 'origin/develop..HEAD' | xargs --no-run-if-empty bundle exec rubocop --config .rubocop.yml --force-exclusion --fail-level warn
    test:
    docker:
    - image: circleci/ruby:2.5.1-node-browsers
    environment:
    RAILS_ENV: test
    DATABASE_URL: postgres://postgres@127.0.0.1:5432/db_name
    - image: circleci/postgres:10.3-alpine
    environment:
    POSTGRES_USER: root
    POSTGRES_DB: db_name
    working_directory: ~/circleci-app
    steps:
    - restore_cache:
    keys:
    - v1-repo-{{ .Environment.CIRCLE_SHA1 }}
    - restore_cache:
    keys:
    - v1-bundle-{{ checksum "Gemfile.lock" }}
    - run: bundle --path vendor/bundle
    - run:
    name: Wait for DB
    command: dockerize -wait tcp://localhost:5432 -timeout 1m
    - run: bundle exec rails db:create db:schema:load
    - run: bundle exec rspec --color --require spec_helper --format RspecJunitFormatter --out ~/rspec/rspec.xml spec --format progress
    - store_test_results:
    path: ~/rspec
    - store_artifacts:
    path: coverage
    deploy_master:
    docker:
    - image: circleci/ruby:2.5.1-node-browsers
    steps:
    - checkout
    - run:
    name: Deploy master branch to Heroku
    command: |
    git push https://heroku:$HEROKU_API_KEY@git.heroku.com/app-production.git master:master
    deploy_staging:
    docker:
    - image: circleci/ruby:2.5.1-node-browsers
    steps:
    - checkout
    - run:
    name: Deploy develop branch to Heroku
    command: |
    git push https://heroku:$HEROKU_API_KEY@git.heroku.com/app-staging.git develop:master
    workflows:
    version: 2
    main:
    jobs:
    - checkout_code
    - bundle_dependencies:
    requires:
    - checkout_code
    - lint:
    requires:
    - bundle_dependencies
    - test:
    requires:
    - lint
    - deploy_master:
    requires:
    - test
    filters:
    branches:
    only: master
    - deploy_staging:
    requires:
    - test
    filters:
    branches:
    only: develop