Skip to content

Commit

Permalink
refactor: Update tests.yml to install lcov and check code coverage
Browse files Browse the repository at this point in the history
This commit updates the tests.yml file to install lcov and check the code coverage. It adds a new step to install lcov and jq dependencies using apt-get. It also modifies the check-coverage step to generate lcov.info, filter out specific files, and calculate the code coverage percentage. The threshold is set to 50%, and if the coverage is below the threshold, the step will exit with an error. This change improves the accuracy of the code coverage report and ensures that the correct files are included/excluded.
  • Loading branch information
PlugFox committed Jul 19, 2024
1 parent 7de02ec commit ad3c559
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ jobs:
- name: 👷 Install Dependencies
id: install-dependencies
timeout-minutes: 1
run: dart pub get --no-example
run: |
sudo apt-get update && sudo apt-get install -y lcov jq
dart pub get --no-example
- name: 📥 Save Pub modules
id: cache-pub-save
Expand All @@ -154,6 +156,7 @@ jobs:
id: run-echo-server
timeout-minutes: 1
run: |
chmod +x ~/build/bin/echo
nohup ~/build/bin/echo > echo.log 2>&1 &
echo $! > echo_pid.txt
env:
Expand Down Expand Up @@ -190,6 +193,19 @@ jobs:
rm -f echo_pid.txt || true
rm -f echo.log || true
- name: 🔍 Check coverage
id: check-coverage
timeout-minutes: 2
run: |
mv coverage/lcov.info coverage/lcov.base.info
lcov -r coverage/lcov.base.info -o coverage/lcov.base.info "lib/src/protobuf/client.*.dart" "lib/**/*.g.dart"
mv coverage/lcov.base.info coverage/lcov.info
lcov --list coverage/lcov.info
THRESHOLD=50
COVERAGE=$(lcov --summary coverage.info | grep lines | tail -1 | awk '{print $4}' | sed 's/%//')
echo "Coverage is $COVERAGE%"
echo $COVERAGE'<'$THRESHOLD | bc | grep -q 1 && echo "Coverage ($COVERAGE%) is below the threshold ($THRESHOLD%)" && exit 1 || echo "Coverage ($COVERAGE%) is above the threshold ($THRESHOLD%)"
- name: 🧹 Cleanup artifacts
id: cleanup-artifacts
if: always()
Expand All @@ -205,20 +221,6 @@ jobs:
https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$artifact_id
echo "Artifacts cleaned up."
- name: 🔍 Check coverage
id: check-coverage
timeout-minutes: 2
run: |
sudo apt-get update && sudo apt-get install -y lcov
mv coverage/lcov.info coverage/lcov.base.info
lcov -r coverage/lcov.base.info -o coverage/lcov.base.info "lib/src/protobuf/client.*.dart" "lib/**/*.g.dart"
mv coverage/lcov.base.info coverage/lcov.info
lcov --list coverage/lcov.info
THRESHOLD=50
COVERAGE=$(lcov --summary coverage.info | grep lines | tail -1 | awk '{print $4}' | sed 's/%//')
echo "Coverage is $COVERAGE%"
echo $COVERAGE'<'$THRESHOLD | bc | grep -q 1 && echo "Coverage ($COVERAGE%) is below the threshold ($THRESHOLD%)" && exit 1 || echo "Coverage ($COVERAGE%) is above the threshold ($THRESHOLD%)"
- name: ☂️ Upload coverage to Codecov
id: upload-coverage
timeout-minutes: 2
Expand Down

0 comments on commit ad3c559

Please sign in to comment.