From 8033f86635f28d0df36244fc293996ca4ee2567c Mon Sep 17 00:00:00 2001 From: Suhashini Naik Date: Wed, 18 Dec 2024 09:38:05 +0530 Subject: [PATCH] Add workflow badges in README.md - 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 --- .github/coverage.js | 58 +++++++++++++++++++++++++++++ .github/workflows/code-coverage.yml | 42 +++++++++++++++++---- .github/workflows/publish.yml | 21 +++++++++-- README.md | 17 +++++++++ 4 files changed, 126 insertions(+), 12 deletions(-) create mode 100644 .github/coverage.js diff --git a/.github/coverage.js b/.github/coverage.js new file mode 100644 index 0000000000..229641e6ad --- /dev/null +++ b/.github/coverage.js @@ -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}%`); +// }); diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index a519986782..b4c2b6b372 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -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.) @@ -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 \ No newline at end of file + path: code_coverage.zip + + - name: Upload Coverage Badge + uses: actions/upload-artifact@v4 + with: + name: coverage_badges + path: coverage_badges.zip diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 395d864ad5..d8d0b7c124 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,9 +1,10 @@ name: Publish Documentation -on: - push: - branches: - - main +on: [push, pull_request] +# on: +# push: +# branches: +# - main permissions: contents: write @@ -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 diff --git a/README.md b/README.md index 62d616929f..bc2a282a12 100644 --- a/README.md +++ b/README.md @@ -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.