0

Circle CI (part 2)

In my previous post on Circle CI (part 1) we can get some basic concept on Circle CI. In todays post, I will try to describe some common components whice are very important to understand for configuring Circle CI file circle.yml. In this post i will try to describe -

  • Machine configuration
  • Project-specific dependencies
  • Database setup
  • Running your tests

Machine configuration

The machine section enables you to configure the virtual machine that runs your tests. Here’s an illustration of the types of things you might typically set in the machine section of the file.

machine:
  timezone:
    America/Los_Angeles
  ruby:
    version: 1.9.3-p0-falcon

test:
  post:
    - bundle exec rake custom:test:suite

This example sets the time zone, chooses a Ruby version and patchset, and adds a custom test command to run after the rest of your commands. In machine configuration section, we can configure

  • Environment
  • Timezone
  • Hosts
  • Ruby version
  • Node.js version
  • Java version
  • PHP version
  • Python version
  • GHC version
  • Databases and other services

Project-specific dependencies

Most web programming languages and frameworks, including Ruby’s bundler, npm for Node.js, and Python’s pip, have some form of dependency specification; CircleCI automatically runs commands to fetch such dependencies.You can use override, pre, and/or post to modify dependencies commands. Here are examples of common tweaks you might make in the dependencies section.

Example: using npm and Node.js

dependencies:
  override:
    - npm install

Example: using a specific version of bundler

dependencies:
  pre:
    - gem uninstall bundler
    - gem install bundler --pre

Database setup

Your web framework typically includes commands to create your database, install your schema, and run your migrations. You can use override, pre, and/or post to modify database commands. See Setting up your test database for more information.If our inferred database.yml isn’t working for you, you may need to override our setup commands as shown in the following example.

database:
  override:
    - mv config/database.ci.yml config/database.yml
    - bundle exec rake db:create db:schema:load --trace

You have the option of pointing to the location of your stored database config file using the environment modifier in the machine section.

machine:
  environment:
    DATABASE_URL: postgres://ubuntu:@127.0.0.1:5432/circle_test

Running your tests

The most important part of testing is actually running the tests! CircleCI supports the use of override, pre, and/or post in the test section. However, this section has one minor difference: all test commands will run, even if one fails. This allows our test output to tell you about all the tests that fail, not just the first error.

Example: running spinach after RSpec

test:
  post:
    - bundle exec rake spinach:
        environment:
          RAILS_ENV: test

Example: running phpunit on a special directory

test:
  override:
    - phpunit my/special/subdirectory/tests

CircleCI also supports the use of minitest_globs (a list of file globs, using Ruby’s Dir.glob syntax) that can list the file globs to be used during testing. By default, when testing in parallel, CircleCI runs all tests in the test/unit, test/integration, and test/functional directories. You can add minitest_globs to replace the standard directories with your own. This is needed only when you have additional or non-standard test directories and you are testing in parallel with MiniTest.

Example: minitest_globs

test:
  minitest_globs:
    - test/integration/**/*.rb
    - test/extra-dir/**/*.rb

Here is the end of todays part. Related referance - https://circleci.com


All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí