Uploading Code Coverage using API - DEPRECATED and will be removed in the future¶
API Details - DEPRECATED and will be removed in the future¶
Given that you have code coverage data produced and present on disk, uploading the coverage data to the CodeScene API requires a few discrete steps:
compress the data into
gzip
formatThe maximum size of the compressed data to upload must not exceeed 8 Mb.
request the upload and specify metadata using the
code-coverage/upload
POST endpointupload the compressed data using the
code-coverage/upload/[ID]
PUT endpoint.
To make this process simpler, CodeScene provides upload scripts that encapsulates these steps into a single script call.
Example for GitHub Actions - DEPRECATED and will be removed in the future¶
Uploading Code Coverage data to CodeScene from a build pipeline means inserting an upload step after test steps that produce coverage data have run. For GitHub actions this can be accomplished by adding a step similar to this:
- name: Upload coverage data to CodeScene
run: |
curl -Os https://downloads.codescene.io/code-coverage/linux/upload.sh
chmod +x upload.sh
./upload.sh \
--repopath "$(pwd)" \
--format open-clover \
--metric statement-coverage \
--file coverage/clover.xml
env:
CS_HOST: ${{ secrets.CS_HOST }}
CS_USER: ${{ secrets.CS_USER }}
CS_PASSWORD: ${{ secrets.CS_PASSWORD }}
shell: bash
This downloads the upload script and runs it with proper arguments.
Example script for Windows - DEPRECATED and will be removed in the future¶
Windows (power shell)
Usage: upload.ps1 -repopath "value" -file "absolute-path-to-the-code-coverage-file" [-subpath "value"] [-format "value"] [-metric "value"]
This script can be used with CodeScene Cloud (codescene.io) or CodeScene On-Prem (see codescene.com)
You need to set the following environment variables:
- CS_USERNAME - the CodeScene API username (only CodeScene On-Prem)
- CS_PASSWORD - the CodeScene API password (only CodeScene On-Prem)
or
- CS_TOKEN - the CodeScene API token (CodeScene Cloud or CodeScene On-Prem)
Parameters:
-cshost - if not specified will try to get the value from environment variable CS_HOST, if not found will upload to CodeScene Cloud
-repopath - absolute path to the cloned git repository, ex: /home/myuser/repos/codescene
-subpath - in case you have a monorepo with more then one project you can set the subpath, ex: /frontend
-format - the code-coverage file format, if not specified the default is: lcov
-metric - the code-coverage metric, if not specified the default is: line-coverage
-file - the absolute path to the file containg code-coverage information
#Example
#---------------------
#upload code coverage data on-prem
$Env:CS_HOST="http://localhost:3003"
$Env:CS_USERNAME="test"
$Env:CS_PASSWORD="test"
upload.ps1 -repopath "c:\tmp\myproject" -subpath "\frontend" -file c:\tmp\coverage/lcov.info
#trigger new analysis on-prem for project with id 123
$Env:PROJECT_ID=123
$CREDENTIALS = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$Env:CS_USERNAME`:$Env:CS_PASSWORD"))
$HEADER = @{
"Authorization"="Basic $CREDENTIALS"
"Content-Type"="application/json"
}
curl -Method POST -Headers $HEADER $Env:CS_HOST/api/v2/projects/$Env:PROJECT_ID/run-analysis -Body ""
#---------------------
#upload code coverage data cloud
$Env:CS_TOKEN="<your_token_here>"
upload.ps1 -repopath "c:\tmp\myproject" -subpath "\frontend" -file c:\tmp\coverage/lcov.info
#trigger new analysis on-prem for project with id 123
$Env:PROJECT_ID=123
$HEADER = @{
"Authorization"=""Bearer $Env:CS_TOKEN""
"Content-Type"="application/json"
}
curl -Method POST -Headers $HEADER http://api.codecene.io/v2/projects/$Env:PROJECT_ID/run-analysis -Body ""
Example script for Mac and Linux - DEPRECATED and will be removed in the future¶
Linux or Mac
Usage: upload.sh --repopath "value" --file "absolute-path-to-the-code-coverage-file" [--subpath "value"] [--format "value"] [--metric "value"]
This script can be used with CodeScene Cloud (codescene.io) or CodeScene On-Prem (see codescene.com)
You need to set the following environment variables:
- CS_USERNAME - the CodeScene API username (only CodeScene On-Prem)
- CS_PASSWORD - the CodeScene API password (only CodeScene On-Prem)
or
- CS_TOKEN - the CodeScene API token (CodeScene Cloud or CodeScene On-Prem)
Parameters:
--cshost - if not specified will try to get the value from environment variable CS_HOST, if not found will upload to CodeScene Cloud. Ex: https://example.com
--repopath - absolute path to the cloned git repository, ex: /home/myuser/repos/codescene
--subpath - in case you have a monorepo with more then one project you can set the subpath, ex: /frontend
--format - the code-coverage file format, if not specified the default is: lcov
--metric - the code-coverage metric, if not specified the default is: line-coverage
--file - the absolute path to the file containg code-coverage information
#Example on-prem and cloud version
#---------------------
#upload code coverage data on-prem
CS_HOST=http://localhost:3003 CS_USERNAME=test CS_PASSWORD=test bash upload.sh --repopath "/tmp/myproject" --subpath "/frontend" --file /tmp/coverage/lcov.info
#trigger new analysis on-prem for project with id 123
PROJECT_ID=123
curl -X 'POST' \
-u "${CS_USERNAME}:${CS_PASSWORD}" \
'${CS_HOST}/api/v2/projects/{PROJECT_ID}/run-analysis' \
-H 'accept: application/json' \
-d ''
#---------------------
#upload code coverage data cloud
CS_TOKEN=<your_token_here> bash upload.sh --repopath "/tmp/myproject" --subpath "/frontend" --file /tmp/coverage/lcov.info
#trigger new analysis cloud for project with id 123
PROJECT_ID=123
curl -X 'POST' \
'http://api.codecene.io/projects/{PROJECT_ID}/run-analysis' \
-H 'accept: application/json' \
-H 'authorization: Bearer ${CS_TOKEN}' \
-d ''