Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test coverage test #8

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
88 changes: 88 additions & 0 deletions .github/workflows/unit_test_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Unit Test Coverage

on:
pull_request:
branches:
- develop

jobs:
test_coverage:
runs-on: ubuntu-latest

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

- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.19.6'

- name: Install dependencies
run: flutter pub get

- name: Install lcov
run: sudo apt-get install -y lcov

- name: Run unit tests with coverage
run: |
flutter test --coverage
echo "Checking if coverage file exists:"
ls -la coverage/

- name: Generate coverage report
run: genhtml coverage/lcov.info -o coverage/html

# Check coverage threshold and continue even if threshold fails
- name: Check coverage threshold
id: check_coverage
run: |
COVERAGE=$(lcov --summary coverage/lcov.info | grep -Po 'lines\.*: \K\d+.\d+')
echo "Extracted Coverage: $COVERAGE%"
echo "coverage=$COVERAGE" >> $GITHUB_ENV
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "Code coverage is below the required threshold of 80%!"
exit 1
else
echo "Code coverage is above the required threshold."
fi
continue-on-error: true

# Push the generated coverage report to the gh-pages branch without wiping everything
- name: Deploy coverage report to GitHub Pages
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"

# Create a new folder for the report to prevent wiping out the whole repo
mkdir -p temp-gh-pages
cp -r coverage/html/* temp-gh-pages/

# Checkout the gh-pages branch
git fetch
git checkout gh-pages || git checkout --orphan gh-pages

# Clean the branch but keep the .git directory intact
git rm -rf .

# Move the coverage report into the root of the gh-pages branch
mv temp-gh-pages/* .

# Commit and push the changes to the gh-pages branch
git add .
git commit -m "Update coverage report"
git push --force "https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" gh-pages

# Post the coverage results in the PR
- name: Post comment with coverage results
uses: marocchino/sticky-pull-request-comment@v2
with:
header: Coverage Report
message: |
Current code coverage is at ${{ env.coverage }}%.
View the detailed [coverage report](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/index.html).

# Final step to fail the job if the coverage threshold check failed
- name: Fail if coverage below threshold
if: steps.check_coverage.outcome == 'failure'
run: exit 1
Loading