Code Coverage with Code Climate

I’m attempting to send code coverage to code climate using a github action:

https://github.com/ksylvest/tights/blob/master/.github/workflows/test.yml#L17-L25

curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter format-coverage -t lcov coverage/lcov.info
./cc-test-reporter upload-coverage

This works - but seems to be missing a “GIT_BRANCH” variable:

https://docs.codeclimate.com/docs/test-coverage-troubleshooting-branch-names#section-check-your-cis-environmental-variable-names

Does anyone have experience with configuring this?

1 Like

Hi @ksylvest.,

Thanks for being here and apologies for the delay, we’ve looked internally to see if there were any setup examples with code climate and have not found any workflows to share, I wonder if reaching out to them directly might help? https://github.com/codeclimate

I’m afraid that we don’t set the GIT_BRANCH environment variable.  We do, however, set the GITHUB_REF variable, which should be able to be used.  You should be able to remove the leading refs/heads/ prefix from that variable and set it to GIT_BRANCH.  For example:

export GIT_BRANCH="${GITHUB_REF/refs\/heads\//}"

curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter format-coverage -t lcov coverage/lcov.info
./cc-test-reporter upload-coverage
3 Likes

Hi there,
I’m having a hard time making Code Coverage work: I have a GitHub action running CI (RSpec specifications) and once done I post the simplecov outcome to Code Climate. The upload to Code Climate is successful and no error is displayed. However, even if I set the GIT_BRANCH variable, the value passed to Code Climate is always HEAD (I have also unsuccessfully tried to hardcode a test value as GIT_BRANCH).

My steps look like

- name: Install Code Climate reporter
        run: |
          export GIT_BRANCH="${GITHUB_REF/refs\/heads\//}"
          sudo curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
          sudo chmod +x ./cc-test-reporter

...
RUN RSPEC
...

- name: Upload coverage information
        env:
          CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE_ID }}
        run: |
          sudo ./cc-test-reporter after-build -r $CC_TEST_REPORTER_ID

Any ideas why the GIT_BRANCH isn’t correctly passed to Code Climate?

Thanks.