Check now ๐
GitHub Action to upload SimpleCov Coverage Results
This post was originally published on my previous blog jer-k.github.io
Published on 2019-10-16
What a wonderful day that was! I've been playing around with Actions ever since and one of my new projects, a Ruby Gem, didn't have any form of CI as of this morning. I set out to create an Action that would run the tests for the gem and produce coverage results via SimpleCov. While it's nothing too extravagant, there was a small nuance that I had to resolve and I decided I wanted to share that info.
Let's start off with some changes to the SimpleCov
configuration.
This ensures that the coverage is above 90% and any changes in the future must not drop the coverage by more than 2%.
The Gem, in its infancy, does not pass this requirement. Due to that failure, I had to figure out why the Action was not
uploading the coverage results. Remember to put the SimpleCov
code at the very top of spec_helper.rb
, before you do
require 'your_gem'
to ensure it knows what files to track.
Now let's look at the Action, which is based off the default Ruby Action supplied by GitHub.
The only additions are the last step.
It uses the upload-artifact Action created by Github to upload the coverage/
folder generated by SimpleCov
. At first, I could not figure out why the artifact was never being uploaded, but I
realized that the step was never being run. We can see this in the Actions UI.
The key to making this work is the if: always()
clause. Looking at the documentation for
Contexts and Expression Syntax, always()
is described as Forces a conditional to evaluate as true, even when canceled.
Since SimpleCov
is failing the Build and test with Rake
step, we have to force the Upload coverage results
step to
always run. After adding in the if clause, we can see a successful upload in the Actions UI.
Next we scroll to the top of the page and download the artifact, which is a zip file of the coverage/
folder.
Inside the folder we can open the generated index.html
to see which files we didn't have coverage for.
Now we can successfully check the coverage report on our gem and see where the tests are lacking. Hopefully your gem has better coverage than mine!
You can find the file in my actions repository, or directly here