Skip to main content

CodeAnt AI Coverage Upload for GitLab

Upload test coverage reports to CodeAnt AI for comprehensive analysis, visualization, and tracking of your code coverage metrics.

Features

  • 📊 Upload coverage reports in multiple formats (XML, JSON, LCOV, etc.)
  • 🔍 Automatic coverage analysis and insights
  • 📈 Track coverage trends over time
  • 🎯 Integration with merge requests
  • 🚀 Easy setup with minimal configuration

Usage

Basic Example

include:
  - remote: 'https://gitlab.com/codeant-pipelines/code-coverage-gitlab/-/raw/main/.gitlab-ci.yml'

stages:
  - test
  - report

test:
  stage: test
  image: python:3.9
  script:
    # Your test command that generates coverage report
    - pytest --cov --cov-report=xml
  artifacts:
    paths:
      - coverage.xml

codeant_coverage:
  extends: .codeant_coverage_upload
  stage: report
  needs: [test]
  variables:
    COVERAGE_FILE: "coverage.xml"

Advanced Example

codeant_coverage:
  extends: .codeant_coverage_upload
  stage: report
  needs: [test]
  variables:
    COVERAGE_FILE: "coverage.json"
    API_BASE: "https://api.codeant.ai"
    PLATFORM: "gitlab"
    BASE_URL: "https://gitlab.com"

Inputs

VariableDescriptionRequiredDefault
ACCESS_TOKENGitLab Access Token for authenticationYes-
COVERAGE_FILEPath to the coverage file (e.g., coverage.xml, coverage.json)Yescoverage.xml
API_BASECodeAnt AI API base URLNohttps://api.codeant.ai
PLATFORMGit platform (github, gitlab, bitbucket)Nogitlab
BASE_URLBase URL of the git platformNo$

Supported Coverage Formats

  • Cobertura XML (.xml)
  • JaCoCo XML
  • LCOV (.lcov)
  • JSON coverage reports
  • And more…

Setup

1. Generate Coverage Report

First, ensure your test suite generates a coverage report. Here are examples for common languages: Python (pytest)
pytest --cov --cov-report=xml
JavaScript/TypeScript (Jest)
jest --coverage --coverageReporters=cobertura
Java (Maven)
mvn test jacoco:report
Go
go test -coverprofile=coverage.out ./...
gocov convert coverage.out | gocov-xml > coverage.xml

2. Add CI/CD Variables

Add your CodeAnt AI access token to your GitLab project:
  1. Go to your repository Settings
  2. Navigate to CI/CD > Variables
  3. Click “Add variable”
  4. Key: ACCESS_TOKEN
  5. Value: Your CodeAnt AI access token
  6. Protected: Yes (recommended)
  7. Masked: Yes (recommended)

3. Configure Pipeline

Add the template to your .gitlab-ci.yml as shown in the usage examples above.

How It Works

  1. The job fetches the latest coverage upload script from CodeAnt AI
  2. Decodes and prepares the script for execution
  3. Uploads your coverage report along with commit and branch information
  4. CodeAnt AI processes the report and provides analysis

Examples

Python Project

include:
  - remote: 'https://gitlab.com/codeant-pipelines/code-coverage-gitlab/-/raw/main/.gitlab-ci.yml'

stages:
  - test
  - report

test:
  stage: test
  image: python:3.9
  script:
    - pip install pytest pytest-cov
    - pytest --cov=. --cov-report=xml
  artifacts:
    paths:
      - coverage.xml

codeant_coverage:
  extends: .codeant_coverage_upload
  stage: report
  needs: [test]
  variables:
    COVERAGE_FILE: "coverage.xml"

Node.js Project

include:
  - remote: 'https://gitlab.com/codeant-pipelines/code-coverage-gitlab/-/raw/main/.gitlab-ci.yml'

stages:
  - test
  - report

test:
  stage: test
  image: node:18
  script:
    - npm ci
    - npm test -- --coverage --coverageReporters=cobertura
  artifacts:
    paths:
      - coverage/cobertura-coverage.xml

codeant_coverage:
  extends: .codeant_coverage_upload
  stage: report
  needs: [test]
  variables:
    COVERAGE_FILE: "coverage/cobertura-coverage.xml"

Java Project

include:
  - remote: 'https://gitlab.com/codeant-pipelines/code-coverage-gitlab/-/raw/main/.gitlab-ci.yml'

stages:
  - test
  - report

test:
  stage: test
  image: maven:3.8-openjdk-11
  script:
    - mvn clean test jacoco:report
  artifacts:
    paths:
      - target/site/jacoco/jacoco.xml

codeant_coverage:
  extends: .codeant_coverage_upload
  stage: report
  needs: [test]
  variables:
    COVERAGE_FILE: "target/site/jacoco/jacoco.xml"

Multiple Coverage Files

codeant_coverage_backend:
  extends: .codeant_coverage_upload
  stage: report
  needs: [test_backend]
  variables:
    COVERAGE_FILE: "backend/coverage.xml"

codeant_coverage_frontend:
  extends: .codeant_coverage_upload
  stage: report
  needs: [test_frontend]
  variables:
    COVERAGE_FILE: "frontend/coverage/lcov.info"

Troubleshooting

Coverage file not found
  • Ensure the COVERAGE_FILE path is correct and the file exists as an artifact from a previous job.
Authentication failed
  • Verify that your ACCESS_TOKEN is valid and has the necessary permissions in GitLab CI/CD variables.
Script execution failed
  • Check that the CodeAnt AI API is accessible from your runner environment.

Contributing

Contributions are welcome! Please feel free to submit a Merge Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

I