-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Heroku CI rails app test coverage #226
Comments
Thanks, @a-b. We're still working on getting the required environment variables from Heroku CI as mentioned in this comment. Please stand by! |
Update: Heroku now supports a |
Cross-posting this comment: @dblandin mentioned: Hey @joshwlewis,
|
Hey @a-b, We've discussed this internally and while we're waiting on Heroku to support this environment variable via Heroku CI, you can use the following (not entirely recommended) workaround:
This fakes the git commit "committed at" data point with the current time. Note that this might produce undesirable behavior when rendering test coverage information on codeclimate.com or annotations on github.com (via the Code Climate browser extension) where we depend upon accurate committed at data, but that should be fairly uncommon. |
Is there a recommended way to install/setup |
Hey @dja, you can use the workaround posted in #226 (comment). Just be aware that there might be some weirdness rendering data if the generated data and |
I have this almost fully working, except getting this issue when passing the workaround The date as formatted is I'm setting variables as so:
|
Hey @dja, It looks like your subshell value isn't excuting correctly. I think that's because you're wrapping the subshell command in single quotes which doesn't trigger interpolation. I'm also wondering if you're Could you try the following? export CI_BUILD_ID="$HEROKU_TEST_RUN_ID"
export CI_NAME="heroku"
export GIT_BRANCH="$HEROKU_TEST_RUN_BRANCH"
export GIT_COMMIT_SHA="$HEROKU_TEST_RUN_COMMIT_VERSION"
export GIT_COMMITTED_AT="$(date +%s)" |
That helped, but getting this error:
|
As far as I can tell, this setup is working on Heroku CI. We have an rspec test suite with simplecov and a mocha/chai/sinon/enzyme test suite run by karma and reporting via istanbul.
{
"environments": {
"test": {
"addons": [
"heroku-postgresql"
],
"buildpacks": [
{ "url": "heroku/nodejs" },
{ "url": "https://github.com/heroku/heroku-buildpack-google-chrome" },
{ "url": "heroku/ruby" }
],
"env": {
"NODE_ENV": "test",
"RAILS_ENV": "test"
},
"scripts": {
"test-setup": "./script/ci_setup",
"test": "./script/ci"
}
}
}
}
#!/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/bash
export CI_BUILD_ID="$HEROKU_TEST_RUN_ID"
export CI_NAME="heroku"
export GIT_BRANCH="$HEROKU_TEST_RUN_BRANCH"
export GIT_COMMIT_SHA="$HEROKU_TEST_RUN_COMMIT_VERSION"
export GIT_COMMITTED_AT="$(date +%s)"
ruby_filename="coverage/codeclimate.rb.json"
js_filename="coverage/codeclimate.js.json"
# run the ruby test suite
bundle exec rake spec
# format ruby coverage
./cc-test-reporter format-coverage --output $ruby_filename
# run the JS test suite
yarn test
# format js coverage
./cc-test-reporter format-coverage --input-type lcov --output $js_filename coverage/karma/lcov.info
# sum code coverage and send to codeclimate
./cc-test-reporter sum-coverage $ruby_filename $js_filename
./cc-test-reporter upload-coverage P.S. 👋 @dblandin |
Heroku CI currently exposes the following environment variables during CI builds: - `HEROKU_TEST_RUN_BRANCH`: A string representing the branch of the commit under test - `HEROKU_TEST_RUN_COMMIT_VERSION`: A string representing the commit version under test (This is the SHA in most cases) - `HEROKU_TEST_RUN_ID`: A string uuid representing the unique ID of the test run source: https://devcenter.heroku.com/articles/heroku-ci#configuration-using-app-json The Code Climate test reporter relies on a git committed at timestamp to reliably render accurate test coverage annotations on codeclimate.com and on github.com via the browser extension. For now, we can automatically apply the environment variables supported by Heroku CI, but a couple others will have to be manually supplied by the user: ``` export CI_NAME="heroku" export GIT_COMMITTED_AT="$(date +%s)" ``` Related to: #226
Heroku CI currently exposes the following environment variables during CI builds: - `HEROKU_TEST_RUN_BRANCH`: A string representing the branch of the commit under test - `HEROKU_TEST_RUN_COMMIT_VERSION`: A string representing the commit version under test (This is the SHA in most cases) - `HEROKU_TEST_RUN_ID`: A string uuid representing the unique ID of the test run source: https://devcenter.heroku.com/articles/heroku-ci#configuration-using-app-json The Code Climate test reporter relies on a git committed at timestamp to reliably render accurate test coverage annotations on codeclimate.com and on github.com via the browser extension. For now, we can automatically apply the environment variables supported by Heroku CI, but a couple others will have to be manually supplied by the user: ``` export CI_NAME="heroku" export GIT_COMMITTED_AT="$(date +%s)" ``` Related to: #226
Hey @TaylorBriggs!! 👋 I just merged and released #305 which brings in support for the environment variables currently available during Heroku CI builds. Not all the way there yet, but at least you can remove a few of those export lines now 😄 @joshwlewis Any update on support for the |
Thanks @dblandin! |
@joshwlewis @appleton We just switched to HerokuCI and noticed the incomplete support for Code Climate. Any update on the Details in this issue and: Thanks! |
@TaylorBriggs's solution worked perfectly for code coverage, but we found that Heroku CI wouldn't report failing tests with that. Not sure if it's our RSpec config, but just want to give a heads up so others can make sure their test failures are being reported properly. Will send another update if we figure it out. |
@sergiopantoja I ran into the issue with Heroku CI not reporting the test failures. I updated my script as follows to catch the error code and exit the script: #!/bin/bash
exit_if_error() {
if [ $1 -ne 0 ]; then
exit 1
fi
}
export CI_NAME="heroku"
export GIT_COMMITTED_AT="$(date +%s)"
ruby_filename="coverage/codeclimate.rb.json"
js_filename="coverage/codeclimate.js.json"
# lint the ruby code
bin/rubocop
exit_if_error $?
# ruby test suite
bin/rake spec
exit_if_error $?
./cc-test-reporter format-coverage --output $ruby_filename
# JS linting and test suite
yarn test
exit_if_error $?
./cc-test-reporter format-coverage --input-type lcov --output $js_filename coverage/karma/lcov.info
# sum code coverage and send to codeclimate
./cc-test-reporter sum-coverage $ruby_filename $js_filename
./cc-test-reporter upload-coverage |
I haven't been working on that project since March, but it was working as of then. Maybe Heroku CI has changed since so you may need to adjust accordingly. |
I'd suggest considering adding e.g.
|
@TaylorBriggs @wfleming Man you guys are great! Thanks so much for the quick response and help. 🙏 |
@sergiopantoja you can also pass an exit status to the reporter like ./run-tests.sh
RETURN_VALUE=$?
./cc-test-reporter after-build --exit-code $RETURN_VALUE or what we do (since ^^ seems unecessary) #!/bin/bash
export CI_NAME="heroku"
export GIT_COMMITTED_AT="$(date +%s)"
bin/rspec
RETURN_VALUE=$?
./cc-test-reporter after-build
exit $RETURN_VALUE The downside of |
Any updates on how to setup up CodeClimate reporting on Heroku CI? I am having some of the same issues. |
Please include Heroku CI specific manual, how to run test coverage for rails app.
Inspired by codeclimate/ruby-test-reporter#183
The text was updated successfully, but these errors were encountered: