Skip to content

Instantly share code, notes, and snippets.

@qortex
Created April 2, 2020 21:56
Show Gist options
  • Save qortex/7e7c49f3731391a91ee898336183acef to your computer and use it in GitHub Desktop.
Save qortex/7e7c49f3731391a91ee898336183acef to your computer and use it in GitHub Desktop.
#!/bin/bash
# See https://github.com/codeclimate/test-reporter/issues/226
# And https://github.com/codeclimate/test-reporter/pull/305
export CI_NAME="heroku"
export GIT_COMMITTED_AT="$(date +%s)"
# Run the ruby test suite
bundle exec rake
RETURN_VALUE=$?
ruby_filename="coverage/codeclimate.rb.json"
# Dirty hack until this is fixed: https://github.com/codeclimate/test-reporter/issues/413
ruby scripts/transform.rb
# Format ruby coverage
./cc-test-reporter format-coverage "coverage/.resultset.json" --input-type simplecov # --output $ruby_filename
# Send to codeclimate
./cc-test-reporter upload-coverage
# Send status code of the test run
./cc-test-reporter after-build --exit-code $RETURN_VALUE --coverage-input-type simplecov
#!/bin/bash
# download the codeclimate test reporter
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
#! /bin/ruby
# Temporary hack to get CodeClimate to work with SimpleCov 0.18 JSON format until issue is fixed
# upstream: https://github.com/codeclimate/test-reporter/issues/413
require 'json'
filename = 'coverage/.resultset.json'
contents = JSON.parse(File.read(filename))
def remove_lines_key(obj)
case obj
when Hash
obj.transform_values do |val|
val.is_a?(Hash) && val.key?('lines') ? val['lines'] : remove_lines_key(val)
end
else
obj
end
end
# overwrite
File.write(filename, JSON.generate(remove_lines_key(contents)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment