Skip to main content

Setup: Rails && GitHub Actions

Overview

GitHub Actions workflow diagram showing 3 phases: Building, Fan-out Testing, Fan-in summarizing step

Before starting this guide, you should have done the general setup for Rails applications.

This guide assumes that your CI workflow is fan-out fan-in pattern. If you only have 1 test job, you can just do the simple translate_oyencov and submit steps. There is no need to upload/download artifact and collate them.


Set your GitHub Actions secret

Adding GitHub Actions Secret

You will need to set OYENCOV_API_KEY in your settings first.

  1. From your GitHub repository page, click Settings
  2. Secret and variables > Actions
  3. "New repository secret"
  4. Name: OYENCOV_API_KEY. Secret: the alphanumerical key you were given on your page.

If you have a simple single test job setup

In this case, there is no need to upload the artifacts generated by OyenCov gem. You still need to run translate_simplecov and submit it.

These are what you need to add to your workflow yaml:

.github/workflow.yml
jobs:
# building:
# steps:
testing:
steps:
# - run: bundle exec rspec
# # Above: Your usual commands to prepare and start tests
# # Below: After the tests are done
- run: bundle exec oyencov translate_simplecov
- run: bundle exec oyencov submit --git-commit-sha $GITHUB_SHA

If you have multiple parallel test jobs

You will need to store the OyenCov resultset from every fan-out jobs in the CI's artifact storage, have 1 summarizing job afterward to pull them, collate them, submit them to OyenCov. Here's how to do it.

Fan-out Testing Phase

Upload both oyencov and simplecov resultsets as job artifacts by adding the steps below:

jobs:
# building:
# steps:
testing:
steps:
# - run: bundle exec rake rspec_chunked
# # Above: Your usual testing jobs
- run: bundle exec oyencov translate_simplecov
- run: 'mkdir -p tmp/coverage-jsons; mv coverage/.resultset.json coverage/oyencov-resultset.json tmp/coverage-jsons/;'
- uses: actions/upload-artifact@v3
with:
name: coverage-jsons-${{ matrix.ci_job }}
path: tmp/coverage-jsons/
# summarizing:

Fan-in Summarizing Phase

Put this in your summarising fan-in job at the end of your workflow.

Ensure actions/download-artifact is run to pull the resultset files generated in previous jobs.

jobs:
# testing:
summarizing:
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
# ... other steps ...
# - name: Set up bundler cache
# uses: ruby/setup-ruby@v1
# with:
# ruby-version: ${{ matrix.ruby-version}}
# bundler-cache: true
# ... other existing steps ...
- run: bundle exec oyencov submit --files coverage-jsons-*/oyencov-resultset.json --git-commit-sha $GITHUB_SHA
env:
OYENCOV_API_KEY: ${{ secrets.OYENCOV_API_KEY }}