Using CircleCI 2.0
deploy step and circleci api v1.1 to merge SimpleCov coverage files of parallel builds
CircleCI 2.0 deploy step doc
- Using this we don't HAVE to use workflows.
- We get to keep rebuild without cache button. (YAY!!)
- We don't have to spin up another container, this work is done in container 0 which is already setup with all configurations etc. So it is bit faster.
I was able to configure this properly and get html report generated using parts from both gists i have mentioned in the main doc in this gist.
Some issues i faced were that coverage was not realistically accurate, issue was that i was initializing simplecov a bit late, i move it above all other includes etc.
This is literally how beginning looks in my
dir = File.join(ENV['CIRCLE_ARTIFACTS'], 'coverage')
SimpleCov.start 'rails' do
Merge code is in
CirclieCI api token setting
simplecov_merger.rb file(attached in this gist). I choose to run this ruby code directly instead of rake task. You can obviously choose however you want to use this code.
You also have to generate a circleci API token for an account which has access to this project on circleci, and set that api token in an env_var in project settings. That environment variable will be available for you than with the name you choose. Replace
API_TOKEN in the
simplecov_merger.rb file with that environment variable. You probably don't want to commit this token to git as anyone having this token can do whatever he want on circleci.
CircleCI doc on environemtn variables and CircleCI doc for managing your API tokens
Note: To use this file as is without rake tasks, you have to give this file execute permission(using chmod) before committing it in your git repo.
Following is how my
.circleci/config.yml file calls this code:
# Store generated coverage for each build(lookout if you have set a different directory, in which case you will also have to change in rb file)
# Make directory to store aggregated/combined results
name: Stash Coverage Results
# This is magic step, which actually will combine coverage reports of all parallel containers
name: Merge and copy coverage data
RUN_COVERAGE=true bundle exec spec/simplecov_merger.rb
# without RUN_COVERAGE=true you wont get html coverage report generated
# Now store the results so we can see them in artifacts(coverage report will only be in container 0 as described earlier)