From a451b949fd744a7e8149b8f0586d9c71fa8cc34b Mon Sep 17 00:00:00 2001 From: Eugenio Paluello Date: Tue, 25 Jun 2024 14:55:07 +0200 Subject: [PATCH] feat: add test coverage in the deno CI (#1232) * feat: add test coverage in the deno CI * fix: continue-on-error when artifacts is not present for download * trigger CI for validation * fix: coverage_percentage * trigger CI for validation * fix: download-artifact * fix: calculate coverage drop against main branch * fix: code style * trigger CI for validation * revert trigger CI for validation * fix: use action instead of checkout and deno coverage --html * fix: deno coverage --html instead of lcov * fix: remove artifacts --- .github/workflows/test.yml | 44 +++++++++++++++++++++++++++++++++++++- .gitignore | 1 + 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1b8b99a65..e4d706bc3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,49 @@ jobs: - uses: denoland/setup-deno@v1 with: deno-version: v1.x - - run: KAKAROT_ADDRESS=0x1 deno test --allow-env + # Checkout target branch and run tests + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - name: Run Tests with Coverage on target branch + run: KAKAROT_ADDRESS=0x1 deno test --allow-env --coverage=cov_profile + - name: Generate Coverage Report on target branch + run: deno coverage cov_profile --html + - name: Install bc + run: | + sudo apt-get update + sudo apt-get install -y bc + - name: Extract coverage percentage from HTML for the target branch + run: | + cat cov_profile/html/index.html + coverage_percentage=$(grep -A 3 "
" cov_profile/html/index.html | grep "" | awk -F'[<>]' '{gsub("%","",$3); print $3}') + echo $coverage_percentage > curr_coverage_percentage.txt + # Checkout base branch and run tests + - uses: actions/checkout@v4 + with: + ref: ${{ github.base_ref }} + clean: false + - name: Run Tests with Coverage on base branch + run: KAKAROT_ADDRESS=0x1 deno test --allow-env --coverage=cov_profile_main + - name: Generate HTML report from for the base branch + run: deno coverage cov_profile_main --html + - name: Extract coverage percentage from HTML for the base branch + run: | + coverage_percentage_main=$(grep -A 3 "
" cov_profile_main/html/index.html | grep "" | awk -F'[<>]' '{gsub("%","",$3); print $3}') + echo $coverage_percentage_main > coverage_percentage_main.txt + - name: Compare coverage percentage + run: | + previous_coverage=$(awk '{print $2}' coverage_percentage_main.txt) + echo "Previous coverage percentage was $previous_coverage%" + current_coverage=$(awk '{print $2}' curr_coverage_percentage.txt) + echo "Current coverage percentage is $current_coverage%" + change=$(echo "$previous_coverage - $current_coverage" | bc) + echo "Coverage change is $change%" + if (( $(echo "$change > 5.0" | bc -l) )); then + echo "Coverage dropped by more than 5%!" + exit 1 + fi + test-rust: runs-on: ubuntu-latest-16-cores timeout-minutes: 30 diff --git a/.gitignore b/.gitignore index 1971a548f..59c3cb74b 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ vscode broadcast .idea +.DS_Store # ignore genesis.json .hive