How to Set Up Code Climate Analysis in CI
Code Climate analyzes maintainability from a .codeclimate.yml config; the test reporter uploads coverage with your repo test-reporter ID.
Configure engines in .codeclimate.yml, then upload coverage using the cc-test-reporter binary with CC_TEST_REPORTER_ID. Analysis for maintainability runs on the Code Climate side.
Steps
- Add
CC_TEST_REPORTER_IDas a repo secret from Code Climate settings. - Run
before-build, your tests with coverage, thenafter-build. - Tune thresholds and excludes in
.codeclimate.yml.
Workflow
.github/workflows/ci.yml
jobs:
quality:
runs-on: ubuntu-latest
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
steps:
- uses: actions/checkout@v4
- run: |
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
- run: npm ci && npm test -- --coverage
- run: ./cc-test-reporter after-build --exit-code $?.codeclimate.yml
.codeclimate.yml
version: "2"
checks:
method-complexity:
config:
threshold: 10
exclude_patterns:
- "dist/"
- "**/*.test.js"Gotchas
- Pass
--exit-code $?so a failed test run is reported to Code Climate instead of a false green. - The reporter expects an lcov path; set
--coverage-input-type lcovif autodetection misses it.