Skip to content

Commit

Permalink
add workflow for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
micha37-martins committed Aug 21, 2024
1 parent b0179c6 commit 6e6871e
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions .github/workflows/github-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,33 @@ on:

jobs:
coverage:

runs-on: ubuntu-22.04

services:
kcov:
image: kcov/kcov:v42
options: --entrypoint sh
volumes:
- ${{ github.workspace }}:/workspace
container:
image: kcov/kcov:v42
options: --privileged
# volumes:
# - ${{ github.workspace }}:/workspace

steps:
- name: Checkout code
uses: actions/checkout@v3.6.0

- name: DEBUG
- name: Run coverage script
run: |
docker exec ${{ job.services.kcov.id }} sh -c "echo test"
chmod +x ./coverage.sh
./coverage.sh
- name: Run coverage script inside kcov service container
run: |
docker exec ${{ job.services.kcov.id }} sh -c "cd /workspace && ./coverage.sh"
- name: Extract coverage from index.js
- name: Generate coverage percentage
id: coverage
run: |
# Extract the coverage percentage directly from the index.js file
coverage=$(grep -oP '(?<=covered"\s*:\s*")\d+\.\d+' coverage/test_smartmon-json.coverage/index.js)
# Output the coverage percentage
coverage=$(grep -o 'Overall coverage rate.*' <path_to_coverage_report> | grep -o '[0-9]*\.[0-9]*')
echo "::set-output name=coverage::$coverage"
- name: Update README.md with coverage badge
if: github.ref_name == 'main' || github.ref_name == 'dev'
run: |
sed -i 's|\[!\[Coverage\](https://img.shields.io/badge/Coverage-[0-9]*%25-brightgreen)\]|[!\[Coverage\](https://img.shields.io/badge/Coverage-${{ steps.coverage.outputs.coverage }}%25-brightgreen)]|' README.md
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add README.md
git commit -m "Update coverage badge"
git push origin ${{ github.ref_name }}
git push origin main

0 comments on commit 6e6871e

Please sign in to comment.