Skip to content

Commit

Permalink
Add workflow badges
Browse files Browse the repository at this point in the history
- Updated code-coverage.yml
- coverage.js written for converting coverage.info to json
- Updated README.md and gh-pages
  • Loading branch information
SuhashiniNaik committed Dec 19, 2024
1 parent ec25295 commit ddbb7f8
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 4 deletions.
46 changes: 43 additions & 3 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Code Coverage Report
name: Code Coverage

on: [workflow_call, push, pull_request]
on:
workflow_call:
push:
branches:
- main
pull_request:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down Expand Up @@ -64,4 +69,39 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: code_coverage
path: code_coverage.zip
path: code_coverage.zip

#To generate code-coverage badge with percentage

- name: Install npm
run: |
sudo apt update
sudo apt install nodejs npm
- name: Convert the coverage.info to json format
run: |
mkdir -p coverage-badge
npm install lcov-parse
node coverage.js
- name: Generate coverage badge
run: |
sudo npm install -g coverage-badges-cli
coverage-badges --source coverage-badge/coverage-summary.json --output coverage-badge/badge-lines.svg --jsonPath 'total.statements.pct'
echo "functional coverage"
coverage-badges --source coverage-badge/coverage-summary.json --output coverage-badge/badge-functions.svg --jsonPath 'total.functions.pct'
- name: Upload coverage badge to gh-pages branch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git clone --branch gh-pages https://github.com/${{ github.repository }} gh-pages
cp coverage-badge/coverage-summary.json gh-pages/coverage-summary.json
cp coverage-badge/badge-lines.svg gh-pages/badge-lines.svg
cp coverage-badge/badge-functions.svg gh-pages/badge-functions.svg
cd gh-pages
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Update coverage badges"
git push https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }} gh-pages
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: doc/github_pages
force_orphan: true
force_orphan: true
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Eclipse OpenBSW

<!-- ![Build](https://github.com/eclipse-openbsw/openbsw/actions/workflows/build.yml/badge.svg) -->

## Build Status 🚀

| Platform | Status |
|----------------|------------------------------------------------------------------------|
| POSIX Build | ![POSIX](https://github.com/eclipse-openbsw/openbsw/actions/workflows/build.yml/badge.svg?branch=main&event=push&matrix.platform=posix) |
| S32K148 | ![S32K](https://github.com/eclipse-openbsw/openbsw/actions/workflows/build.yml/badge.svg?branch=main&event=push&matrix.platform=s32k148) |

## Code Coverage

| Code Coverage | Status |
|---------------------|-------------------------------------------------------------------|
| Line Coverage | ![Code Coverage](https://raw.githubusercontent.com/esrlabs/openbsw/gh-pages/badge-lines.svg) |
| Functional Coverage | ![Code Coverage](https://raw.githubusercontent.com/esrlabs/openbsw/gh-pages/badge-functions.svg) |



<!-- ![Code coverage](https://github.com/eclipse-openbsw/openbsw/actions/workflows/code-coverage.yml/badge.svg) -->


## Overview

Eclipse OpenBSW is an open source SDK to build professional, high quality embedded software products.
Expand Down
58 changes: 58 additions & 0 deletions coverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var parse = require('lcov-parse');
const fs = require('fs');


const lcovFilePath = './cmake-build-unit-tests/coverage.info';


const lcovString = fs.readFileSync(lcovFilePath, 'utf8');


parse(lcovString, function(err, data) {
if (err) {
console.error('Error parsing LCOV string:', err);
return;
}


let totalLinesFound = 0;
let totalLinesHit = 0;
let totalFunctionsFound = 0;
let totalFunctionsHit = 0;

data.forEach(file => {
if (file.lines) {
totalLinesFound += file.lines.found || 0;
totalLinesHit += file.lines.hit || 0;
}
if (file.functions) {
totalFunctionsFound += file.functions.found || 0;
totalFunctionsHit += file.functions.hit || 0;
}
});


const totalLineCoverage = ((totalLinesHit / totalLinesFound) * 100).toFixed(2);
const totalFunctionCoverage = ((totalFunctionsHit / totalFunctionsFound) * 100).toFixed(2);


const formattedData = {
total: {
statements: {
pct: totalLineCoverage
},
functions: {
pct: totalFunctionCoverage
}
}
};


const outputFilePath = './coverage-badge/coverage-summary.json';
fs.writeFileSync(outputFilePath, JSON.stringify(formattedData, null, 2));


console.log('Coverage data has been saved to:', outputFilePath);
console.log(`Total Line Coverage: ${totalLineCoverage}%`);
console.log(`Total Function Coverage: ${totalFunctionCoverage}%`);
});

0 comments on commit ddbb7f8

Please sign in to comment.