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

Install bc to support arithmetic operations with floating numbers #85

Closed
jorgecoca opened this issue Aug 11, 2020 · 3 comments · Fixed by cirruslabs/docker-images-android#29

Comments

@jorgecoca
Copy link

A common case that could happen on pipelines would be to compare a certain code coverage generated with a threshold, so you can validate that there's no coverage regressions in your codebase. For example, in my case, I run a script like this:

#!/bin/bash

set -e

LCOV_PATH=$1
MINIMUM_COVERAGE=$2
FILTERED_COVERAGE_PATH='./lcov_filtered.info'

if [ ! -z "$3" ]; then
    echo "Excluding $3 from coverage..."
    lcov --remove ${LCOV_PATH} $3 -o ${FILTERED_COVERAGE_PATH}
    CODE_COVERAGE=$(lcov --list ${FILTERED_COVERAGE_PATH} | sed -n "s/.*Total:|\([^%]*\)%.*/\1/p")
else
    CODE_COVERAGE=$(lcov --list ${LCOV_PATH} | sed -n "s/.*Total:|\([^%]*\)%.*/\1/p")
fi

echo "Minumum Coverage Required: ${MINIMUM_COVERAGE}%"
echo "Current Code Coverage: ${CODE_COVERAGE}%"
if (( $(echo "$CODE_COVERAGE < $2" | bc) )); then exit 1; fi

However, this script will fail at the very last line because bc is not installed in this Docker image (for example):

tool/coverage.sh: line 30: bc: command not found

Would it be possible to install bc in the flutter image? Thanks!

fkorotkov added a commit to cirruslabs/docker-images-android that referenced this issue Aug 11, 2020
@fkorotkov
Copy link
Contributor

Thank you for your descriptive example! I don't have any concerns about adding it. Seems like a small tool that can be usefull. See cirruslabs/docker-images-android#29

Unfortunately, the android images are already targeting Android 11 and flutter is only about to support it so it's not freezable to update flutter image to cirrusci/android-sdk:30. Will bash magic work for you in the meantime?

if [ $CODE_COVERAGE -le $2 ]; then exit 1; fi

@jorgecoca
Copy link
Author

The problem with that line is the -le (or that same family) only works with integers, not floating numbers, so if your coverage is, let's say, 87.5, then you won't be able to compute.

My bash knowledge is really limited, so any guidance would be appreciated: if you can think of an alternative to compare numbers (integers and floating), then let me know and I am happy to run it on my pipeline!

Thank you so much!

fkorotkov added a commit to cirruslabs/docker-images-android that referenced this issue Aug 11, 2020
@fkorotkov fkorotkov reopened this Aug 11, 2020
fkorotkov added a commit to cirruslabs/docker-images-android that referenced this issue Aug 11, 2020
@fkorotkov
Copy link
Contributor

Should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants