Skip to content

Commit

Permalink
Fix Github worflow for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Victoremepunto committed Sep 18, 2023
1 parent eaeec85 commit 865fbb4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
25 changes: 3 additions & 22 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,7 @@ jobs:
with:
node-version: '14'
- run: npm install -g bats
- run: |
wget https://github.com/SimonKagstrom/kcov/releases/download/v40/kcov-amd64.tar.gz
tar -xf kcov-amd64.tar.gz
- run: |
./usr/local/bin/kcov --exclude-path=/tmp --include-pattern /cicd-tools/src $PWD/coverage bats --filter-tags '!no-kcov' test/
shell: 'script -q -e -c "bash {0}"' # work around tty issues
env:
TERM: linux # fix tput for tty issue work around
- run: ./test/generate_coverage.sh
- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
Expand All @@ -63,17 +56,5 @@ jobs:
id: coverage-percent
shell: bash
env:
minimum_coverage: 85.50
# TODO: this is a bit broken - fix and submit PR upstream
run: |
value=$(jq '.percent_covered' <coverage/bats/coverage.json)
fixed_point() { # <float val>
int=${value%.*}
decimals=${value#*.}
echo $int${decimals::2}
}
echo "Coverage: $value%" | tee "$GITHUB_STEP_SUMMARY"
if (( $(fixed_point $value) < $(fixed_point $expected) )); then
echo " is below required minimum coverage ($minimum_coverage%)." | tee -a "$GITHUB_STEP_SUMMARY"
exit 1
fi
minimum_coverage: 90.01
run: test/check_coverage.sh
16 changes: 16 additions & 0 deletions test/check_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

minimum_coverage=${minimum_coverage:-90.01}
coverage_report='coverage/bats/coverage.json'
value=$(jq -r '.percent_covered' < $coverage_report)

reformat_decimal_to_int() {
printf "%0.2f" "$1" | sed 's/\.//'
}

echo "Coverage: $value%" | tee "$GITHUB_STEP_SUMMARY"

if (( $(reformat_decimal_to_int "$value") < $(reformat_decimal_to_int "$minimum_coverage") )); then
echo " is below required minimum coverage ($minimum_coverage%)." | tee -a "$GITHUB_STEP_SUMMARY"
exit 1
fi
27 changes: 27 additions & 0 deletions test/generate_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

COVERAGE_DIRECTORY="$PWD/coverage"
BATS_CMD='bats'
TESTS_DIRECTORY='test'
IGNORE_TAGS='!no-kcov'
KCOV_CMD='kcov'

get_kcov() {
local url='https://github.com/SimonKagstrom/kcov/releases/download/v40/kcov-amd64.tar.gz'
curl -sL "$url" | tar -xz usr/local/bin/kcov --strip-components=3
}

if [ "$CI" = 'true' ]; then
get_kcov || exit 1
KCOV_CMD='./kcov'
fi

if [ -d "$COVERAGE_DIRECTORY" ]; then
rm -rf "$COVERAGE_DIRECTORY"
fi

"$KCOV_CMD" --include-pattern cicd-tools/src \
"$COVERAGE_DIRECTORY" \
"$BATS_CMD" \
--filter-tags "$IGNORE_TAGS" \
"$TESTS_DIRECTORY"

0 comments on commit 865fbb4

Please sign in to comment.