Skip to content

Latest commit

 

History

History
123 lines (103 loc) · 3.75 KB

language-ruby_5bb9e082042863158cc7236d.md

File metadata and controls

123 lines (103 loc) · 3.75 KB

This guide covers configuring Ruby projects on Semaphore. If you’re new to Semaphore please read our Guided tour first.

Supported Ruby versions

Semaphore uses rbenv to manage Ruby versions. Any version installable with rbenv is supported on Semaphore. You can find the current list of preinstalled versions in the Ubuntu image reference. The default version is set from .ruby-version in your repo. You can change this by calling sem-version ruby 2.5.1. Here's an example:

blocks:
  - name: Tests
    task:
      prologue:
        commands:
          - sem-version ruby 2.5.1
      jobs:
        - name: Tests
          commands:
            - ruby --version

Dependency caching

You can use Semaphores cache command to store and load a gem bundle. This requires setting the BUNDLE_PATH environment variable. In the following configuration example, we install dependencies and warm the cache in the first block, then use the cache in subsequent blocks.

#.semaphore/semaphore.yml
version: "v1.0"
name: Example Ruby pipeline
agent:
  machine:
    type: e1-standard-2
    os_image: ubuntu1804

blocks:
  - name: Install dependencies
    task:
      jobs:
        - name: cache bundle
          commands:
            - checkout
            - cache restore bundle-$(checksum Gemfile.lock)
            - bundle install --deployment
            - cache store bundle-$(checksum Gemfile.lock) vendor/bundle

  - name: Tests
    task:
      prologue:
        commands:
          - checkout
          - cache restore bundle-$(checksum Gemfile.lock)
      env_vars:
        - name: BUNDLE_PATH
          value: vendor/bundle
      jobs:
        - name: Test all the things
          commands:
            - bundle exec rake test

If you need to clear cache for your project, launch a debug session and execute cache clear or cache delete <key>.

Environment variables

Semaphore doesn't set language specific environment variables like RAILS_ENV or RACK_ENV. You can set these at the task level.

blocks:
  - name: Tests
    task:
      env_vars:
        - name: RACK_ENV
          value: test
      jobs:
        - name: Everything
          commands:
            - bundle exec rake test

C-Extensions & system dependencies

Projects may need system packages to install gems like pg. Semaphore provides full sudo access so you may install all required packages. Here's an example of installing the pg gem.

blocks:
  - name: Tests
    task:
      prologue:
        commands:
          - sudo apt-get update && sudo apt-get install -y libpq-dev
          - gem install pg
      jobs:
        - name: Everything
          commands:
            - bundle exec rake test

Browser testing

Capybara is the recommended solution for browser tests in Ruby. The Firefox, Chrome, and Chrome Headless drivers work out of the box.

Refer to the Ubuntu image reference for details on preinstalled browsers and testing tools on Semaphore.