Skip to content

SimpleCov Semaphore Codeclimate

Letícia Oliveira edited this page Apr 12, 2022 · 2 revisions

This is a simplified tutorial on how to integrate Simplecov test coverage, using a semaphore build, and export the test coverage to codeclimate, or at least how I did it.

First, you need to install SimpleCOv gem.

You must have semaphore and codeclimate integrated with your Github account(duh).

Download cc-test-reporter (Read more here) or download the latest version (linux). Put it in your repository folder.

Go to your CodeClimate account and find your CC_TEST_REPORTER_ID. This is the key that will allow you to post your test coverage results to codeclimate.

Now, on Semaphore, there are two ways to go. One is to configure your build (tests of your application) on the platform, or creating a .semaphore/semaphore.yml file on your repo to configure manually your semaphore builds/jobs.

If you're going with Semaphore website, add CC_TEST_REPORTER_ID to the build secrets.

If you're editing your semaphore.yml file,

blocks:
  - name: Test
    task:
      env_vars:
        - name: CC_TEST_REPORTER_ID
          value: PASTE_YOUR_KEY_HERE
    jobs:
      - name: Test
        commands:
          - checkout
          - bundle install
          - bundle exec rspec

On your test build on semaphore or on your semaphore.yml local file, add these lines after bundle install and bundle exec rspec:

- chmod +x ./cc-test-reporter
- ./cc-test-reporter format-coverage coverage/.resultset.json --input-type simplecov
- ./cc-test-reporter upload-coverage

semaphore.yml Example file:

version: v1.0
name: Ruby
agent:
  machine:
    type: e1-standard-2
    os_image: ubuntu2004
blocks:
  - name: RSpec
    task:
      env_vars:
        - name: CC_TEST_REPORTER_ID
          value: KEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEY
      jobs:
        - name: rspec
          commands:
            - checkout
            - sem-version ruby 3.0.0
            - bundle config set --local deployment 'true'
            - bundle config set --local path 'vendor/bundle'
            - bundle install
            - yarn install
            - bundle exec rspec --format documentation
            - chmod +x ./cc-test-reporter
            - ./cc-test-reporter format-coverage coverage/.resultset.json --input-type 'simplecov'
            - ./cc-test-reporter upload-coverage
Clone this wiki locally