Skip to content

Commit

Permalink
Add workflow badges in README.md
Browse files Browse the repository at this point in the history
- coverage.js written for converting coverage.info to json has been commented out
- Updated README.md with links to workflow badges
- Updated code-coverage.yml with badge extraction
- testing 1
  • Loading branch information
SuhashiniNaik committed Jan 20, 2025
1 parent a43a155 commit 8033f86
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 12 deletions.
58 changes: 58 additions & 0 deletions .github/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}%`);
// });
42 changes: 34 additions & 8 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: Code Coverage

on:
workflow_call:
push:
branches:
- main
pull_request:
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 @@ -62,11 +64,35 @@ jobs:
# Zip the coverage report
mv cmake-build-unit-tests/coverage code_coverage &&
zip -r code_coverage.zip code_coverage
zip -r code_coverage.zip code_coverage &&
# Extract coverage percentage and generate badge URL
LinePercentage=\$(lcov --summary cmake-build-unit-tests/coverage.info | grep 'lines' | awk '{print \$2}' | tr -d '%') &&
echo \"Line Percentage: \$LinePercentage\" # Debug print &&
wget \"https://img.shields.io/badge/coverage-\${LinePercentage}25-brightgreen.svg\" -O line_coverage_badge.svg &&
FunctionPercentage=\$(lcov --summary cmake-build-unit-tests/coverage.info | grep 'functions' | awk '{print \$2}' | tr -d '%') &&
echo \"Function Percentage: \$FunctionPercentage\" # Debug print &&
wget \"https://img.shields.io/badge/coverage-\${FunctionPercentage}25-brightgreen.svg\" -O function_coverage_badge.svg &&
mkdir coverage_badges &&
# Move the badges into the folder
mv line_coverage_badge.svg coverage_badges/ &&
mv function_coverage_badge.svg coverage_badges/ &&
# Zip the folder containing the badges
zip -r coverage_badges.zip coverage_badges
"
- name: Upload code coverage artifact
uses: actions/upload-artifact@v4
with:
name: code_coverage
path: code_coverage.zip
path: code_coverage.zip

- name: Upload Coverage Badge
uses: actions/upload-artifact@v4
with:
name: coverage_badges
path: coverage_badges.zip
21 changes: 17 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Publish Documentation

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

permissions:
contents: write
Expand Down Expand Up @@ -60,6 +61,18 @@ jobs:
run: |
unzip code_coverage.zip
rm code_coverage.zip
- name: Download Coverage badge artifact
uses: actions/download-artifact@v4
with:
name: coverage_badges
path: ./doc/github_pages

- name: Unzip Coverage badge artifact
working-directory: ./doc/github_pages
run: |
unzip coverage_badges.zip
rm coverage_badges.zip
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Eclipse OpenBSW


## 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 | ![Line Coverage](https://raw.githubusercontent.com/esrlabs/openbsw/gh-pages/coverage_badges/line_coverage_badge.svg) |
| Function Coverage | ![Function Coverage](https://raw.githubusercontent.com/esrlabs/openbsw/gh-pages/coverage_badges/function_coverage_badge.svg) |



## Overview

Eclipse OpenBSW is an open source SDK to build professional, high quality embedded software products.
Expand Down

0 comments on commit 8033f86

Please sign in to comment.