Set up Code Climate with GitHub Actions


This post goes over how to set up Code Climate test reporter with GitHub Actions.

Prerequisites

Given you have a workflow .github/workflows/test.yml:

# .github/workflows/test.yml
name: test
on: push
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      # ...

Setup

Use remarkablemark/setup-codeclimate:

steps:
  - uses: remarkablemark/setup-codeclimate@v2

Assuming your test command is npm test:

steps:
  - uses: remarkablemark/setup-codeclimate@v2
  - run: |
      cc-test-reporter before-build
      npm test
      cc-test-reporter after-build --exit-code $?
    env:
      CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

Example

Full example of .github/workflows/test.yml:

# .github/workflows/test.yml
name: test
on: push
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: remarkablemark/setup-codeclimate@v2
      - run: |
          cc-test-reporter before-build
          npm test
          cc-test-reporter after-build --exit-code $?
        env:
          CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

For more options, check out the readme or examples.



Please support this site and join our Discord!